15 #include "typedWritable.h"
16 #include "bamWriter.h"
17 #include "bamReader.h"
18 #include "datagramOutputFile.h"
19 #include "datagramInputFile.h"
20 #include "lightMutexHolder.h"
37 if (link == (BamWriterLink *)NULL) {
41 link = (BamWriterLink *)(((uintptr_t)link) & ~(uintptr_t)0x1);
43 compare_and_exchange_ptr(_bam_writers, (
void *)link, (
void *)NULL));
45 while (link != (BamWriterLink *)NULL) {
46 BamWriterLink *next_link = link->_next;
47 link->_writer->object_destructs(
this);
176 if (!dout.
open(stream)) {
180 if (writer == NULL) {
188 if (!writer.
init()) {
243 if (!din.
open(stream)) {
247 if (reader == NULL) {
254 if (head != _bam_header) {
259 if (!reader.
init()) {
271 if (ref_ptr == NULL) {
293 if (ref_ptr == NULL) {
325 BamWriterLink *begin;
326 BamWriterLink *new_link =
new BamWriterLink;
327 new_link->_writer = writer;
330 nassertv(((uintptr_t)new_link & (uintptr_t)0x1) == 0);
335 begin = (BamWriterLink *)(((uintptr_t)begin) & ~(uintptr_t)0x1);
336 new_link->_next = begin;
338 compare_and_exchange_ptr(_bam_writers, (
void *)begin, (
void *)new_link));
351 BamWriterLink *begin;
357 begin = (BamWriterLink *)(((uintptr_t)begin) & ~(uintptr_t)0x1);
363 compare_and_exchange_ptr(_bam_writers, (
void *)begin,
364 (
void *)((uintptr_t)begin | (uintptr_t)0x1)));
367 BamWriterLink *prev_link = (BamWriterLink *)NULL;
368 BamWriterLink *link = begin;
370 while (link != NULL && link->_writer != writer) {
375 if (link == (BamWriterLink *)NULL) {
377 _bam_writers = (
void *)begin;
381 if (prev_link == (BamWriterLink *)NULL) {
383 _bam_writers = (
void *)link->_next;
385 prev_link->_next = link->_next;
386 _bam_writers = (
void *)begin;
void set_source(DatagramGenerator *source)
Changes the source of future datagrams for this BamReader.
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual ReferenceCount * as_reference_count()
Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that 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...
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 string &header)
Writes a sequence of bytes to the beginning of the datagram file.
void set_target(DatagramSink *target)
Changes the destination of future datagrams written by the BamWriter.
static bool decode_raw_from_bam_stream(TypedWritable *&ptr, ReferenceCount *&ref_ptr, const string &data, BamReader *reader=NULL)
Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
bool open(const FileReference *file)
Opens the indicated filename for writing.
bool init()
Initializes the BamReader prior to reading any objects from its source.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
virtual bool unref() const
Explicitly decrements the reference count.
A trivial implementation for atomic adjustments for systems that don't require multiprogramming, and therefore don't require special atomic operations.
bool write_object(const TypedWritable *obj)
Writes a single object to the Bam file, so that the BamReader::read_object() can later correctly rest...
This class can be used to write a binary file that consists of an arbitrary header followed by a numb...
A base class for all things that want to be reference-counted.
string encode_to_bam_stream() const
Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that da...
void ref() const
Explicitly increments the reference count.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void update_bam_nested(BamWriter *manager)
Called by the BamWriter when this object has not itself been modified recently, but it should check i...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool init()
Initializes the BamWriter prior to writing any objects to its output stream.