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