00001 // Filename: lwoGroupChunk.cxx 00002 // Created by: drose (24Apr01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "lwoGroupChunk.h" 00020 #include "lwoInputFile.h" 00021 00022 #include <notify.h> 00023 00024 TypeHandle LwoGroupChunk::_type_handle; 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: LwoGroupChunk::get_num_chunks 00028 // Access: Public 00029 // Description: Returns the number of child chunks of this group. 00030 //////////////////////////////////////////////////////////////////// 00031 int LwoGroupChunk:: 00032 get_num_chunks() const { 00033 return _chunks.size(); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: LwoGroupChunk::get_chunk 00038 // Access: Public 00039 // Description: Returns the nth child chunk of this group. 00040 //////////////////////////////////////////////////////////////////// 00041 IffChunk *LwoGroupChunk:: 00042 get_chunk(int n) const { 00043 nassertr(n >= 0 && n < (int)_chunks.size(), (IffChunk *)NULL); 00044 return _chunks[n]; 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: LwoGroupChunk::read_chunks_iff 00049 // Access: Public 00050 // Description: Reads a sequence of child chunks, until byte stop_at 00051 // has been been reached, and stores them as the 00052 // children. Returns true if successful (and exactly 00053 // the correct number of bytes were read), or false 00054 // otherwise. 00055 //////////////////////////////////////////////////////////////////// 00056 bool LwoGroupChunk:: 00057 read_chunks_iff(IffInputFile *in, size_t stop_at) { 00058 while (in->get_bytes_read() < stop_at && !in->is_eof()) { 00059 PT(IffChunk) chunk = in->get_chunk(); 00060 if (chunk == (IffChunk *)NULL) { 00061 return false; 00062 } 00063 _chunks.push_back(chunk); 00064 } 00065 00066 return (in->get_bytes_read() == stop_at); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: LwoGroupChunk::read_subchunks_iff 00071 // Access: Public 00072 // Description: Similar to read_chunks_iff(), but reads them as 00073 // subchunks. 00074 //////////////////////////////////////////////////////////////////// 00075 bool LwoGroupChunk:: 00076 read_subchunks_iff(IffInputFile *in, size_t stop_at) { 00077 while (in->get_bytes_read() < stop_at && !in->is_eof()) { 00078 PT(IffChunk) chunk = in->get_subchunk(this); 00079 if (chunk == (IffChunk *)NULL) { 00080 return false; 00081 } 00082 _chunks.push_back(chunk); 00083 } 00084 00085 return (in->get_bytes_read() == stop_at); 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: LwoGroupChunk::write_chunks 00090 // Access: Public 00091 // Description: Formats the list of chunks for output to the user 00092 // (primarily for debugging), one per line. 00093 //////////////////////////////////////////////////////////////////// 00094 void LwoGroupChunk:: 00095 write_chunks(ostream &out, int indent_level) const { 00096 Chunks::const_iterator ci; 00097 for (ci = _chunks.begin(); ci != _chunks.end(); ++ci) { 00098 (*ci)->write(out, indent_level); 00099 } 00100 }