Panda3D
Loading...
Searching...
No Matches
lwoTags.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 lwoTags.cxx
10 * @author drose
11 * @date 2001-04-24
12 */
13
14#include "lwoTags.h"
15#include "lwoInputFile.h"
16
17#include "dcast.h"
18#include "indent.h"
19
20TypeHandle LwoTags::_type_handle;
21
22/**
23 * Returns the number of tags of this group.
24 */
26get_num_tags() const {
27 return _tags.size();
28}
29
30/**
31 * Returns the nth tag of this group.
32 */
33std::string LwoTags::
34get_tag(int n) const {
35 nassertr(n >= 0 && n < (int)_tags.size(), std::string());
36 return _tags[n];
37}
38
39/**
40 * Reads the data of the chunk in from the given input file, if possible. The
41 * ID and length of the chunk have already been read. stop_at is the byte
42 * position of the file to stop at (based on the current position at
43 * in->get_bytes_read()). Returns true on success, false otherwise.
44 */
46read_iff(IffInputFile *in, size_t stop_at) {
47 LwoInputFile *lin = DCAST(LwoInputFile, in);
48
49 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
50 std::string tag = lin->get_string();
51 _tags.push_back(tag);
52 }
53
54 return (lin->get_bytes_read() == stop_at);
55}
56
57/**
58 *
59 */
60void LwoTags::
61write(std::ostream &out, int indent_level) const {
62 indent(out, indent_level)
63 << get_id() << " { ";
64
65 if (!_tags.empty()) {
66 Tags::const_iterator ti = _tags.begin();
67 out << '"' << *ti << '"';
68 ++ti;
69 while (ti != _tags.end()) {
70 out << ", \"" << *ti << '"';
71 ++ti;
72 }
73 }
74 out << " }\n";
75}
IffId get_id() const
Returns the ID associated with this chunk.
Definition iffChunk.I:25
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.
std::string get_string()
Extracts a null-terminated string.
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
A specialization of IffInputFile to handle reading a Lightwave Object file.
int get_num_tags() const
Returns the number of tags of this group.
Definition lwoTags.cxx:26
std::string get_tag(int n) const
Returns the nth tag of this group.
Definition lwoTags.cxx:34
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
Definition lwoTags.cxx:46
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.