Panda3D
writableConfigurable.h
1 // Filename: writableConfigurable.h
2 // Created by: jason (19Jun00)
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 //
16 #ifndef WRITABLECONFIGURABLE_H
17 #define WRITABLECONFIGURABLE_H
18 //
19 ////////////////////////////////////////////////////////////////////
20 // Includes
21 ////////////////////////////////////////////////////////////////////
22 
23 #include "pandabase.h"
24 
25 #include "typedWritable.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Defines
29 ////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : WritableConfigurable
33 // Description : Defined as a fix to allow creating Configurable and
34 // Writable objects. Otherwise the compiler gets
35 // confused since both TypedWritable and Configurable
36 // inherit from TypedObject.
37 //
38 // An object that has data or parameters that are set
39 // less frequently (at least occasionally) than every
40 // frame. We can cache the configuration info by
41 // by using the "dirty" flag.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_PANDA_PUTIL WritableConfigurable : public TypedWritable {
44 
45 public:
46  WritableConfigurable( void ) { make_dirty(); }
47  virtual void config( void ) { _dirty = false; }
48  INLINE void check_config() const {
49  if (_dirty) {
50  // This is a sneaky trick to allow check_config() to be called
51  // from a const member function. Even though we will be calling
52  // config(), a non-const function that modifies the class
53  // object, in some sense it's not really modifying the class
54  // object--it's just updating a few internal settings for
55  // consistency.
56  ((WritableConfigurable *)this)->config();
57  }
58  }
59 
60  INLINE bool is_dirty() const { return _dirty; }
61  INLINE void make_dirty() { _dirty = true; }
62 
63 private:
64  bool _dirty;
65 
66 public:
67  virtual void write_datagram(BamWriter*, Datagram&) = 0;
68 
69 PUBLISHED:
70  static TypeHandle get_class_type() {
71  return _type_handle;
72  }
73 
74 public:
75  static void init_type() {
76  TypedWritable::init_type();
77  register_type(_type_handle, "WritableConfigurable",
78  TypedWritable::get_class_type());
80  "WriteableConfigurable");
81  }
82  virtual TypeHandle get_type() const {
83  return get_class_type();
84  }
85  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 
87 
88 private:
89  static TypeHandle _type_handle;
90 };
91 
92 #endif
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Defined as a fix to allow creating Configurable and Writable objects.
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.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43