Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/configurable.h

Go to the documentation of this file.
00001 // Filename: configurable.h
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 #ifndef CONFIGURABLE_H
00019 #define CONFIGURABLE_H
00020 //
00021 ////////////////////////////////////////////////////////////////////
00022 // Includes
00023 ////////////////////////////////////////////////////////////////////
00024 
00025 #include <pandabase.h>
00026 
00027 #include "typedObject.h"
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 // Defines
00031 ////////////////////////////////////////////////////////////////////
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : Configurable
00035 // Description : An object that has data or parameters that are set
00036 //               less frequently (at least occasionally) than every
00037 //               frame.  We can cache the configuration info by
00038 //               by using the "dirty" flag.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDA Configurable : public TypedObject {
00041 public:
00042 
00043   Configurable( void ) { make_dirty(); }
00044   virtual void config( void ) { _dirty = false; }
00045   INLINE void check_config() const {
00046     if (_dirty) {
00047       // This is a sneaky trick to allow check_config() to be called
00048       // from a const member function.  Even though we will be calling
00049       // config(), a non-const function that modifies the class
00050       // object, in some sense it's not really modifying the class
00051       // object--it's just updating a few internal settings for
00052       // consistency.
00053       ((Configurable *)this)->config();
00054     }
00055   }
00056 
00057   INLINE bool is_dirty(void) const { return _dirty; }
00058   INLINE void make_dirty(void) { _dirty = true; }
00059 
00060 private:
00061 
00062   bool _dirty;
00063 
00064 
00065 public:
00066   static TypeHandle get_class_type() {
00067     return _type_handle;
00068   }
00069   static void init_type() {
00070     TypedObject::init_type();
00071     register_type(_type_handle, "Configurable",
00072                   TypedObject::get_class_type());
00073   }
00074   virtual TypeHandle get_type() const {
00075     return get_class_type();
00076   }
00077   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00078 
00079 
00080 private:
00081   static TypeHandle _type_handle;
00082 };
00083 
00084 #endif

Generated on Fri May 2 00:43:36 2003 for Panda by doxygen1.3