Panda3D
configurable.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 configurable.h
10  * @author mike
11  * @date 1997-01-09
12  */
13 
14 #ifndef CONFIGURABLE_H
15 #define CONFIGURABLE_H
16 
17 // Includes
18 
19 #include "pandabase.h"
20 
21 #include "typedObject.h"
22 
23 // Defines
24 
25 /**
26  * An object that has data or parameters that are set less frequently (at
27  * least occasionally) than every frame. We can cache the configuration info
28  * by by using the "dirty" flag.
29  */
30 class EXPCL_PANDA_PUTIL Configurable : public TypedObject {
31 public:
32 
33  Configurable( void ) { make_dirty(); }
34  virtual void config( void ) { _dirty = false; }
35  INLINE void check_config() const {
36  if (_dirty) {
37  // This is a sneaky trick to allow check_config() to be called from a
38  // const member function. Even though we will be calling config(), a
39  // non-const function that modifies the class object, in some sense it's
40  // not really modifying the class object--it's just updating a few
41  // internal settings for consistency.
42  ((Configurable *)this)->config();
43  }
44  }
45 
46  INLINE bool is_dirty() const { return _dirty; }
47  INLINE void make_dirty() { _dirty = true; }
48 
49 private:
50 
51  bool _dirty;
52 
53 
54 public:
55  static TypeHandle get_class_type() {
56  return _type_handle;
57  }
58  static void init_type() {
60  register_type(_type_handle, "Configurable",
61  TypedObject::get_class_type());
62  }
63  virtual TypeHandle get_type() const {
64  return get_class_type();
65  }
66  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
67 
68 
69 private:
70  static TypeHandle _type_handle;
71 };
72 
73 #endif
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:44
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.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:88
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An object that has data or parameters that are set less frequently (at least occasionally) than every...
Definition: configurable.h:30
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81