Panda3D
lwoGroupChunk.cxx
1 // Filename: lwoGroupChunk.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 "lwoGroupChunk.h"
16 #include "lwoInputFile.h"
17 
18 #include "pnotify.h"
19 
20 TypeHandle LwoGroupChunk::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: LwoGroupChunk::get_num_chunks
24 // Access: Public
25 // Description: Returns the number of child chunks of this group.
26 ////////////////////////////////////////////////////////////////////
28 get_num_chunks() const {
29  return _chunks.size();
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: LwoGroupChunk::get_chunk
34 // Access: Public
35 // Description: Returns the nth child chunk of this group.
36 ////////////////////////////////////////////////////////////////////
38 get_chunk(int n) const {
39  nassertr(n >= 0 && n < (int)_chunks.size(), (IffChunk *)NULL);
40  return _chunks[n];
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: LwoGroupChunk::read_chunks_iff
45 // Access: Public
46 // Description: Reads a sequence of child chunks, until byte stop_at
47 // has been been reached, and stores them as the
48 // children. Returns true if successful (and exactly
49 // the correct number of bytes were read), or false
50 // otherwise.
51 ////////////////////////////////////////////////////////////////////
52 bool LwoGroupChunk::
53 read_chunks_iff(IffInputFile *in, size_t stop_at) {
54  while (in->get_bytes_read() < stop_at && !in->is_eof()) {
55  PT(IffChunk) chunk = in->get_chunk();
56  if (chunk == (IffChunk *)NULL) {
57  return false;
58  }
59  _chunks.push_back(chunk);
60  }
61 
62  return (in->get_bytes_read() == stop_at);
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: LwoGroupChunk::read_subchunks_iff
67 // Access: Public
68 // Description: Similar to read_chunks_iff(), but reads them as
69 // subchunks.
70 ////////////////////////////////////////////////////////////////////
71 bool LwoGroupChunk::
72 read_subchunks_iff(IffInputFile *in, size_t stop_at) {
73  while (in->get_bytes_read() < stop_at && !in->is_eof()) {
74  PT(IffChunk) chunk = in->get_subchunk(this);
75  if (chunk == (IffChunk *)NULL) {
76  return false;
77  }
78  _chunks.push_back(chunk);
79  }
80 
81  return (in->get_bytes_read() == stop_at);
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: LwoGroupChunk::write_chunks
86 // Access: Public
87 // Description: Formats the list of chunks for output to the user
88 // (primarily for debugging), one per line.
89 ////////////////////////////////////////////////////////////////////
90 void LwoGroupChunk::
91 write_chunks(ostream &out, int indent_level) const {
92  Chunks::const_iterator ci;
93  for (ci = _chunks.begin(); ci != _chunks.end(); ++ci) {
94  (*ci)->write(out, indent_level);
95  }
96 }
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
IffChunk * get_chunk(int n) const
Returns the nth child chunk of this group.
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
Definition: iffChunk.h:32
int get_num_chunks() const
Returns the number of child chunks of this group.
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:45