00001 #if !defined(PARAMETER_H_INCLUDED_)
00002 #define PARAMETER_H_INCLUDED_
00003
00004 #if _MSC_VER > 1000
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007
00008 #include "Named.h"
00009 #include "Described.h"
00010 #include "Stiostream.h"
00011 #include <stdexcept>
00012 using namespace std;
00013
00023 class Parameter : public Named, public Described
00024 {
00025 public:
00026
00027 static const int Boolean;
00028 static const int Integer;
00029 static const int Float;
00030 static const int Double;
00031
00032 Parameter();
00033 Parameter(const string & name, const string & description, double value, int type, int key);
00034 Parameter(const string & name, const string & description, bool * value, int key);
00035 Parameter(const string & name, const string & description, int * value, int key);
00036 Parameter(const string & name, const string & description, float * value, int key);
00037 Parameter(const string & name, const string & description, double* value, int key);
00038 Parameter(const Parameter & parameter);
00039 virtual ~Parameter();
00040
00041 const Parameter & operator=(const Parameter & parameter);
00042
00043 int getKey() const;
00044 int getType() const;
00045 bool getBoolValue() const;
00046 int getIntValue() const;
00047 float getFloatValue() const;
00048 double getDoubleValue() const;
00049
00050 void setKey(int key);
00051 void setValue(bool value);
00052 void setValue(int value);
00053 void setValue(float value);
00054 void setValue(double value);
00055 void set(const string & name,const string & description, double value,int type=Double,int key=0);
00056 void set(const string & name,const string & description, bool * value,int key=0);
00057 void set(const string & name,const string & description, int * value,int key=0);
00058 void set(const string & name,const string & description, float * value,int key=0);
00059 void set(const string & name,const string & description, double* value,int key=0);
00060
00061 protected:
00062
00063 int _key;
00064 int _type;
00065 double _value;
00066 void * _exValue;
00067
00068 };
00069
00070
00071 inline const Parameter & Parameter::operator=(const Parameter & parameter)
00072 {
00073 if (¶meter==this)
00074 return *this;
00075 _key = parameter._key;
00076 _type = parameter._type;
00077 _value = parameter._value;
00078 return *this;
00079 }
00080
00081 inline int Parameter::getKey() const
00082 {
00083 return _key;
00084 }
00085
00086 inline int Parameter::getType() const
00087 {
00088 return _type;
00089 }
00090
00091 inline bool Parameter::getBoolValue() const
00092 {
00093 if (_exValue)
00094 return *static_cast<bool*>(_exValue);
00095 else
00096 return _value>0;
00097 }
00098
00099 inline int Parameter::getIntValue() const
00100 {
00101 if (_exValue)
00102 return *static_cast<int*>(_exValue);
00103 else
00104 return int(_value);
00105 }
00106
00107 inline float Parameter::getFloatValue() const
00108 {
00109 if (_exValue)
00110 return *static_cast<float*>(_exValue);
00111 else
00112 return float(_value);
00113 }
00114
00115 inline double Parameter::getDoubleValue() const
00116 {
00117 if (_exValue)
00118 return *static_cast<double*>(_exValue);
00119 else
00120 return _value;
00121 }
00122
00123 inline void Parameter::setKey(int key)
00124 {
00125 _key = key;
00126 }
00127
00128 inline void Parameter::setValue(bool value)
00129 {
00130
00131 if (_exValue)
00132 {
00133 switch (_type)
00134 {
00135 case 0: *static_cast<bool*>(_exValue) = value; break;
00136 case 1: *static_cast<int*>(_exValue) = (int) value; break;
00137 case 2: *static_cast<float*>(_exValue) = (float)value; break;
00138 case 3: *static_cast<double*>(_exValue) = (double)value; break;
00139 }
00140 }
00141 else
00142 _value = value;
00143 }
00144
00145 inline void Parameter::setValue(int value)
00146 {
00147
00148 if (_exValue)
00149 {
00150 switch (_type)
00151 {
00152 case 0: *static_cast<bool*>(_exValue) = value>0; break;
00153 case 1: *static_cast<int*>(_exValue) = value; break;
00154 case 2: *static_cast<float*>(_exValue) = (float)value; break;
00155 case 3: *static_cast<double*>(_exValue) = (double)value; break;
00156 }
00157 }
00158 else
00159 _value = value;
00160 }
00161
00162 inline void Parameter::setValue(float value)
00163 {
00164
00165 if (_exValue)
00166 {
00167 switch (_type)
00168 {
00169 case 0: *static_cast<bool*>(_exValue) = value>0; break;
00170 case 1: *static_cast<int*>(_exValue) = (int) value; break;
00171 case 2: *static_cast<float*>(_exValue) = value; break;
00172 case 3: *static_cast<double*>(_exValue) = (double)value; break;
00173 }
00174 }
00175 else
00176 _value = value;
00177 }
00178
00179
00180 inline void Parameter::setValue(double value)
00181 {
00182
00183 if (_exValue)
00184 {
00185 switch (_type)
00186 {
00187 case 0: *static_cast<bool*>(_exValue) = value>0; break;
00188 case 1: *static_cast<int*>(_exValue) = (int) value; break;
00189 case 2: *static_cast<float*>(_exValue) = (float)value; break;
00190 case 3: *static_cast<double*>(_exValue) = value; break;
00191 }
00192 }
00193 else
00194 _value = value;
00195 }
00196
00197 inline void Parameter::set(const string & name,
00198 const string & description,
00199 double value,
00200 int type,
00201 int key)
00202 {
00203 setName(name);
00204 _description = description;
00205 _type = type;
00206 _key = key;
00207 _value = value;
00208 _exValue = 0;
00209 }
00210
00211 inline void Parameter::set(const string & name,const string & description, bool * value,int key)
00212 {
00213 setName(name);
00214 _description = description;
00215 _type = Boolean;
00216 _key = key;
00217 _exValue = value;
00218 }
00219
00220 inline void Parameter::set(const string & name,const string & description, int * value,int key)
00221 {
00222 setName(name);
00223 _description = description;
00224 _type = Integer;
00225 _key = key;
00226 _value = 0;
00227 _exValue = value;
00228 }
00229
00230 inline void Parameter::set(const string & name,const string & description, float * value,int key)
00231 {
00232 setName(name);
00233 _description = description;
00234 _type = Float;
00235 _key = key;
00236 _value = 0;
00237 _exValue = value;
00238 }
00239
00240
00241 inline void Parameter::set(const string & name,const string & description, double* value,int key)
00242 {
00243 setName(name);
00244 _description = description;
00245 _type = Double;
00246 _key = key;
00247 _value = 0;
00248 _exValue = value;
00249 }
00250
00251 #endif // !defined(PARAMETER_H_INCLUDED_)