Panda3D
 All Classes Functions Variables Enumerations
configurable.h
1 // Filename: configurable.h
2 // Created by: mike (09Jan97)
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 #ifndef CONFIGURABLE_H
15 #define CONFIGURABLE_H
16 //
17 ////////////////////////////////////////////////////////////////////
18 // Includes
19 ////////////////////////////////////////////////////////////////////
20 
21 #include "pandabase.h"
22 
23 #include "typedObject.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Defines
27 ////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : Configurable
31 // Description : An object that has data or parameters that are set
32 // less frequently (at least occasionally) than every
33 // frame. We can cache the configuration info by
34 // by using the "dirty" flag.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_PUTIL Configurable : public TypedObject {
37 public:
38 
39  Configurable( void ) { make_dirty(); }
40  virtual void config( void ) { _dirty = false; }
41  INLINE void check_config() const {
42  if (_dirty) {
43  // This is a sneaky trick to allow check_config() to be called
44  // from a const member function. Even though we will be calling
45  // config(), a non-const function that modifies the class
46  // object, in some sense it's not really modifying the class
47  // object--it's just updating a few internal settings for
48  // consistency.
49  ((Configurable *)this)->config();
50  }
51  }
52 
53  INLINE bool is_dirty() const { return _dirty; }
54  INLINE void make_dirty() { _dirty = true; }
55 
56 private:
57 
58  bool _dirty;
59 
60 
61 public:
62  static TypeHandle get_class_type() {
63  return _type_handle;
64  }
65  static void init_type() {
67  register_type(_type_handle, "Configurable",
68  TypedObject::get_class_type());
69  }
70  virtual TypeHandle get_type() const {
71  return get_class_type();
72  }
73  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
74 
75 
76 private:
77  static TypeHandle _type_handle;
78 };
79 
80 #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 an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
An object that has data or parameters that are set less frequently (at least occasionally) than every...
Definition: configurable.h:36
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85