Panda3D
|
00001 // Filename: configVariableEnum.h 00002 // Created by: drose (21Oct04) 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 00015 #ifndef CONFIGVARIABLEENUM_H 00016 #define CONFIGVARIABLEENUM_H 00017 00018 #include "dtoolbase.h" 00019 #include "configVariable.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Class : ConfigVariableEnum 00023 // Description : This class specializes ConfigVariable as an 00024 // enumerated type. It is a template class, so it 00025 // cannot be easily published; it's not really necessary 00026 // outside of C++ anyway. 00027 // 00028 // This variable assumes that the enumerated type in 00029 // question has input and output stream operators 00030 // defined that do the right thing (outputting a 00031 // sensible string for the type, and converting a string 00032 // to the correct value). 00033 //////////////////////////////////////////////////////////////////// 00034 template<class EnumType> 00035 class ConfigVariableEnum : public ConfigVariable { 00036 public: 00037 INLINE ConfigVariableEnum(const string &name, EnumType default_value, 00038 const string &description = string(), 00039 int flags = 0); 00040 INLINE ConfigVariableEnum(const string &name, const string &default_value, 00041 const string &description = string(), 00042 int flags = 0); 00043 INLINE ~ConfigVariableEnum(); 00044 00045 INLINE void operator = (EnumType value); 00046 INLINE operator EnumType () const; 00047 00048 INLINE int size() const; 00049 INLINE EnumType operator [] (int n) const; 00050 00051 INLINE void set_value(EnumType value); 00052 INLINE EnumType get_value() const; 00053 INLINE EnumType get_default_value() const; 00054 00055 INLINE EnumType get_word(int n) const; 00056 INLINE void set_word(int n, EnumType value); 00057 00058 private: 00059 INLINE EnumType parse_string(const string &value) const; 00060 INLINE string format_enum(EnumType value) const; 00061 00062 private: 00063 bool _got_default_value; 00064 EnumType _default_value; 00065 00066 AtomicAdjust::Integer _local_modified; 00067 EnumType _cache; 00068 }; 00069 00070 #include "configVariableEnum.I" 00071 00072 #endif 00073