54 if (!_din.
open(bam_filename)) {
58 return continue_open_read(bam_filename, report_errors);
66 open_read(std::istream &in,
const string &bam_filename,
bool report_errors) {
73 return continue_open_read(bam_filename, report_errors);
86 if (_reader ==
nullptr) {
99 return _reader !=
nullptr && _reader->
is_eof();
111 if (_reader ==
nullptr) {
134 read_node(
bool report_errors) {
139 if (
object !=
nullptr &&
148 if (
object == TypedWritable::Null) {
150 loader_cat.error() <<
"Bam file " << _bam_filename <<
" is empty.\n";
153 }
else if (!object->
is_of_type(PandaNode::get_class_type())) {
156 <<
"Bam file " << _bam_filename
157 <<
" contains a " <<
object->get_type() <<
", not a PandaNode.\n";
167 <<
"Ignoring extra objects in " << _bam_filename <<
"\n";
175 <<
"Unable to resolve Bam file.\n";
195 if (!_dout.
open(bam_filename)) {
197 loader_cat.error() <<
"Unable to open " << bam_filename <<
"\n";
202 return continue_open_write(bam_filename, report_errors);
210 open_write(std::ostream &out,
const string &bam_filename,
bool report_errors) {
213 if (!_dout.
open(out)) {
214 loader_cat.error() <<
"Could not write bam: " << bam_filename <<
"\n";
218 return continue_open_write(bam_filename, report_errors);
227 if (_writer ==
nullptr) {
244 if (_reader !=
nullptr) {
249 if (_writer !=
nullptr) {
265 if (_reader ==
nullptr) {
266 return _bam_major_ver;
278 if (_reader ==
nullptr) {
279 return _bam_minor_ver;
288 BamFile::BamEndian BamFile::
289 get_file_endian()
const {
290 if (_writer !=
nullptr) {
293 if (_reader !=
nullptr) {
305 get_file_stdfloat_double()
const {
306 if (_writer !=
nullptr) {
309 if (_reader !=
nullptr) {
313 return bam_stdfloat_double;
322 return _bam_major_ver;
331 return _bam_minor_ver;
357 continue_open_read(
const string &bam_filename,
bool report_errors) {
358 _bam_filename = bam_filename;
360 if (!_bam_filename.empty()) {
362 <<
"Reading " << _bam_filename <<
"\n";
368 loader_cat.error() << _bam_filename <<
" is not a valid BAM file.\n";
373 if (head != _bam_header) {
375 loader_cat.error() << _bam_filename <<
" is not a valid BAM file.\n";
381 if (!_reader->
init()) {
394 continue_open_write(
const string &bam_filename,
bool report_errors) {
395 _bam_filename = bam_filename;
397 if (!_bam_filename.empty()) {
398 loader_cat.info() <<
"Writing " << _bam_filename <<
"\n";
403 loader_cat.error() <<
"Unable to write to " << _bam_filename <<
"\n";
410 if (!_writer->
init()) {
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
A basic node of the scene graph or data graph.
bool open_read(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated filename for reading.
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
bool resolve()
This must be called after one or more objects have been read via calls to read_object() in order to r...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT(PandaNode) BamFile
Although the bam file format is general enough to store a list of objects of arbitrary type,...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool resolve()
This may be called at any time during processing of the Bam file to resolve all the known pointers so...
int get_file_major_ver()
Returns the major version number of the file currently being read, or the system current major versio...
A hierarchy of directories and files that appears to be one continuous file system,...
TypedWritable * read_object()
Reads a single object from the Bam file.
Base class for objects that can be written to and read from Bam files.
bool write_header(const std::string &header)
Writes a sequence of bytes to the beginning of the datagram file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void close()
Closes the input or output stream.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
bool open(const FileReference *file)
Opens the indicated filename for writing.
int get_file_major_ver() const
Returns the major version number of the Bam file currently being read.
bool init()
Initializes the BamReader prior to reading any objects from its source.
bool is_eof() const
Returns true if the reader has reached end-of-file, false otherwise.
get_file_stdfloat_double
Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit ...
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_current_minor_ver()
Returns the system current minor version number.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool write_object(const TypedWritable *obj)
Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly rest...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_current_major_ver()
Returns the system current major version number.
get_file_endian
Returns the endian preference indicated by the Bam file currently being read.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
get_file_endian
Returns the endian preference indicated by the Bam file currently being written.
get_file_stdfloat_double
Returns true if the file will store all "standard" floats as 64-bit doubles, or false if they are 32-...
bool delete_file(const Filename &filename)
Attempts to delete the indicated file or directory.
bool open_write(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated file for writing.
void close()
Closes the file.
bool init()
Initializes the BamWriter prior to writing any objects to its output stream.
int get_file_minor_ver()
Returns the minor version number of the file currently being read, or the system current minor versio...
bool is_eof() const
Returns true if the reader has reached end-of-file, false otherwise.
TypedWritable * read_object()
Reads and returns the next object from the Bam file, or NULL if the end of the file has been reached,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.