Panda3D

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
BamFile Class Reference

The principle public interface to reading and writing Bam disk files. More...

`#include "bamFile.h"`

Inheritance diagram for BamFile:

## Public Member Functions
void | close ()
| Closes the input or output stream.
int | get_current_major_ver ()
| Returns the system current major version number.
int | get_current_minor_ver ()
| Returns the system current minor version number.
BamEndian | get_file_endian () const
int | get_file_major_ver ()
| 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.
int | get_file_minor_ver ()
| 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.
bool | get_file_stdfloat_double () const
BamReader * | get_reader ()
BamWriter * | get_writer ()
bool | is_eof () const
| Returns true if the reader has reached end-of-file, false otherwise.
bool | is_valid_read () const
| Returns true if the Bam file is open and ready for reading with no errors so far detected, or false otherwise.
bool | is_valid_write () const
| Returns true if the Bam file is open and ready for writing with no errors so far detected, or false otherwise.
bool | open_read (const Filename &bam_filename, bool report_errors=true)
| Attempts to open the indicated filename for reading.
bool | open_read (std::istream &in, const std::string &bam_filename="stream", bool report_errors=true)
| Attempts to open the indicated stream for reading.
bool | open_write (const Filename &bam_filename, bool report_errors=true)
| Attempts to open the indicated file for writing.
bool | open_write (std::ostream &out, const std::string &bam_filename="stream", bool report_errors=true)
| Attempts to open the indicated stream for writing.
PointerTo< PandaNode > | read_node (bool report_errors=true)
| 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.
TypedWritable * | read_object ()
| 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.
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.
bool | write_object (const TypedWritable *object)
| Writes the indicated object to the Bam file.

## Public Attributes
| get_file_endian
| Returns the endian preference indicated by the Bam file currently being read or written.
| get_file_stdfloat_double
| Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit floats.
| get_file_version
| get_reader
| Returns the BamReader in charge of performing the read operations.
| get_writer
| Returns the BamWriter in charge of performing the write operations.

## 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. More...
enum | BamObjectCode { BOC_push , BOC_pop , BOC_adjunct , BOC_remove , BOC_file_data }
| This is the code written along with each object. More...
enum | BamTextureMode { BTM_unchanged , BTM_fullpath , BTM_relative , BTM_basename , BTM_rawdata }

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

Definition at line 41 of file bamFile.h.

## Constructor & Destructor Documentation

## ◆ BamFile()

BamFile::BamFile | ( |  | ) |

Definition at line 32 of file bamFile.cxx.

## ◆ ~BamFile()

BamFile::~BamFile | ( |  | ) |

Definition at line 41 of file bamFile.cxx.

## Member Function Documentation

## ◆ close()

void BamFile::close | ( |  | ) |

Closes the input or output stream.

Definition at line 242 of file bamFile.cxx.

Referenced by open_read(), open_read(), open_write(), open_write(), NodePath::write_bam_file(), NodePath::write_bam_stream(), and write_object().

## ◆ get_current_major_ver()

int BamFile::get_current_major_ver | ( |  | ) |

Returns the system current major version number.

This is the version number that will be assigned to any generated Bam files.

Definition at line 320 of file bamFile.cxx.

## ◆ get_current_minor_ver()

int BamFile::get_current_minor_ver | ( |  | ) |

Returns the system current minor version number.

This is the version number that will be assigned to any generated Bam files.

Definition at line 329 of file bamFile.cxx.

## ◆ get_file_major_ver()

int BamFile::get_file_major_ver | ( |  | ) |

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.

Definition at line 263 of file bamFile.cxx.

## ◆ get_file_minor_ver()

int BamFile::get_file_minor_ver | ( |  | ) |

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.

Definition at line 276 of file bamFile.cxx.

## ◆ is_eof()

bool BamFile::is_eof | ( |  | ) | const

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 97 of file bamFile.cxx.

Referenced by read_node().

## ◆ is_valid_read()

bool BamFile::is_valid_read | ( |  | ) | const
| inline

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

Definition at line 18 of file bamFile.I.

## ◆ is_valid_write()

bool BamFile::is_valid_write | ( |  | ) | const
| inline

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

Definition at line 28 of file bamFile.I.

## ◆ open_read() [1/2]

bool BamFile::open_read | ( | const Filename & | bam_filename,
|  | bool | report_errors = true )

Attempts to open the indicated filename for reading.

Returns true if successful, false on error.

Definition at line 50 of file bamFile.cxx.

References close().

Referenced by WindowFramework::get_shuttle_controls_font(), and Loader::load_bam_stream().

## ◆ open_read() [2/2]

bool BamFile::open_read | ( | std::istream & | in,
|  | const std::string & | bam_filename = "stream",
|  | bool | report_errors = true )

Attempts to open the indicated stream for reading.

The filename is just for information purposes only. Returns true if successful, false on error.

Definition at line 65 of file bamFile.cxx.

References close().

## ◆ open_write() [1/2]

bool BamFile::open_write | ( | const Filename & | bam_filename,
|  | bool | report_errors = true )

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.

Definition at line 189 of file bamFile.cxx.

References close(), and VirtualFileSystem::get_global_ptr().

Referenced by NodePath::write_bam_file(), and NodePath::write_bam_stream().

## ◆ open_write() [2/2]

bool BamFile::open_write | ( | std::ostream & | out,
|  | const std::string & | bam_filename = "stream",
|  | bool | report_errors = true )

Attempts to open the indicated stream for writing.

The filename is just for information purposes only. Returns true if successful, false on error.

Definition at line 209 of file bamFile.cxx.

References close().

## ◆ read_node()

PointerTo< PandaNode > BamFile::read_node | ( | bool | report_errors = true | ) |

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.

Definition at line 133 of file bamFile.cxx.

References is_eof(), TypedObject::is_exact_type(), TypedObject::is_of_type(), read_object(), and resolve().

Referenced by WindowFramework::get_shuttle_controls_font(), and Loader::load_bam_stream().

## ◆ read_object()

TypedWritable * BamFile::read_object | ( |  | ) |

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.

Definition at line 84 of file bamFile.cxx.

Referenced by read_node().

## ◆ resolve()

bool BamFile::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).

Definition at line 109 of file bamFile.cxx.

Referenced by read_node().

## ◆ write_object()

bool BamFile::write_object | ( | const TypedWritable * | object | ) |

Writes the indicated object to the Bam file.

Returns true if successful, false on error.

Definition at line 225 of file bamFile.cxx.

References close().

Referenced by NodePath::write_bam_file(), and NodePath::write_bam_stream().

## Member Data Documentation

## ◆ get_file_endian

BamFile::BamEndian BamFile::get_file_endian

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

Definition at line 82 of file bamFile.h.

## ◆ get_file_stdfloat_double

bool BamFile::get_file_stdfloat_double

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

Definition at line 83 of file bamFile.h.

## ◆ get_file_version

BamFile::get_file_version

Definition at line 81 of file bamFile.h.

## ◆ get_reader

BamReader * BamFile::get_reader

Returns the BamReader in charge of performing the read operations.

This will return NULL unless open_read() was called.

Definition at line 85 of file bamFile.h.

## ◆ get_writer

BamWriter * BamFile::get_writer

Returns the BamWriter in charge of performing the write operations.

This will return NULL unless open_write() was called.

Definition at line 86 of file bamFile.h.

Referenced by NodePath::write_bam_file(), and NodePath::write_bam_stream().

The documentation for this class was generated from the following files:

- panda/src/pgraph/bamFile.h
- panda/src/pgraph/bamFile.cxx
- panda/src/pgraph/bamFile.I