Panda3D
Public Member Functions | List of all members
BamFile Class Reference

The principle public interface to reading and writing Bam disk files. See also BamReader and BamWriter, the more general implementation of this class. More...

Inheritance diagram for BamFile:
BamEnums

Public Member Functions

 __init__ ()
 
 close ()
 Closes the input or output stream. More...
 
int getCurrentMajorVer ()
 Returns the system current major version number. This is the version number that will be assigned to any generated Bam files. More...
 
int getCurrentMinorVer ()
 Returns the system current minor version number. This is the version number that will be assigned to any generated Bam files. More...
 
BamEnums::BamEndian getFileEndian ()
 Returns the endian preference indicated by the Bam file currently being read or written. More...
 
int getFileMajorVer ()
 Returns the major version number of the file currently being read, or the system current major version number if no file is currently open for reading. More...
 
int getFileMinorVer ()
 Returns the minor version number of the file currently being read, or the system current minor version number if no file is currently open for reading. 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...
 
BamReader getReader ()
 Returns the BamReader in charge of performing the read operations. This will return NULL unless open_read() was called. More...
 
BamWriter getWriter ()
 Returns the BamWriter in charge of performing the write operations. This will return NULL unless open_write() was called. More...
 
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(). More...
 
bool isValidRead ()
 Returns true if the Bam file is open and ready for reading with no errors so far detected, or false otherwise. More...
 
bool isValidWrite ()
 Returns true if the Bam file is open and ready for writing with no errors so far detected, or false otherwise. More...
 
bool openRead (const Filename bam_filename, bool report_errors)
 Attempts to open the indicated filename for reading. Returns true if successful, false on error. More...
 
bool openRead (Istream in, str bam_filename, bool report_errors)
 Attempts to open the indicated stream for reading. The filename is just for information purposes only. Returns true if successful, false on error. More...
 
bool openWrite (const Filename bam_filename, bool report_errors)
 Attempts to open the indicated file for writing. If another file by the same name already exists, it will be silently removed. Returns true if successful, false otherwise. More...
 
bool openWrite (Ostream out, str bam_filename, bool report_errors)
 Attempts to open the indicated stream for writing. The filename is just for information purposes only. Returns true if successful, false on error. More...
 
PandaNode readNode (bool report_errors)
 Although the bam file format is general enough to store a list of objects of arbitrary type, bam files on disk usually contain just one object, a PandaNode that is the root of a scene graph. (Bam files that store other kinds of things are usually given the extension "boo", for "binary other objects", to differentiate them from the normal scene graph type file.) More...
 
TypedWritable readObject ()
 Reads and returns the next object from the Bam file, or NULL if the end of the file has been reached, or if there is an error condition. Use is_eof() to differentiate these two cases. More...
 
bool resolve ()
 This must be called after one or more objects have been read via calls to read_object() in order to resolve all internal pointer references in the objects read and make all the pointers valid. It returns true if all objects are successfully resolved, or false if some have not been (in which case you must call resolve() again later). More...
 
bool writeObject (const TypedWritable object)
 Writes the indicated object to the Bam file. Returns true if successful, false on error. More...
 

Additional Inherited Members

- Public Types inherited from BamEnums
enum  BamEndian { BE_bigendian = 0, BE_littleendian = 1, BE_native = 1 }
 This defines an enumerated type used to represent the endianness of certain numeric values stored in a Bam file. It really has only two possible values, either BE_bigendian or BE_littleendian; but through a preprocessor trick we also add BE_native, which is the same numerically as whichever value the hardware supports natively. More...
 
enum  BamObjectCode {
  BOC_push = 0, BOC_pop = 1, BOC_adjunct = 2, BOC_remove = 3,
  BOC_file_data = 4
}
 This is the code written along with each object. It is used to control object scoping. A BOC_push includes an object definition, and will always be eventually paired with a BOC_pop (which does not). A BOC_adjunct includes an object definition but does not push the level; it is associated with the current level. BOC_remove lists object ID's that have been deallocated on the sender end. BOC_file_data may appear at any level and indicates the following datagram contains auxiliary file data that may be referenced by a later object. More...
 
