Panda3D

lwoPolygonTags.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 lwoPolygonTags.cxx
10 * @author drose
11 * @date 2001-04-24
12 */
13
14 #include "lwoPolygonTags.h"
15 #include "lwoInputFile.h"
16
17 #include "dcast.h"
18 #include "indent.h"
19
20 TypeHandle LwoPolygonTags::_type_handle;
21
22
23 /**
24 * Returns true if the map has a tag associated with the given polygon index,
25 * false otherwise.
26 */
27 bool LwoPolygonTags::
28 has_tag(int polygon_index) const {
29 return (_tmap.count(polygon_index) != 0);
30 }
31
32 /**
33 * Returns the tag associated with the given polygon index, or -1 if there is
34 * no tag associated.
35 */
36 int LwoPolygonTags::
37 get_tag(int polygon_index) const {
38 TMap::const_iterator ti;
39 ti = _tmap.find(polygon_index);
40 if (ti != _tmap.end()) {
41 return (*ti).second;
42 }
43
44 return -1;
45 }
46
47 /**
48 * Reads the data of the chunk in from the given input file, if possible. The
49 * ID and length of the chunk have already been read. stop_at is the byte
50 * position of the file to stop at (based on the current position at
51 * in->get_bytes_read()). Returns true on success, false otherwise.
52 */
53 bool LwoPolygonTags::
54 read_iff(IffInputFile *in, size_t stop_at) {
55 LwoInputFile *lin = DCAST(LwoInputFile, in);
56
57 _tag_type = lin->get_id();
58
59 while (lin->get_bytes_read() < stop_at && !lin->is_eof()) {
60 int polygon_index = lin->get_vx();
61 int tag = lin->get_be_int16();
62
63 bool inserted = _tmap.insert(TMap::value_type(polygon_index, tag)).second;
64 if (!inserted) {
65 nout << "Duplicate index " << polygon_index << " in map.\n";
66 }
67 }
68
69 return (lin->get_bytes_read() == stop_at);
70 }
71
72 /**
73 *
74 */
75 void LwoPolygonTags::
76 write(std::ostream &out, int indent_level) const {
77 indent(out, indent_level)
78 << get_id() << " { tag_type = " << _tag_type << ", "
79 << _tmap.size() << " values }\n";
80 }
IffChunk::get_id
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
IffInputFile
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
IffInputFile::get_id
IffId get_id()
Extracts a 4-character IFF ID.
Definition: iffInputFile.cxx:196
IffInputFile::get_bytes_read
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:44
IffInputFile::get_be_int16
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
Definition: iffInputFile.cxx:113
IffInputFile::is_eof
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:36
LwoInputFile
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:26
LwoInputFile::get_vx
int get_vx()
Reads a Lightwave variable-length index.
Definition: lwoInputFile.cxx:50
LwoPolygonTags::has_tag
bool has_tag(int polygon_index) const
Returns true if the map has a tag associated with the given polygon index, false otherwise.
Definition: lwoPolygonTags.cxx:28
LwoPolygonTags::get_tag
int get_tag(int polygon_index) const
Returns the tag associated with the given polygon index, or -1 if there is no tag associated.
Definition: lwoPolygonTags.cxx:37
LwoPolygonTags::read_iff
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: lwoPolygonTags.cxx:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoInputFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoPolygonTags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.