Panda3D
Loading...
Searching...
No Matches
lwoGroupChunk.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file lwoGroupChunk.cxx
10 * @author drose
11 * @date 2001-04-24
12 */
13
14#include "lwoGroupChunk.h"
15#include "lwoInputFile.h"
16
17#include "pnotify.h"
18
19TypeHandle LwoGroupChunk::_type_handle;
20
21/**
22 * Returns the number of child chunks of this group.
23 */
25get_num_chunks() const {
26 return _chunks.size();
27}
28
29/**
30 * Returns the nth child chunk of this group.
31 */
33get_chunk(int n) const {
34 nassertr(n >= 0 && n < (int)_chunks.size(), nullptr);
35 return _chunks[n];
36}
37
38/**
39 * Reads a sequence of child chunks, until byte stop_at has been been reached,
40 * and stores them as the children. Returns true if successful (and exactly
41 * the correct number of bytes were read), or false otherwise.
42 */
43bool LwoGroupChunk::
44read_chunks_iff(IffInputFile *in, size_t stop_at) {
45 while (in->get_bytes_read() < stop_at && !in->is_eof()) {
46 PT(IffChunk) chunk = in->get_chunk();
47 if (chunk == nullptr) {
48 return false;
49 }
50 _chunks.push_back(chunk);
51 }
52
53 return (in->get_bytes_read() == stop_at);
54}
55
56/**
57 * Similar to read_chunks_iff(), but reads them as subchunks.
58 */
59bool LwoGroupChunk::
60read_subchunks_iff(IffInputFile *in, size_t stop_at) {
61 while (in->get_bytes_read() < stop_at && !in->is_eof()) {
62 PT(IffChunk) chunk = in->get_subchunk(this);
63 if (chunk == nullptr) {
64 return false;
65 }
66 _chunks.push_back(chunk);
67 }
68
69 return (in->get_bytes_read() == stop_at);
70}
71
72/**
73 * Formats the list of chunks for output to the user (primarily for
74 * debugging), one per line.
75 */
76void LwoGroupChunk::
77write_chunks(std::ostream &out, int indent_level) const {
78 Chunks::const_iterator ci;
79 for (ci = _chunks.begin(); ci != _chunks.end(); ++ci) {
80 (*ci)->write(out, indent_level);
81 }
82}
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition iffChunk.h:30
A wrapper around an istream used for reading an IFF file.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
int get_num_chunks() const
Returns the number of child chunks of this group.
IffChunk * get_chunk(int n) const
Returns the nth child chunk of this group.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.