Panda3D

configurable.h

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