Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
BamReader Class Reference

This is the fundamental interface for extracting binary objects from a Bam file, as generated by a BamWriter. More...

Inheritance diagram for BamReader:
BamEnums

Public Member Functions

 __init__ (DatagramGenerator source)
 
bool changePointer (const TypedWritable orig_pointer, const TypedWritable new_pointer)
 Indicates that an object recently read from the bam stream should be replaced with a new object. More...
 
BamReader::AuxData getAuxData (TypedWritable obj, str name)
 Returns the pointer previously associated with the bam reader by a previous call to set_aux_data(), or NULL if data with the indicated key has not been set. More...
 
int getCurrentMajorVer ()
 Returns the major version number of Bam files supported by the current code base. More...
 
int getCurrentMinorVer ()
 Returns the minor version number of Bam files supported by the current code base. More...
 
BamEnums::BamEndian getFileEndian ()
 Returns the endian preference indicated by the Bam file currently being read. More...
 
int getFileMajorVer ()
 Returns the major version number of the Bam file currently being read. More...
 
int getFileMinorVer ()
 Returns the minor version number of the Bam file currently being read. More...
 
const Filename getFilename ()
 If a BAM is a file, then the BamReader should contain the name of the file. More...
 
bool getFileStdfloatDouble ()
 Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit floats. More...
 
object getFileVersion ()
 
const LoaderOptions getLoaderOptions ()
 Returns the LoaderOptions passed to the loader when the model was requested, if any. More...
 
DatagramGenerator getSource ()
 Returns the current source of the BamReader as set by set_source() or the constructor. More...
 
bool init ()
 Initializes the BamReader prior to reading any objects from its source. More...
 
bool isEof ()
 Returns true if the reader has reached end-of-file, false otherwise. More...
 
TypedWritable readObject ()
 Reads a single object from the Bam file. More...
 
bool resolve ()
 This may be called at any time during processing of the Bam file to resolve all the known pointers so far. More...
 
 setAuxData (TypedWritable obj, str name, BamReader::AuxData data)
 Associates an arbitrary block of data with the indicated object (or NULL), and the indicated name. More...
 
 setLoaderOptions (const LoaderOptions options)
 Specifies the LoaderOptions for this BamReader. More...
 
 setSource (DatagramGenerator source)
 Changes the source of future datagrams for this BamReader. More...
 
- Public Member Functions inherited from BamEnums
 __init__ ()
 
 __init__ (const BamEnums)
 

Static Public Member Functions

static registerFactory (TypeHandle handle, object func)
 

Public Attributes

BamEnums::BamEndian file_endian
 Returns the endian preference indicated by the Bam file currently being read. More...
 
bool file_stdfloat_double
 Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit floats. More...
 
object file_version
 
const Filename filename
 If a BAM is a file, then the BamReader should contain the name of the file. More...
 
const LoaderOptions loader_options
 Returns the LoaderOptions passed to the loader when the model was requested, if any. More...
 
DatagramGenerator source
 Returns the current source of the BamReader as set by set_source() or the constructor. More...
 

Additional Inherited Members

- Public Types inherited from BamEnums
enum  BamEndian { BE_bigendian = 0, BE_littleendian = 1, BE_native = 1 }
 
enum  BamObjectCode {
  BOC_push = 0, BOC_pop = 1, BOC_adjunct = 2, BOC_remove = 3,
  BOC_file_data = 4
}
 
enum  BamTextureMode {
  BTM_unchanged = 0, BTM_fullpath = 1, BTM_relative = 2, BTM_basename = 3,
  BTM_rawdata = 4
}
 

Detailed Description

This is the fundamental interface for extracting binary objects from a Bam file, as generated by a BamWriter.

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.

Member Function Documentation

◆ __init__()

__init__ ( DatagramGenerator  source)

◆ changePointer()

bool changePointer ( const TypedWritable  orig_pointer,
const TypedWritable  new_pointer 
)

Indicates that an object recently read from the bam stream should be replaced with a new object.

Any future occurrences of the original object in the stream will henceforth return the new object instead.

