54 if (!_din.open(bam_filename)) {
58 return continue_open_read(bam_filename, report_errors);
66open_read(std::istream &in,
const string &bam_filename,
bool report_errors) {
73 return continue_open_read(bam_filename, report_errors);
86 if (_reader ==
nullptr) {
90 return _reader->read_object();
99 return _reader !=
nullptr && _reader->is_eof();
111 if (_reader ==
nullptr) {
115 return _reader->resolve();
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";
194 vfs->delete_file(bam_filename);
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);
210open_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) {
231 if (!_writer->write_object(
object)) {
244 if (_reader !=
nullptr) {
249 if (_writer !=
nullptr) {
265 if (_reader ==
nullptr) {
266 return _bam_major_ver;
268 return _reader->get_file_major_ver();
278 if (_reader ==
nullptr) {
279 return _bam_minor_ver;
281 return _reader->get_file_minor_ver();
290 if (_writer !=
nullptr) {
293 if (_reader !=
nullptr) {
294 return _reader->get_file_endian();
306 if (_writer !=
nullptr) {
307 return _writer->get_file_stdfloat_double();
309 if (_reader !=
nullptr) {
310 return _reader->get_file_stdfloat_double();
313 return bam_stdfloat_double;
322 return _bam_major_ver;
331 return _bam_minor_ver;
357continue_open_read(
const string &bam_filename,
bool report_errors) {
358 _bam_filename = bam_filename;
360 if (!_bam_filename.empty()) {
362 <<
"Reading " << _bam_filename <<
"\n";
366 if (!_din.read_header(head, _bam_header.size())) {
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";
380 _reader =
new BamReader(&_din);
381 if (!_reader->init()) {
394continue_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";
401 if (!_dout.write_header(_bam_header)) {
403 loader_cat.error() <<
"Unable to write to " << _bam_filename <<
"\n";
408 _writer =
new BamWriter(&_dout);
410 if (!_writer->init()) {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_file_stdfloat_double
Returns true if the file stores all "standard" floats as 64-bit doubles, or false if they are 32-bit ...
int get_current_major_ver()
Returns the system current major version number.
void close()
Closes the input or output stream.
int get_current_minor_ver()
Returns the system current minor version number.
int get_file_minor_ver()
Returns the minor version number of the file currently being read, or the system current minor versio...
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,...
bool open_write(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated file for writing.
TypedWritable * read_object()
Reads and returns the next object from the Bam file, or NULL if the end of the file has been reached,...
int get_file_major_ver()
Returns the major version number of the file currently being read, or the system current major versio...
get_file_endian
Returns the endian preference indicated by the Bam file currently being read or written.
bool open_read(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated filename for reading.
get_writer
Returns the BamWriter in charge of performing the write operations.
get_reader
Returns the BamReader in charge of performing the read operations.
bool resolve()
This must be called after one or more objects have been read via calls to read_object() in order to r...
bool is_eof() const
Returns true if the reader has reached end-of-file, false otherwise.
bool write_object(const TypedWritable *object)
Writes the indicated object to the Bam file.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
get_file_endian
Returns the endian preference indicated by the Bam file currently being written.
The name of a file, such as a texture file or an Egg file.
A basic node of the scene graph or data graph.
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Base class for objects that can be written to and read from Bam files.
A hierarchy of directories and files that appears to be one continuous file system,...
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.