Panda3D
iffGenericChunk.cxx
1 // Filename: iffGenericChunk.cxx
2 // Created by: drose (23Apr01)
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 "iffGenericChunk.h"
16 #include "iffInputFile.h"
17 
18 #include "indent.h"
19 
20 TypeHandle IffGenericChunk::_type_handle;
21 
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: IffGenericChunk::read_iff
25 // Access: Public, Virtual
26 // Description: Reads the data of the chunk in from the given input
27 // file, if possible. The ID and length of the chunk
28 // have already been read. stop_at is the byte position
29 // of the file to stop at (based on the current position
30 // at in->get_bytes_read()). Returns true on success,
31 // false otherwise.
32 ////////////////////////////////////////////////////////////////////
34 read_iff(IffInputFile *in, size_t stop_at) {
35  size_t length = stop_at - in->get_bytes_read();
36  bool result = in->read_bytes(_data, length);
37  in->align();
38  return result;
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: IffGenericChunk::write
43 // Access: Public, Virtual
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 void IffGenericChunk::
47 write(ostream &out, int indent_level) const {
48  indent(out, indent_level)
49  << get_id() << " { " << _data.get_length() << " bytes }\n";
50 }
51 
void align()
If the current file pointer is not positioned on an even-byte boundary, reads and discards one byte s...
Definition: iffInputFile.I:68
bool read_bytes(Datagram &datagram, int length)
Reads a series of bytes, and stores them in the indicated Datagram.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
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
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
size_t get_length() const
Returns the number of bytes in the datagram.
Definition: datagram.I:457