The return value is true if the replacement was successfully made, or false if the object was not read from the stream (or if change_pointer had already been called on it).

◆ getAuxData()

BamReader::AuxData getAuxData ( TypedWritable  obj,
str  name 
)

Returns the pointer previously associated with the bam reader by a previous call to set_aux_data(), or NULL if data with the indicated key has not been set.

◆ getCurrentMajorVer()

int getCurrentMajorVer ( )

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.

◆ getCurrentMinorVer()

int getCurrentMinorVer ( )

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.

◆ getFileEndian()

BamEnums::BamEndian getFileEndian ( )

Returns the endian preference indicated by the Bam file currently being read.

This does not imply that every number is stored using the indicated convention, but individual objects may choose to respect this flag when recording data.

◆ getFileMajorVer()

int getFileMajorVer ( )

Returns the major version number of the Bam file currently being read.

◆ getFileMinorVer()

int getFileMinorVer ( )

Returns the minor version number of the Bam file currently being read.

◆ getFilename()

const Filename getFilename ( )

If a BAM is a file, then the BamReader should contain the name of the file.

This enables the reader to interpret pathnames in the BAM as relative to the directory containing the BAM.

◆ getFileStdfloatDouble()

bool getFileStdfloatDouble ( )

Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit floats.

This is determined by the compilation flags of the version of Panda that generated this file.

◆ getFileVersion()

object getFileVersion ( )

◆ getLoaderOptions()

const LoaderOptions getLoaderOptions ( )

Returns the LoaderOptions passed to the loader when the model was requested, if any.

◆ getSource()

DatagramGenerator getSource ( )

Returns the current source of the BamReader as set by set_source() or the constructor.

◆ init()

bool init ( )

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.

◆ isEof()

bool isEof ( )

Returns true if the reader has reached end-of-file, false otherwise.

This call is only valid after a call to read_object().

◆ readObject()

TypedWritable readObject ( )

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().

This flavor of read_object() requires the caller to know what type of object it has received in order to properly manage the reference counts.

◆ registerFactory()

static registerFactory ( TypeHandle  handle,
object  func 
)
static

◆ resolve()

bool resolve ( )

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).

◆ setAuxData()

setAuxData ( TypedWritable  obj,
str  name,
BamReader::AuxData  data 
)

Associates an arbitrary block of data with the indicated object (or NULL), and the indicated name.

This is intended to provide a place for temporary storage for objects reading themselves from the bam file. To use it, inherit from BamReader::AuxData and store whatever data you like there. Then associate your AuxData with the object as it is being read with set_aux_data(). You may later set the aux data to NULL to remove it; or it will automatically be removed (and deleted) after finalize() is called for the object in question.

If the TypedWritable pointer is NULL, the the aux data is stored globally for the BamReader in general. This pointer is available to any bam objects, and will not be automatically removed until the BamReader itself destructs.

In either case, the name is just an arbitrary user-defined key. If there is already a data pointer stored for the obj/name pair, that data pointer will be replaced (and deleted).

◆ setLoaderOptions()

setLoaderOptions ( const LoaderOptions  options)

Specifies the LoaderOptions for this BamReader.

◆ setSource()

setSource ( DatagramGenerator  source)

Changes the source of future datagrams for this BamReader.

This also implicitly calls init() if it has not already been called.

Member Data Documentation

◆ file_endian

BamEnums::BamEndian file_endian

Returns the endian preference indicated by the Bam file currently being read.

This does not imply that every number is stored using the indicated convention, but individual objects may choose to respect this flag when recording data.

◆ file_stdfloat_double

bool file_stdfloat_double

Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit floats.

This is determined by the compilation flags of the version of Panda that generated this file.

◆ file_version

object file_version

◆ filename

const Filename filename

If a BAM is a file, then the BamReader should contain the name of the file.

This enables the reader to interpret pathnames in the BAM as relative to the directory containing the BAM.

◆ loader_options

const LoaderOptions loader_options

Returns the LoaderOptions passed to the loader when the model was requested, if any.

◆ source

Returns the current source of the BamReader as set by set_source() or the constructor.