Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BamWriter Class Reference

This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by a BamReader. More...

#include <bamWriter.h>

List of all members.

Public Member Functions

 BamWriter (DatagramSink *sink)
 ~BamWriter ()
bool init ()
 Initializes the BamWriter prior to writing any objects to its output stream.

bool write_object (const TypedWritable *obj)
 Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly restore the object and all its pointers.

bool has_object (const TypedWritable *obj) const
 Returns true if the object has previously been written (or at least requested to be written) to the bam file, or false if we've never heard of it before.

void write_pointer (Datagram &packet, const TypedWritable *dest)
 The interface for writing a pointer to another object to a Bam file.

void write_cdata (Datagram &packet, const PipelineCyclerBase &cycler)
 Writes out the indicated CycleData object.

bool register_pta (Datagram &packet, const void *ptr)
 Prepares to write a PointerToArray to the Bam file, unifying references to the same pointer across the Bam file.

void write_handle (Datagram &packet, TypeHandle type)
 Writes a TypeHandle to the file in such a way that the BamReader can read the same TypeHandle later via read_handle().


Private Types

typedef pmap< const TypedWritable *,
StoreState
StateMap
typedef pdeque< const TypedWritable * > ObjectQueue
typedef pmap< const void *,
int > 
PTAMap

Private Member Functions

int enqueue_object (const TypedWritable *object)
 Assigns an object ID to the object and queues it up for later writing to the Bam file.


Private Attributes

pset< int > _types_written
StateMap _state_map
int _next_object_id
ObjectQueue _object_queue
PTAMap _pta_map
int _next_pta_id
DatagramSink_target


Detailed Description

This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by a BamReader.

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; the BamWriter automatically manages these (with help from code within each class) and writes all referenced objects to the file in such a way that the pointers may be correctly restored later.

This is the abstract interface and does not specifically deal with disk files, but rather with a DatagramSink of some kind, which simply accepts a linear stream of Datagrams. It is probably written to a disk file, but it might conceivably be streamed directly to 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.

Definition at line 111 of file bamWriter.h.


Member Typedef Documentation

typedef pdeque<const TypedWritable *> BamWriter::ObjectQueue [private]
 

Definition at line 157 of file bamWriter.h.

typedef pmap<const void *, int> BamWriter::PTAMap [private]
 

Definition at line 162 of file bamWriter.h.

typedef pmap<const TypedWritable *, StoreState> BamWriter::StateMap [private]
 

Definition at line 149 of file bamWriter.h.


Constructor & Destructor Documentation

BamWriter::BamWriter DatagramSink sink  ) 
 

Definition at line 39 of file bamWriter.cxx.

BamWriter::~BamWriter  ) 
 

Definition at line 52 of file bamWriter.cxx.

References _next_object_id, _next_pta_id, _target, Datagram::add_uint16(), and DatagramSink::put_datagram().


Member Function Documentation

int BamWriter::enqueue_object const TypedWritable object  )  [private]
 

Assigns an object ID to the object and queues it up for later writing to the Bam file.

The return value is the object ID, or 0 if there is an error.

Definition at line 462 of file bamWriter.cxx.

bool BamWriter::has_object const TypedWritable obj  )  const
 

Returns true if the object has previously been written (or at least requested to be written) to the bam file, or false if we've never heard of it before.

Definition at line 234 of file bamWriter.cxx.

Referenced by PandaNode::CData::fillin().

bool BamWriter::init void   ) 
 

Initializes the BamWriter prior to writing any objects to its output stream.

This includes writing out the Bam header.

This returns true if the BamWriter successfully initialized, false otherwise.

Definition at line 74 of file bamWriter.cxx.

bool BamWriter::register_pta Datagram packet,
const void *  ptr
 

Prepares to write a PointerToArray to the Bam file, unifying references to the same pointer across the Bam file.

The writing object should call this prior to writing out a PointerToArray. It will return true if the same pointer has been written previously, in which case the writing object need do nothing further; or it will return false if this particular pointer has not yet been written, in which case the writing object must then write out the contents of the array.

Also see the WRITE_PTA() macro, which consolidates the work that must be done to write a PTA.

Definition at line 348 of file bamWriter.cxx.

void BamWriter::write_cdata Datagram packet,
const PipelineCyclerBase cycler
 

Writes out the indicated CycleData object.

This should be used by classes that store some or all of their data within a CycleData subclass, in support of pipelining. This will call the virtual CycleData::write_datagram() method to do the actual writing.

Definition at line 307 of file bamWriter.cxx.

Referenced by SwitchNode::cull_callback(), SequenceNode::cull_callback(), Light::get_viz(), PlaneNode::output(), PointLight::write(), and DirectionalLight::write().

void BamWriter::write_handle Datagram packet,
TypeHandle  type
 

Writes a TypeHandle to the file in such a way that the BamReader can read the same TypeHandle later via read_handle().

Definition at line 407 of file bamWriter.cxx.

References _state_map.

bool BamWriter::write_object const TypedWritable obj  ) 
 

Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly restore the object and all its pointers.

This implicitly also writes any additional objects this object references (if they haven't already been written), so that pointers may be fully resolved.

This may be called repeatedly to write a sequence of objects to the Bam file, but typically (especially for scene graph files, indicated with the .bam extension), only one object is written directly from the Bam file: the root of the scene graph. The remaining objects will all be written recursively by the first object.

Returns true if the object is successfully written, false otherwise.

Definition at line 137 of file bamWriter.cxx.

void BamWriter::write_pointer Datagram packet,
const TypedWritable dest
 

The interface for writing a pointer to another object to a Bam file.

This is intended to be called by the various objects that write themselves to the Bam file, within the write_datagram() method.

This writes the pointer out in such a way that the BamReader will be able to restore the pointer later. If the pointer is to an object that has not yet itself been written to the Bam file, that object will automatically be written.

Definition at line 266 of file bamWriter.cxx.

References _next_pta_id, _pta_map, Datagram::add_uint16(), nassertr, and NULL.

Referenced by CharacterJoint::add_local_transform(), PandaNode::CData::make_copy(), GeomNode::CData::make_copy(), AnimGroup::output(), RenderEffects::return_new(), PartBundleNode::safe_to_flatten(), and PandaNode::CData::write_up_list().


Member Data Documentation

int BamWriter::_next_object_id [private]
 

Definition at line 153 of file bamWriter.h.

Referenced by ~BamWriter().

int BamWriter::_next_pta_id [private]
 

Definition at line 164 of file bamWriter.h.

Referenced by write_pointer(), and ~BamWriter().

ObjectQueue BamWriter::_object_queue [private]
 

Definition at line 158 of file bamWriter.h.

PTAMap BamWriter::_pta_map [private]
 

Definition at line 163 of file bamWriter.h.

Referenced by write_pointer().

StateMap BamWriter::_state_map [private]
 

Definition at line 150 of file bamWriter.h.

Referenced by write_handle().

DatagramSink* BamWriter::_target [private]
 

Definition at line 167 of file bamWriter.h.

Referenced by ~BamWriter().

pset<int> BamWriter::_types_written [private]
 

Definition at line 137 of file bamWriter.h.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:47:33 2003 for Panda by doxygen1.3