enum  BamTextureMode {
  BTM_unchanged = 0, BTM_fullpath = 1, BTM_relative = 2, BTM_basename = 3,
  BTM_rawdata = 4
}
 This enum is used to control how textures are written to a bam stream. More...
 

Detailed Description

The principle public interface to reading and writing Bam disk files. See also BamReader and BamWriter, the more general implementation of this class.

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.

Member Function Documentation

◆ __init__()

__init__ ( )

◆ close()

close ( )

Closes the input or output stream.

◆ getCurrentMajorVer()

int getCurrentMajorVer ( )

Returns the system current major version number. This is the version number that will be assigned to any generated Bam files.

◆ getCurrentMinorVer()

int getCurrentMinorVer ( )

Returns the system current minor version number. This is the version number that will be assigned to any generated Bam files.

◆ getFileEndian()

BamEnums::BamEndian getFileEndian ( )

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

◆ getFileMajorVer()

int getFileMajorVer ( )

Returns the major version number of the file currently being read, or the system current major version number if no file is currently open for reading.

◆ getFileMinorVer()

int getFileMinorVer ( )

Returns the minor version number of the file currently being read, or the system current minor version number if no file is currently open for reading.

◆ getFileStdfloatDouble()

bool getFileStdfloatDouble ( )

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

◆ getReader()

BamReader getReader ( )

Returns the BamReader in charge of performing the read operations. This will return NULL unless open_read() was called.

◆ getWriter()

BamWriter getWriter ( )

Returns the BamWriter in charge of performing the write operations. This will return NULL unless open_write() was called.

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

◆ isValidRead()

bool isValidRead ( )

Returns true if the Bam file is open and ready for reading with no errors so far detected, or false otherwise.

◆ isValidWrite()

bool isValidWrite ( )

Returns true if the Bam file is open and ready for writing with no errors so far detected, or false otherwise.

◆ openRead() [1/2]

bool openRead ( const Filename  bam_filename,
bool  report_errors 
)

Attempts to open the indicated filename for reading. Returns true if successful, false on error.

◆ openRead() [2/2]

bool openRead ( Istream  in,
str  bam_filename,
bool  report_errors 
)

Attempts to open the indicated stream for reading. The filename is just for information purposes only. Returns true if successful, false on error.

◆ openWrite() [1/2]

bool openWrite ( const Filename  bam_filename,
bool  report_errors 
)

Attempts to open the indicated file for writing. If another file by the same name already exists, it will be silently removed. Returns true if successful, false otherwise.

◆ openWrite() [2/2]

bool openWrite ( Ostream  out,
str  bam_filename,
bool  report_errors 
)

Attempts to open the indicated stream for writing. The filename is just for information purposes only. Returns true if successful, false on error.

◆ readNode()

PandaNode readNode ( bool  report_errors)

Although the bam file format is general enough to store a list of objects of arbitrary type, bam files on disk usually contain just one object, a PandaNode that is the root of a scene graph. (Bam files that store other kinds of things are usually given the extension "boo", for "binary other objects", to differentiate them from the normal scene graph type file.)

This is a convenience method for when you believe you are reading a scene graph bam file. It reads the one PandaNode and returns it. It also calls resolve() to fully resolve the object, since we expect this will be the only object in the file.

If the bam file contains something other than a PandaNode, an error is printed and NULL is returned.

◆ readObject()

TypedWritable readObject ( )

Reads and returns the next object from the Bam file, or NULL if the end of the file has been reached, or if there is an error condition. Use is_eof() to differentiate these two cases.

The pointers returned by this method will not be valid for use until resolve() is subsequently called.

◆ resolve()

bool resolve ( )

This must be called after one or more objects have been read via calls to read_object() in order to resolve all internal pointer references in the objects read and make all the pointers valid. It returns true if all objects are successfully resolved, or false if some have not been (in which case you must call resolve() again later).

◆ writeObject()

bool writeObject ( const TypedWritable  object)

Writes the indicated object to the Bam file. Returns true if successful, false on error.