Panda3D
|
00001 // Filename: lwoGroupChunk.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 "lwoGroupChunk.h" 00016 #include "lwoInputFile.h" 00017 00018 #include "pnotify.h" 00019 00020 TypeHandle LwoGroupChunk::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: LwoGroupChunk::get_num_chunks 00024 // Access: Public 00025 // Description: Returns the number of child chunks of this group. 00026 //////////////////////////////////////////////////////////////////// 00027 int LwoGroupChunk:: 00028 get_num_chunks() const { 00029 return _chunks.size(); 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: LwoGroupChunk::get_chunk 00034 // Access: Public 00035 // Description: Returns the nth child chunk of this group. 00036 //////////////////////////////////////////////////////////////////// 00037 IffChunk *LwoGroupChunk:: 00038 get_chunk(int n) const { 00039 nassertr(n >= 0 && n < (int)_chunks.size(), (IffChunk *)NULL); 00040 return _chunks[n]; 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: LwoGroupChunk::read_chunks_iff 00045 // Access: Public 00046 // Description: Reads a sequence of child chunks, until byte stop_at 00047 // has been been reached, and stores them as the 00048 // children. Returns true if successful (and exactly 00049 // the correct number of bytes were read), or false 00050 // otherwise. 00051 //////////////////////////////////////////////////////////////////// 00052 bool LwoGroupChunk:: 00053 read_chunks_iff(IffInputFile *in, size_t stop_at) { 00054 while (in->get_bytes_read() < stop_at && !in->is_eof()) { 00055 PT(IffChunk) chunk = in->get_chunk(); 00056 if (chunk == (IffChunk *)NULL) { 00057 return false; 00058 } 00059 _chunks.push_back(chunk); 00060 } 00061 00062 return (in->get_bytes_read() == stop_at); 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: LwoGroupChunk::read_subchunks_iff 00067 // Access: Public 00068 // Description: Similar to read_chunks_iff(), but reads them as 00069 // subchunks. 00070 //////////////////////////////////////////////////////////////////// 00071 bool LwoGroupChunk:: 00072 read_subchunks_iff(IffInputFile *in, size_t stop_at) { 00073 while (in->get_bytes_read() < stop_at && !in->is_eof()) { 00074 PT(IffChunk) chunk = in->get_subchunk(this); 00075 if (chunk == (IffChunk *)NULL) { 00076 return false; 00077 } 00078 _chunks.push_back(chunk); 00079 } 00080 00081 return (in->get_bytes_read() == stop_at); 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: LwoGroupChunk::write_chunks 00086 // Access: Public 00087 // Description: Formats the list of chunks for output to the user 00088 // (primarily for debugging), one per line. 00089 //////////////////////////////////////////////////////////////////// 00090 void LwoGroupChunk:: 00091 write_chunks(ostream &out, int indent_level) const { 00092 Chunks::const_iterator ci; 00093 for (ci = _chunks.begin(); ci != _chunks.end(); ++ci) { 00094 (*ci)->write(out, indent_level); 00095 } 00096 }