Panda3D
Loading...
Searching...
No Matches
bamReader.I
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 bamReader.I
10 * @author jason
11 * @date 2000-06-12
12 */
13
14/**
15 *
16 */
17INLINE BamReaderAuxData::
18BamReaderAuxData() {
19}
20
21/**
22 * Returns the current source of the BamReader as set by set_source() or the
23 * constructor.
24 */
26get_source() {
27 return _source;
28}
29
30/**
31 * If a BAM is a file, then the BamReader should contain the name of the file.
32 * This enables the reader to interpret pathnames in the BAM as relative to
33 * the directory containing the BAM.
34 */
35INLINE const Filename &BamReader::
36get_filename() const {
37 if (_source != nullptr) {
38 return _source->get_filename();
39 }
40 static const Filename empty_filename;
41 return empty_filename;
42}
43
44/**
45 * Returns the LoaderOptions passed to the loader when the model was
46 * requested, if any.
47 */
48INLINE const LoaderOptions &BamReader::
49get_loader_options() const {
50 return _loader_options;
51}
52
53/**
54 * Specifies the LoaderOptions for this BamReader.
55 */
56INLINE void BamReader::
57set_loader_options(const LoaderOptions &options) {
58 _loader_options = options;
59}
60
61/**
62 * Returns true if the reader has reached end-of-file, false otherwise. This
63 * call is only valid after a call to read_object().
64 */
65INLINE bool BamReader::
66is_eof() const {
67 nassertr(_source != nullptr, true);
68 return _source->is_eof();
69}
70
71/**
72 * Returns the major version number of the Bam file currently being read.
73 */
74INLINE int BamReader::
75get_file_major_ver() const {
76 return _file_major;
77}
78
79/**
80 * Returns the minor version number of the Bam file currently being read.
81 */
82INLINE int BamReader::
83get_file_minor_ver() const {
84 return _file_minor;
85}
86
87/**
88 * Returns the endian preference indicated by the Bam file currently being
89 * read. This does not imply that every number is stored using the indicated
90 * convention, but individual objects may choose to respect this flag when
91 * recording data.
92 */
94get_file_endian() const {
95 return _file_endian;
96}
97
98/**
99 * Returns true if the file stores all "standard" floats as 64-bit doubles, or
100 * false if they are 32-bit floats. This is determined by the compilation
101 * flags of the version of Panda that generated this file.
102 */
103INLINE bool BamReader::
105 return _file_stdfloat_double;
106}
107
108/**
109 * Returns the major version number of Bam files supported by the current code
110 * base. This must match get_file_major_ver() in order to successfully read a
111 * file.
112 */
113INLINE int BamReader::
114get_current_major_ver() const {
115 return _cur_major;
116}
117
118/**
119 * Returns the minor version number of Bam files supported by the current code
120 * base. This must match or exceed get_file_minor_ver() in order to
121 * successfully read a file.
122 */
123INLINE int BamReader::
124get_current_minor_ver() const {
125 return _cur_minor;
126}
127
128/**
129 * Returns the FileReference that provides the source for these datagrams, if
130 * any, or NULL if the datagrams do not originate from a file on disk.
131 */
133get_file() {
134 nassertr(_source != nullptr, nullptr);
135 return _source->get_file();
136}
137
138/**
139 * Returns the VirtualFile that provides the source for these datagrams, if
140 * any, or NULL if the datagrams do not originate from a VirtualFile.
141 */
143get_vfile() {
144 nassertr(_source != nullptr, nullptr);
145 return _source->get_vfile();
146}
147
148/**
149 * Returns the current file position within the data stream, if any, or 0 if
150 * the file position is not meaningful or cannot be determined.
151 *
152 * For BamReaders that return a meaningful file position, this will be
153 * pointing to the first byte following the datagram returned after a call to
154 * get_datagram().
155 */
156INLINE std::streampos BamReader::
157get_file_pos() {
158 nassertr(_source != nullptr, 0);
159 return _source->get_file_pos();
160}
161
162/**
163 * Registers a factory function that is called when an object of the given
164 * type is encountered within the .bam stream.
165 *
166 * @param user_data an optional pointer to be passed along to the function.
167 */
169register_factory(TypeHandle handle, WritableFactory::CreateFunc *func, void *user_data) {
170 get_factory()->register_factory(handle, func, user_data);
171}
172
173/**
174 * Returns the global WritableFactory for generating TypedWritable objects
175 */
177get_factory() {
178 if (_factory == nullptr) {
179 create_factory();
180 }
181 return _factory;
182}
183
184/**
185 * Creates a new WritableFactory for generating TypedWritable objects
186 */
187INLINE void BamReader::
188create_factory() {
189 _factory = new WritableFactory;
190}
191
192/**
193 * Reads a single datagram from the stream. Returns true on success, false on
194 * failure.
195 */
196INLINE bool BamReader::
197get_datagram(Datagram &datagram) {
198 nassertr(_source != nullptr, false);
199 if (_source->is_error()) {
200 return false;
201 }
202
203 if (!_source->get_datagram(datagram)) {
204 return false;
205 }
206
207 datagram.set_stdfloat_double(_file_stdfloat_double);
208 return true;
209}
210
211/**
212 *
213 */
214INLINE BamReader::AuxData::
215AuxData() {
216}
217
218/**
219 *
220 */
221INLINE BamReader::CreatedObj::
222CreatedObj() :
223 _created(false),
224 _ptr(nullptr),
225 _ref_ptr(nullptr),
226 _change_this(nullptr),
227 _change_this_ref(nullptr)
228{
229}
230
231/**
232 *
233 */
234INLINE BamReader::CreatedObj::
235~CreatedObj() {
236 set_ptr(nullptr, nullptr);
237}
238
239/**
240 * Replaces the pointer to the created object. There are actually two
241 * pointers to the same object in different forms: a generic TypedWritable
242 * pointer, and an untyped ReferenceCount pointer. We need both pointers
243 * because some objects (like PandaNode) inherit from TypedWritable and
244 * ReferenceCount independently.
245 *
246 * Managing a typed pointer and an untyped ReferenceCount pointer to the same
247 * object takes just a bit of extra care.
248 */
249INLINE void BamReader::CreatedObj::
250set_ptr(TypedWritable *ptr, ReferenceCount *ref_ptr) {
251 if (_ptr != ptr) {
252 if (_ref_ptr != nullptr) {
253 nassertv(_ref_ptr != ref_ptr);
254 unref_delete(_ref_ptr);
255 }
256
257 _ptr = ptr;
258 _ref_ptr = ref_ptr;
259
260 if (_ref_ptr != nullptr) {
261 _ref_ptr->ref();
262 }
263 } else {
264 nassertv(_ref_ptr == ref_ptr);
265 }
266}
267
268/**
269 * Takes in a FactoryParams, passed from a WritableFactory into any
270 * TypedWritable's make function, and parses out the datagram that contatins
271 * the data it needs to construct itself, and parses out the pointer to the
272 * managing BamReader object
273 */
274INLINE void
276 DatagramIterator &scan, BamReader *&manager) {
277 BamReaderParam *param = DCAST(BamReaderParam, params.get_param(0));
278
279 scan = param->get_iterator();
280 manager = param->get_manager();
281}
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
BamEndian
This defines an enumerated type used to represent the endianness of certain numeric values stored in ...
Definition bamEnums.h:32
The parameters that are passed through the Factory to any object constructing itself from a Bam file.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
bool is_eof() const
Returns true if the reader has reached end-of-file, false otherwise.
Definition bamReader.I:66
int get_current_minor_ver() const
Returns the minor version number of Bam files supported by the current code base.
Definition bamReader.I:124
const FileReference * get_file()
Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagr...
Definition bamReader.I:133
get_file_stdfloat_double
Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit ...
Definition bamReader.h:160
get_source
Returns the current source of the BamReader as set by set_source() or the constructor.
Definition bamReader.h:154
int get_file_major_ver() const
Returns the major version number of the Bam file currently being read.
Definition bamReader.I:75
get_filename
If a BAM is a file, then the BamReader should contain the name of the file.
Definition bamReader.h:155
static void register_factory(TypeHandle type, WritableFactory::CreateFunc *func, void *user_data=nullptr)
Registers a factory function that is called when an object of the given type is encountered within th...
Definition bamReader.I:169
std::streampos get_file_pos()
Returns the current file position within the data stream, if any, or 0 if the file position is not me...
Definition bamReader.I:157
set_loader_options
Specifies the LoaderOptions for this BamReader.
Definition bamReader.h:156
VirtualFile * get_vfile()
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagram...
Definition bamReader.I:143
get_loader_options
Returns the LoaderOptions passed to the loader when the model was requested, if any.
Definition bamReader.h:156
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition bamReader.I:83
get_file_endian
Returns the endian preference indicated by the Bam file currently being read.
Definition bamReader.h:159
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
int get_current_major_ver() const
Returns the major version number of Bam files supported by the current code base.
Definition bamReader.I:114
This class defines the abstract interace to any source of datagrams, whether it be from a file or fro...
virtual std::streampos get_file_pos()
Returns the current file position within the data stream, if any, or 0 if the file position is not me...
virtual const FileReference * get_file()
Returns the FileReference that provides the source for these datagrams, if any, or NULL if the datagr...
virtual const Filename & get_filename()
Returns the filename that provides the source for these datagrams, if any, or empty string if the dat...
virtual VirtualFile * get_vfile()
Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagram...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void set_stdfloat_double(bool stdfloat_double)
Changes the stdfloat_double flag, which defines the operation performed by add_stdfloat() and Datagra...
Definition datagram.I:395
An instance of this class is passed to the Factory when requesting it to do its business and construc...
FactoryParam * get_param(int n) const
Returns the nth parameter that has been added to the set.
A Factory can be used to create an instance of a particular subclass of some general base class.
Definition factory.h:34
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
Keeps a reference-counted pointer to a file on disk.
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
Specifies parameters that may be passed to the loader.
A base class for all things that want to be reference-counted.
void ref() const
Explicitly increments the reference count.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
The abstract base class for a file or directory within the VirtualFileSystem.
Definition virtualFile.h:35
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...