#include <bamReader.h>
Public Types | |
typedef Factory< TypedWritable > | WritableFactory |
typedef TypedWritable *(* | ChangeThisFunc )(TypedWritable *object, BamReader *manager) |
Public Member Functions | |
BamReader (DatagramGenerator *generator) | |
~BamReader () | |
bool | init () |
Initializes the BamReader prior to reading any objects from its source. | |
TypedWritable * | read_object () |
Reads a single object from the Bam file. | |
bool | is_eof () const |
Returns true if the reader has reached end-of-file, false otherwise. | |
bool | resolve () |
This may be called at any time during processing of the Bam file to resolve all the known pointers so far. | |
int | get_file_major_ver () const |
Returns the major version number of the Bam file currently being read. | |
int | get_file_minor_ver () const |
Returns the minor version number of the Bam file currently being read. | |
int | get_current_major_ver () const |
Returns the major version number of Bam files supported by the current code base. | |
int | get_current_minor_ver () const |
Returns the minor version number of Bam files supported by the current code base. | |
void | read_pointer (DatagramIterator &scan) |
The interface for reading a pointer to another object from a Bam file. | |
void | read_pointers (DatagramIterator &scan, int count) |
A convenience function to read a contiguous list of pointers. | |
void | skip_pointer (DatagramIterator &scan) |
Reads and discards a pointer value from the Bam file. | |
void | read_cdata (DatagramIterator &scan, PipelineCyclerBase &cycler) |
Reads in the indicated CycleData object. | |
void | register_finalize (TypedWritable *whom) |
Should be called by an object reading itself from the Bam file to indicate that this particular object would like to receive the finalize() callback when all the objects and pointers in the Bam file are completely read. | |
void | register_change_this (ChangeThisFunc func, TypedWritable *whom) |
Called by an object reading itself from the bam file to indicate that the object pointer that will be returned is temporary, and will eventually need to be replaced with another pointer. | |
void | finalize_now (TypedWritable *whom) |
Forces the finalization of a particular object. | |
void * | get_pta (DatagramIterator &scan) |
This function works in conjection with register_pta(), below, to read a PointerToArray (PTA) from the Bam file, and unify references to the same PTA. | |
void | register_pta (void *ptr) |
The second part of read_pta(), this should be called with the pointer to the array that was read in after read_pta() returned NULL. | |
TypeHandle | read_handle (DatagramIterator &scan) |
Reads a TypeHandle out of the Datagram. | |
Static Public Member Functions | |
WritableFactory * | get_factory () |
Returns the global WritableFactory for generating TypedWritable objects. | |
Static Public Attributes | |
BamReader *const | Null = (BamReader*)0L |
WritableFactory *const | NullFactory = (WritableFactory*)0L |
Private Types | |
typedef pmap< int, TypeHandle > | IndexMap |
typedef pmap< int, CreatedObj > | CreatedObjs |
typedef pmap< int, vector_int > | ObjectPointers |
typedef pmap< PipelineCyclerBase *, vector_int > | CyclerPointers |
typedef pset< TypedWritable * > | Finalize |
typedef pmap< int, void * > | PTAMap |
typedef pset< TypeHandle > | NewTypes |
Private Member Functions | |
int | p_read_object () |
The private implementation of read_object(), this reads an object from the file and returns its object ID. | |
bool | resolve_object_pointers (TypedWritable *object, const vector_int &pointer_ids) |
Checks whether all of the pointers a particular object is waiting for have been filled in yet. | |
bool | resolve_cycler_pointers (PipelineCyclerBase *cycler, const vector_int &pointer_ids) |
Checks whether all of the pointers a particular PipelineCycler is waiting for have been filled in yet. | |
void | finalize () |
Should be called after all objects have been read, this will finalize all the objects that registered themselves for the finalize callback. | |
Static Private Member Functions | |
void | create_factory () |
Creates a new WritableFactory for generating TypedWritable objects. | |
Private Attributes | |
DatagramGenerator * | _source |
IndexMap | _index_map |
CreatedObjs | _created_objs |
CreatedObjs::iterator | _now_creating |
PipelineCyclerBase * | _reading_cycler |
ObjectPointers | _object_pointers |
CyclerPointers | _cycler_pointers |
int | _num_extra_objects |
Finalize | _finalize_list |
PTAMap | _pta_map |
int | _pta_id |
int | _file_major |
int | _file_minor |
Static Private Attributes | |
WritableFactory * | _factory = (WritableFactory*)0L |
NewTypes | _new_types |
const int | _cur_major = _bam_major_ver |
const int | _cur_minor = _bam_minor_ver |
A Bam file can be thought of as a linear collection of objects. Each object is an instance of a class that inherits, directly or indirectly, from TypedWritable. The objects may include pointers to other objects within the Bam file; the BamReader automatically manages these (with help from code within each class) and restores the pointers correctly.
This is the abstract interface and does not specifically deal with disk files, but rather with a DatagramGenerator of some kind, which is simply a linear source of Datagrams. It is probably from a disk file, but it might conceivably be streamed directly from a network or some such nonsense.
Bam files are most often used to store scene graphs or subgraphs, and by convention they are given filenames ending in the extension ".bam" when they are used for this purpose. However, a Bam file may store any arbitrary list of TypedWritable objects; in this more general usage, they are given filenames ending in ".boo" to differentiate them from the more common scene graph files.
See also BamFile, which defines a higher-level interface to read and write Bam files on disk.
Definition at line 124 of file bamReader.h.
|
Definition at line 157 of file bamReader.h. |
|
Definition at line 196 of file bamReader.h. |
|
Definition at line 215 of file bamReader.h. |
|
Definition at line 225 of file bamReader.h. |
|
Definition at line 186 of file bamReader.h. |
|
Definition at line 238 of file bamReader.h. |
|
Definition at line 211 of file bamReader.h. |
|
Definition at line 230 of file bamReader.h. |
|
Definition at line 126 of file bamReader.h. |
|
Definition at line 49 of file bamReader.cxx. References _pta_id, _reading_cycler, and NULL. |
|
Definition at line 67 of file bamReader.cxx. References _source, DatagramGenerator::get_datagram(), and DatagramGenerator::is_error(). |
|
Creates a new WritableFactory for generating TypedWritable objects.
Definition at line 136 of file bamReader.I. Referenced by get_current_major_ver(). |
|
Should be called after all objects have been read, this will finalize all the objects that registered themselves for the finalize callback.
Definition at line 1098 of file bamReader.cxx. |
|
Forces the finalization of a particular object. This may be called by any of the objects during finalization, to guarantee finalization ordering where it is important. Definition at line 695 of file bamReader.cxx. References BamReader::CreatedObj::_change_this, _created_objs, _factory, _now_creating, _object_pointers, BamReader::CreatedObj::_ptr, FactoryParams::add_param(), Factory< TypedWritable >::make_instance_more_general(), nassertr, and NULL. |
|
Returns the major version number of Bam files supported by the current code base. This must match get_file_major_ver() in order to successfully read a file. Definition at line 85 of file bamReader.I. References _factory, create_factory(), INLINE, and NullFactory. |
|
Returns the minor version number of Bam files supported by the current code base. This must match or exceed get_file_minor_ver() in order to successfully read a file. Definition at line 104 of file bamReader.I. References DCAST, BamReaderParam::get_iterator(), FactoryParams::get_param(), and INLINE. |
|
|
Returns the major version number of the Bam file currently being read.
Definition at line 51 of file bamReader.I. References _file_minor. |
|
Returns the minor version number of the Bam file currently being read.
Definition at line 66 of file bamReader.I. References _cur_minor, and INLINE. |
|
This function works in conjection with register_pta(), below, to read a PointerToArray (PTA) from the Bam file, and unify references to the same PTA. The first time get_pta() encounters a particular PTA, it will return NULL. This is the indication that the caller should then read in the data associated with the PTA, and subsequently call register_pta() with the address of the filled-in array. The next time (and all subsequent times) that get_pta() encounters this same PTA, it will return the pointer that was passed with register_pta(). Also see the READ_PTA() macro, which consolidates all the work that must be done to read a PTA. Definition at line 746 of file bamReader.cxx. References NULL. |
|
Initializes the BamReader prior to reading any objects from its source. This includes reading the Bam header. This returns true if the BamReader successfully initialized, false otherwise. Definition at line 89 of file bamReader.cxx. References _file_major, and _file_minor. |
|
Returns true if the reader has reached end-of-file, false otherwise. This call is only valid after a call to read_object(). Definition at line 36 of file bamReader.I. References _file_major, and INLINE. |
|
The private implementation of read_object(), this reads an object from the file and returns its object ID.
Definition at line 818 of file bamReader.cxx. References NULL. |
|
Reads in the indicated CycleData object. This should be used by classes that store some or all of their data within a CycleData subclass, in support of pipelining. This will call the virtual CycleData::fillin() method to do the actual reading. Definition at line 582 of file bamReader.cxx. References _pta_id, _pta_map, DatagramIterator::get_uint16(), nassertr, and NULL. Referenced by SequenceNode::has_single_child_visibility(), GeomNode::output(), PointLight::register_with_read_factory(), PlaneNode::register_with_read_factory(), DirectionalLight::register_with_read_factory(), and PandaNode::reparent(). |
|
Reads a TypeHandle out of the Datagram.
Definition at line 379 of file bamReader.cxx. |
|
Reads a single object from the Bam file. If the object type is known, a new object of the appropriate type is created and returned; otherwise, NULL is returned. NULL is also returned when the end of the file is reached. is_eof() may be called to differentiate between these two cases. This may be called repeatedly to extract out all the objects in the Bam file, but typically (especially for scene graph files, indicated with the .bam extension), only one object is retrieved directly from the Bam file: the root of the scene graph. The remaining objects will all be retrieved recursively by the first object. Note that the object returned may not yet be complete. In particular, some of its pointers may not be filled in; you must call resolve() to fill in all the available pointers before you can safely use any objects returned by read_object(). Definition at line 189 of file bamReader.cxx. References TypedWritable::get_type(), and NULL. |
|
The interface for reading a pointer to another object from a Bam file. Objects reading themselves from a Bam file should call this when they expect to read a pointer to some other object. This function reads whatever is stored in the bam file to represent the pointer, and advances the datagram iterator accordingly. Rather than returning a pointer immediately, this function reads the internal pointer information from the datagram and queues up the request. The pointer itself may not be available until later (it may be a pointer to an object that appears later in the Bam file). Later, when all pointers are available, the complete_pointers() callback function will be called with an array of actual pointers, one for time read_pointer() was called. It is then the calling object's responsibilty to store these pointers in the object properly. Definition at line 500 of file bamReader.cxx. References _finalize_list, and TypedWritable::Null. Referenced by GeomNode::CData::complete_pointers(), PiecewiseCurve::find_curve(), CharacterJoint::has_local_transform(), TextureAttrib::write_datagram(), MaterialAttrib::write_datagram(), FogAttrib::write_datagram(), and AnimGroup::write_descendants(). |
|
A convenience function to read a contiguous list of pointers. This is equivalent to calling read_pointer() count times. Definition at line 540 of file bamReader.cxx. References BamReader::CreatedObj::_ptr, and NULL. |
|
Called by an object reading itself from the bam file to indicate that the object pointer that will be returned is temporary, and will eventually need to be replaced with another pointer. The supplied function pointer will later be called on the object, immediately after complete_pointers() is called; it should return the new and final pointer. We use a static function pointer instead of a virtual function (as in finalize()), to allow the function to destruct the old pointer if necessary. (It is invalid to destruct the this pointer within a virtual function.) Definition at line 661 of file bamReader.cxx. References _source. Referenced by RenderEffects::register_with_read_factory(). |
|
Should be called by an object reading itself from the Bam file to indicate that this particular object would like to receive the finalize() callback when all the objects and pointers in the Bam file are completely read. This provides a hook for objects (like Characters) that need to do any additional finalization work after all of their related pointers are guaranteed to be filled in. Definition at line 618 of file bamReader.cxx. Referenced by TransformState::calc_components(), RenderEffects::determine_compass(), and CharacterJointBundle::make_copy(). |
|
The second part of read_pta(), this should be called with the pointer to the array that was read in after read_pta() returned NULL. This associates the pointer with the ID that was previously read, so that future calls to read_pta() will return the same pointer. Also see the READ_PTA() macro, which consolidates all the work that must be done to read a PTA. Definition at line 795 of file bamReader.cxx. |
|
This may be called at any time during processing of the Bam file to resolve all the known pointers so far. It is usually called at the end of the processing, after all objects have been read, which is generally the best time to call it. This must be called at least once after reading a particular object via get_object() in order to validate that object. The return value is true if all objects have been resolved, or false if some objects are still outstanding (in which case you will need to call resolve() again later). Definition at line 276 of file bamReader.cxx. References _cycler_pointers. Referenced by BamFile::read_object(). |
|
Checks whether all of the pointers a particular PipelineCycler is waiting for have been filled in yet. If they have, calls complete_pointers() on the cycler and returns true; otherwise, returns false. Definition at line 1029 of file bamReader.cxx. |
|
Checks whether all of the pointers a particular object is waiting for have been filled in yet. If they have, calls complete_pointers() on the object and returns true; otherwise, returns false. Definition at line 961 of file bamReader.cxx. |
|
Reads and discards a pointer value from the Bam file. This pointer will not be counted among the pointers read for a given object, and will not be in the list of pointers passed to complete_pointers(). Definition at line 561 of file bamReader.cxx. References _finalize_list, TypedWritable::finalize(), nassertv, and NULL. |
|
Definition at line 197 of file bamReader.h. Referenced by finalize_now(). |
|
Definition at line 37 of file bamReader.cxx. |
|
Definition at line 38 of file bamReader.cxx. Referenced by get_file_minor_ver(). |
|
Definition at line 216 of file bamReader.h. Referenced by resolve(). |
|
Definition at line 31 of file bamReader.cxx. Referenced by finalize_now(), and get_current_major_ver(). |
|
Definition at line 241 of file bamReader.h. |
|
Definition at line 241 of file bamReader.h. Referenced by get_file_major_ver(), and init(). |
|
Definition at line 226 of file bamReader.h. Referenced by read_pointer(), and skip_pointer(). |
|
Definition at line 187 of file bamReader.h. |
|
Definition at line 35 of file bamReader.cxx. |
|
Definition at line 202 of file bamReader.h. Referenced by finalize_now(). |
|
Definition at line 221 of file bamReader.h. |
|
Definition at line 212 of file bamReader.h. Referenced by finalize_now(). |
|
Definition at line 232 of file bamReader.h. Referenced by BamReader(), and read_cdata(). |
|
Definition at line 231 of file bamReader.h. Referenced by read_cdata(). |
|
Definition at line 205 of file bamReader.h. Referenced by BamReader(). |
|
Definition at line 182 of file bamReader.h. Referenced by register_change_this(), and ~BamReader(). |
|
Definition at line 32 of file bamReader.cxx. |
|
Definition at line 33 of file bamReader.cxx. Referenced by get_current_major_ver(). |