Panda3D

lwoTags.cxx

00001 // Filename: lwoTags.cxx
00002 // Created by:  drose (24Apr01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "lwoTags.h"
00016 #include "lwoInputFile.h"
00017 
00018 #include "dcast.h"
00019 #include "indent.h"
00020 
00021 TypeHandle LwoTags::_type_handle;
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: LwoTags::get_num_tags
00025 //       Access: Public
00026 //  Description: Returns the number of tags of this group.
00027 ////////////////////////////////////////////////////////////////////
00028 int LwoTags::
00029 get_num_tags() const {
00030   return _tags.size();
00031 }
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: LwoTags::get_tag
00035 //       Access: Public
00036 //  Description: Returns the nth tag of this group.
00037 ////////////////////////////////////////////////////////////////////
00038 string LwoTags::
00039 get_tag(int n) const {
00040   nassertr(n >= 0 && n < (int)_tags.size(), string());
00041   return _tags[n];
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: LwoTags::read_iff
00046 //       Access: Public, Virtual
00047 //  Description: Reads the data of the chunk in from the given input
00048 //               file, if possible.  The ID and length of the chunk
00049 //               have already been read.  stop_at is the byte position
00050 //               of the file to stop at (based on the current position
00051 //               at in->get_bytes_read()).  Returns true on success,
00052 //               false otherwise.
00053 ////////////////////////////////////////////////////////////////////
00054 bool LwoTags::
00055 read_iff(IffInputFile *in, size_t stop_at) {
00056   LwoInputFile *lin = DCAST(LwoInputFile, in);
00057 
00058   while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
00059     string tag = lin->get_string();
00060     _tags.push_back(tag);
00061   }
00062 
00063   return (lin->get_bytes_read() == stop_at);
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: LwoTags::write
00068 //       Access: Public, Virtual
00069 //  Description:
00070 ////////////////////////////////////////////////////////////////////
00071 void LwoTags::
00072 write(ostream &out, int indent_level) const {
00073   indent(out, indent_level)
00074     << get_id() << " { ";
00075 
00076   if (!_tags.empty()) {
00077     Tags::const_iterator ti = _tags.begin();
00078     out << '"' << *ti << '"';
00079     ++ti;
00080     while (ti != _tags.end()) {
00081       out << ", \"" << *ti << '"';
00082       ++ti;
00083     }
00084   }
00085   out << " }\n";
00086 }
 All Classes Functions Variables Enumerations