00001 // sampalib.org ESL library and tools 00002 // Copyright (C) 2007 Thierry Grellier 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License version 2 as 00006 // published by the Free Software Foundation. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along 00014 // with this program; if not, write to the Free Software Foundation, Inc., 00015 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 // 00017 // contact: www.sampalib.org 00018 00019 #ifndef SAMPA_PARAMETER_H 00020 #define SAMPA_PARAMETER_H 00021 00022 #include <string> 00023 #include "sampa/core/persistence.h" 00024 #include "sampa/core/time.h" 00025 00026 namespace Sampa { 00027 00028 template <class> class ParameterInitializer; 00029 template <typename> class EnumeratedParameterInitializer; 00030 00031 class ParameterManager; 00032 class LuaInterpreter; 00033 00034 void parameter_initialize(LuaInterpreter* interpreter, const std::string& init_parm_table); 00035 00036 class ParameterGroupName { 00037 public: 00038 ParameterGroupName(const char*); 00039 ParameterGroupName(const std::string&); 00040 ParameterGroupName(const ParameterGroupName&); 00041 ~ParameterGroupName(); 00042 const std::string& get_name() const { return m_name; } 00043 bool is_pushed() const { return m_pushed; } 00044 private: 00045 std::string m_name; 00046 ParameterGroupName* m_next; 00047 bool m_pushed; 00048 // disabled 00049 ParameterGroupName(); 00050 ParameterGroupName& operator=(const ParameterGroupName&); 00051 friend class ParameterManager; 00052 }; 00053 00054 class SAMPA_PERSISTENT_CLASS(BoolParameter) { 00055 public: 00056 BoolParameter(const char* name); 00057 BoolParameter(const char* name, bool default_value); 00058 inline operator bool() const { return m_value; } 00059 inline bool get_value() const { return m_value; } 00060 void update(const char*); 00061 private: 00062 bool m_value; 00063 friend class ParameterInitializer<BoolParameter>; 00064 SAMPA_PERSISTENT(BoolParameter); 00065 }; 00066 00067 class SAMPA_PERSISTENT_CLASS(IntParameter) { 00068 public: 00069 IntParameter(const char* name); 00070 IntParameter(const char* name, int default_value); 00071 inline operator int() const { return m_value; } 00072 inline int get_value() const { return m_value; } 00073 void update(const char*); 00074 private: 00075 int m_value; 00076 friend class ParameterInitializer<IntParameter>; 00077 SAMPA_PERSISTENT(IntParameter); 00078 }; 00079 00080 class SAMPA_PERSISTENT_CLASS(HexParameter) { 00081 public: 00082 HexParameter(const char* name); 00083 HexParameter(const char* name, unsigned long long default_value); 00084 inline operator unsigned long long () const { return m_value; } 00085 inline unsigned long long get_value() const { return m_value; } 00086 void update(const char*); 00087 private: 00088 unsigned long long m_value; 00089 friend class ParameterInitializer<HexParameter>; 00090 SAMPA_PERSISTENT(HexParameter); 00091 }; 00092 00093 class SAMPA_PERSISTENT_CLASS(StringParameter) { 00094 public: 00095 StringParameter(const char* name); 00096 StringParameter(const char* name, const std::string& default_value); 00097 inline operator const char* const () const { return m_value.c_str(); } 00098 inline const char* get_value() const { return m_value.c_str(); } 00099 void update(const char*); 00100 private: 00101 std::string m_value; 00102 friend class ParameterInitializer<StringParameter>; 00103 public: 00104 SAMPA_PERSISTENT(StringParameter); 00105 }; 00106 00107 class SAMPA_PERSISTENT_CLASS(DoubleParameter) { 00108 public: 00109 DoubleParameter(const char* name); 00110 DoubleParameter(const char* name, double default_value); 00111 inline operator double() const { return m_value; } 00112 inline double get_value() const { return m_value; } 00113 void update(const char*); 00114 private: 00115 double m_value; 00116 friend class ParameterInitializer<DoubleParameter>; 00117 public: 00118 SAMPA_PERSISTENT(DoubleParameter); 00119 }; 00120 00121 class SAMPA_PERSISTENT_CLASS(TimeParameter) { 00122 public: 00123 TimeParameter(const char* name); 00124 TimeParameter(const char* name, const Time& default_value); 00125 inline operator const Time&() const { return m_value; } 00126 inline const Time& get_value() const { return m_value; } 00127 void update(const char*); 00128 private: 00129 Time m_value; 00130 friend class ParameterInitializer<TimeParameter>; 00131 public: 00132 SAMPA_PERSISTENT(TimeParameter); 00133 }; 00134 00135 class SAMPA_PERSISTENT_CLASS(SizeParameter) { 00136 public: 00137 SizeParameter(const char* name); 00138 inline operator const int&() const { return m_value; } 00139 inline const int& get_value() const { return m_value; } 00140 void update(const char*); 00141 private: 00142 int m_value; 00143 friend class ParameterInitializer<SizeParameter>; 00144 public: 00145 SAMPA_PERSISTENT(SizeParameter); 00146 }; 00147 00148 template <typename Enumerated> 00149 class SAMPA_PERSISTENT_CLASS(EnumeratedParameter) { 00150 public: 00151 EnumeratedParameter(const char* name); 00152 EnumeratedParameter(const char* name, Enumerated default_value); 00153 inline operator Enumerated() const { return m_value; } 00154 inline const Enumerated& get_value() const { return m_value; } 00155 void update(const char*); 00156 private: 00157 Enumerated m_value; 00158 friend class EnumeratedParameterInitializer<Enumerated>; 00159 SAMPA_PERSISTENT(EnumeratedParameter); 00160 }; 00161 00162 } // namespace Sampa 00163 00164 #endif
1.5.3