00001 #if !defined(CONSTRAINEDPARAMETER_H__5B75CCD2_01CA_4993_8BD6_836465B6A0E1__INCLUDED_)
00002 #define CONSTRAINEDPARAMETER_H__5B75CCD2_01CA_4993_8BD6_836465B6A0E1__INCLUDED_
00003
00004 #if _MSC_VER > 1000
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007
00008 #include "Parameter.h"
00009
00010 class ConstrainedParameter : public Parameter
00011 {
00012 public:
00013 ConstrainedParameter();
00014 ConstrainedParameter(const string & name, const string & description,
00015 double value, double defaultValue,
00016 double min, double max, int type=Double, int key=0);
00017 ConstrainedParameter(const string & name, const string & description,
00018 bool * value, bool defaultValue, int key=0);
00019 ConstrainedParameter(const string & name, const string & description,
00020 int * value, int defaultValue, int min, int max, int key=0);
00021 ConstrainedParameter(const string & name, const string & description,
00022 float* value, float defaultValue,float min, float max, int key=0);
00023 ConstrainedParameter(const string & name, const string & description,
00024 double * value, double defaultValue, double min, double max, int key=0);
00025
00026 ConstrainedParameter(const ConstrainedParameter & parameter);
00027 virtual ~ConstrainedParameter();
00028
00029 const ConstrainedParameter & operator=(const ConstrainedParameter & parameter);
00030
00031 double getMinimum() const;
00032 double getMaximum() const;
00033 double getDefault() const;
00034 void setMinimum(double min);
00035 void setMaximum(double max);
00036 void setDefault(double value);
00037 void setValue(double value);
00038 void set(const string & name,const string & description,
00039 double value, double defaultValue, double min, double max, int type=Double, int key=0);
00040 void set(const string & name,const string & description,bool*value, bool defaultValue, int key=0);
00041 void set(const string & name,const string & description,int *value, int defaultValue, int min, int max, int key=0);
00042 void set(const string & name,const string & description,float*value, float defaultValue, float min, float max, int key=0);
00043 void set(const string & name,const string & description,double*value, double defaultValue, double min, double max, int key=0);
00044 void reset();
00045
00046 protected:
00047
00048 double _minimum;
00049 double _maximum;
00050 double _default;
00051
00052 };
00053
00054 inline const ConstrainedParameter & ConstrainedParameter::operator=(const ConstrainedParameter & parameter)
00055 {
00056 if (¶meter==this)
00057 return *this;
00058 _key = parameter._key;
00059 _type = parameter._type;
00060 _value = parameter._value;
00061 _minimum = parameter._minimum;
00062 _maximum = parameter._maximum;
00063 _default = parameter._default;
00064 return *this;
00065 }
00066
00067 inline double ConstrainedParameter::getMinimum() const
00068 {
00069 return _minimum;
00070 }
00071
00072 inline double ConstrainedParameter::getMaximum() const
00073 {
00074 return _maximum;
00075 }
00076
00077 inline double ConstrainedParameter::getDefault() const
00078 {
00079 return _default;
00080 }
00081
00082 inline void ConstrainedParameter::setMinimum(double min)
00083 {
00084 _minimum = min;
00085 if (_value<_minimum)
00086 _value = _minimum;
00087 if (_default<_minimum)
00088 _default = _minimum;
00089 }
00090
00091 inline void ConstrainedParameter::setMaximum(double max)
00092 {
00093 _maximum = max;
00094 if (_value>_maximum)
00095 _value = _maximum;
00096 if (_default>_maximum)
00097 _default = _maximum;
00098 }
00099
00100 inline void ConstrainedParameter::setDefault(double value)
00101 {
00102 if (value<_minimum)
00103 _default = _minimum;
00104 else if (value>_maximum)
00105 _default = _maximum;
00106 else
00107 _default = value;
00108 }
00109
00110 inline void ConstrainedParameter::setValue(double value)
00111 {
00112 if (value<_minimum)
00113 Parameter::setValue(_minimum);
00114 else if (value>_maximum)
00115 Parameter::setValue(_maximum);
00116 else
00117 Parameter::setValue(value);
00118 }
00119
00123 inline void ConstrainedParameter::reset()
00124 {
00125 _value = _default;
00126 }
00127
00128 inline void ConstrainedParameter::set(const string & name,
00129 const string & description,
00130 double value,
00131 double defaultValue,
00132 double min,
00133 double max,
00134 int type,
00135 int key)
00136 {
00137 Parameter::set(name,description,value,type,key);
00138 if (min>max) throw runtime_error("ConstrainedParameter::set() - ERROR - min>max");
00139 if (type==Double || type==Integer)
00140 {
00141 _minimum = min;
00142 _maximum = max;
00143 setDefault(defaultValue);
00144 setValue(value);
00145 }
00146 else
00147 {
00148 _minimum = 0;
00149 _maximum = 1;
00150 _default = (defaultValue!=0);
00151 _value = (value!=0);
00152 _type = Boolean;
00153 }
00154 }
00155
00156 inline void ConstrainedParameter::set(const string & name,const string & description,
00157 bool*value, bool defaultValue, int key)
00158 {
00159 Parameter::set(name,description,value,key);
00160 _default = defaultValue;
00161 _minimum = 0;
00162 _maximum = 1;
00163 }
00164
00165 inline void ConstrainedParameter::set(const string & name,const string & description,
00166 int *value, int defaultValue, int min, int max, int key)
00167 {
00168 Parameter::set(name,description,value,key);
00169 _default = defaultValue;
00170 _minimum = min;
00171 _maximum = max;
00172 }
00173
00174 inline void ConstrainedParameter::set(const string & name,const string & description,
00175 float*value, float defaultValue, float min, float max, int key)
00176 {
00177 Parameter::set(name,description,value,key);
00178 _default = defaultValue;
00179 _minimum = min;
00180 _maximum = max;
00181 }
00182
00183 inline void ConstrainedParameter::set(const string & name,const string & description,
00184 double*value, double defaultValue, double min, double max, int key)
00185 {
00186 Parameter::set(name,description,value,key);
00187 _default = defaultValue;
00188 _minimum = min;
00189 _maximum = max;
00190 }
00191
00192 #endif // !defined(CONSTRAINEDPARAMETER_H__5B75CCD2_01CA_4993_8BD6_836465B6A0E1__INCLUDED_)
00193