Panda3D
lwoTags.cxx
1 // Filename: lwoTags.cxx
2 // Created by: drose (24Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "lwoTags.h"
16 #include "lwoInputFile.h"
17 
18 #include "dcast.h"
19 #include "indent.h"
20 
21 TypeHandle LwoTags::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: LwoTags::get_num_tags
25 // Access: Public
26 // Description: Returns the number of tags of this group.
27 ////////////////////////////////////////////////////////////////////
28 int LwoTags::
29 get_num_tags() const {
30  return _tags.size();
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: LwoTags::get_tag
35 // Access: Public
36 // Description: Returns the nth tag of this group.
37 ////////////////////////////////////////////////////////////////////
38 string LwoTags::
39 get_tag(int n) const {
40  nassertr(n >= 0 && n < (int)_tags.size(), string());
41  return _tags[n];
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: LwoTags::read_iff
46 // Access: Public, Virtual
47 // Description: Reads the data of the chunk in from the given input
48 // file, if possible. The ID and length of the chunk
49 // have already been read. stop_at is the byte position
50 // of the file to stop at (based on the current position
51 // at in->get_bytes_read()). Returns true on success,
52 // false otherwise.
53 ////////////////////////////////////////////////////////////////////
54 bool LwoTags::
55 read_iff(IffInputFile *in, size_t stop_at) {
56  LwoInputFile *lin = DCAST(LwoInputFile, in);
57 
58  while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
59  string tag = lin->get_string();
60  _tags.push_back(tag);
61  }
62 
63  return (lin->get_bytes_read() == stop_at);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: LwoTags::write
68 // Access: Public, Virtual
69 // Description:
70 ////////////////////////////////////////////////////////////////////
71 void LwoTags::
72 write(ostream &out, int indent_level) const {
73  indent(out, indent_level)
74  << get_id() << " { ";
75 
76  if (!_tags.empty()) {
77  Tags::const_iterator ti = _tags.begin();
78  out << '"' << *ti << '"';
79  ++ti;
80  while (ti != _tags.end()) {
81  out << ", \"" << *ti << '"';
82  ++ti;
83  }
84  }
85  out << " }\n";
86 }
string get_string()
Extracts a null-terminated string.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
int get_num_tags() const
Returns the number of tags of this group.
Definition: lwoTags.cxx:29
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:29
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
Definition: lwoTags.cxx:55
string get_tag(int n) const
Returns the nth tag of this group.
Definition: lwoTags.cxx:39
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:45