Panda3D

typedWritable.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file typedWritable.h
10 * @author jason
11 * @date 2000-06-08
12 */
13
14 #ifndef TYPEDWRITABLE_H
15 #define TYPEDWRITABLE_H
16
17 #include "typedObject.h"
18 #include "vector_typedWritable.h"
19 #include "pvector.h"
20 #include "lightMutex.h"
21 #include "updateSeq.h"
22 #include "vector_uchar.h"
23
24 class BamReader;
25 class BamWriter;
26 class Datagram;
27 class DatagramIterator;
28 class ReferenceCount;
29
30 /**
31 * Base class for objects that can be written to and read from Bam files.
32 *
33 * See also TypedObject for detailed instructions.
34 */
35 class EXPCL_PANDA_PUTIL TypedWritable : public TypedObject {
36 public:
37 static TypedWritable* const Null;
38
39 INLINE TypedWritable();
40 INLINE TypedWritable(const TypedWritable &copy);
41 INLINE void operator = (const TypedWritable &copy);
42
43 virtual ~TypedWritable();
44
45 virtual void write_datagram(BamWriter *manager, Datagram &dg);
46 virtual void update_bam_nested(BamWriter *manager);
47
48 virtual int complete_pointers(TypedWritable **p_list, BamReader *manager);
49 virtual bool require_fully_complete() const;
50
51 PUBLISHED:
52 virtual void fillin(DatagramIterator &scan, BamReader *manager);
53
54 public:
55 virtual void finalize(BamReader *manager);
56
57 virtual ReferenceCount *as_reference_count();
58
59 PUBLISHED:
60 INLINE void mark_bam_modified();
61 INLINE UpdateSeq get_bam_modified() const;
62
63 EXTENSION(PyObject *__reduce__(PyObject *self) const);
64 EXTENSION(PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const);
65
66 INLINE vector_uchar encode_to_bam_stream() const;
67 bool encode_to_bam_stream(vector_uchar &data, BamWriter *writer = nullptr) const;
68 static bool decode_raw_from_bam_stream(TypedWritable *&ptr,
69 ReferenceCount *&ref_ptr,
70 vector_uchar data,
71 BamReader *reader = nullptr);
72
73 private:
74 void add_bam_writer(BamWriter *writer);
75 void remove_bam_writer(BamWriter *writer);
76
77 // We may need to store a list of the BamWriter(s) that have a reference to
78 // this object, so that we can remove the object from those tables when it
79 // destructs.
80 struct BamWriterLink {
81 BamWriter *_writer;
82 BamWriterLink *_next;
83 };
84 AtomicAdjust::Pointer _bam_writers; // Tagged pointer
85
86 UpdateSeq _bam_modified;
87
88 public:
89 static TypeHandle get_class_type() {
90 return _type_handle;
91 }
92 static void init_type() {
93 TypedObject::init_type();
94 register_type(_type_handle, "TypedWritable",
95 TypedObject::get_class_type());
96 TypeRegistry::ptr()->record_alternate_name(_type_handle, "TypedWriteable");
97 }
98 virtual TypeHandle get_type() const {
99 return get_class_type();
100 }
101 virtual TypeHandle force_init_type() {
102 init_type();
103 return get_class_type();
104 }
105
106 private:
107 static TypeHandle _type_handle;
108
109 friend class BamWriter;
110 };
111
112 #include "typedWritable.I"
113
114 #endif
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
ReferenceCount
A base class for all things that want to be reference-counted.
Definition: referenceCount.h:38
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypeRegistry::record_alternate_name
void record_alternate_name(TypeHandle type, const std::string &name)
Indicates an alternate name for the same type.
Definition: typeRegistry.cxx:189
TypeRegistry::ptr
static TypeRegistry * ptr()
Returns the pointer to the global TypeRegistry object.
Definition: typeRegistry.I:30
TypedObject
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:88
TypedObject::init_type
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:44
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
UpdateSeq
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
lightMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedWritable.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
updateSeq.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_typedWritable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
vector_uchar.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.