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