| [adcfc6] | 1 | /*
 | 
|---|
 | 2 |  * Parameter_impl.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Apr 16, 2012
 | 
|---|
 | 5 |  *      Author: ankele
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef PARAMETER_IMPL_HPP_
 | 
|---|
 | 9 | #define PARAMETER_IMPL_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include "Parameter.hpp"
 | 
|---|
| [e45c1d] | 17 | #include "ParameterExceptions.hpp"
 | 
|---|
| [f10b0c] | 18 | 
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | template<typename T>
 | 
|---|
 | 21 | Parameter<T>::Parameter(const Parameter<T> &instance) :
 | 
|---|
| [6440c6] | 22 |   ParameterInterface(instance.getName()),
 | 
|---|
| [cf1d82] | 23 |   value(instance.value.getValidator())
 | 
|---|
| [f10b0c] | 24 | {
 | 
|---|
| [61003d] | 25 |   value.set(instance.value.getUnvalidated());
 | 
|---|
| [f10b0c] | 26 | }
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | /** Constructor for class Parameter.
 | 
|---|
 | 29 |  *
 | 
|---|
 | 30 |  */
 | 
|---|
 | 31 | template<typename T>
 | 
|---|
 | 32 | Parameter<T>::Parameter() :
 | 
|---|
| [6440c6] | 33 |   ParameterInterface("__no_name__"),
 | 
|---|
| [cf1d82] | 34 |   value()
 | 
|---|
| [f10b0c] | 35 | {};
 | 
|---|
 | 36 | 
 | 
|---|
| [adcfc6] | 37 | /** Constructor for class Parameter.
 | 
|---|
 | 38 |  *
 | 
|---|
 | 39 |  */
 | 
|---|
 | 40 | template<typename T>
 | 
|---|
 | 41 | Parameter<T>::Parameter(const std::string &_name) :
 | 
|---|
| [6440c6] | 42 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 43 |   value()
 | 
|---|
| [adcfc6] | 44 | {};
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | /** Constructor for class Parameter.
 | 
|---|
 | 47 |  *
 | 
|---|
 | 48 |  * @param _name name of this parameter
 | 
|---|
 | 49 |  * @param _value initial value to set
 | 
|---|
 | 50 |  */
 | 
|---|
 | 51 | template<typename T>
 | 
|---|
 | 52 | Parameter<T>::Parameter(const std::string &_name, const T &_value) :
 | 
|---|
| [6440c6] | 53 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 54 |   value()
 | 
|---|
| [adcfc6] | 55 | {
 | 
|---|
| [cf1d82] | 56 |   value.set(_value);
 | 
|---|
| [adcfc6] | 57 | };
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | /** Constructor for class Parameter.
 | 
|---|
 | 60 |  *
 | 
|---|
 | 61 |  * @param _name name of this parameter
 | 
|---|
 | 62 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 63 |  */
 | 
|---|
 | 64 | template<typename T>
 | 
|---|
 | 65 | Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator) :
 | 
|---|
| [6440c6] | 66 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 67 |   value(_Validator)
 | 
|---|
| [adcfc6] | 68 | {};
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | /** Constructor for class Parameter.
 | 
|---|
 | 71 |  *
 | 
|---|
 | 72 |  * @param _name name of this parameter
 | 
|---|
 | 73 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 74 |  * @param _value initial value to set
 | 
|---|
 | 75 |  */
 | 
|---|
 | 76 | template<typename T>
 | 
|---|
 | 77 | Parameter<T>::Parameter(const std::string &_name, const Validator<T> &_Validator, const T &_value) :
 | 
|---|
| [6440c6] | 78 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 79 |   value(_Validator)
 | 
|---|
| [adcfc6] | 80 | {
 | 
|---|
| [cf1d82] | 81 |   value.set(_value);
 | 
|---|
| [adcfc6] | 82 | };
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | /** Constructor for class Parameter.
 | 
|---|
 | 85 |  *
 | 
|---|
 | 86 |  * @param _name name of this parameter
 | 
|---|
 | 87 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 88 |  */
 | 
|---|
 | 89 | template<typename T>
 | 
|---|
 | 90 | Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues) :
 | 
|---|
| [6440c6] | 91 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 92 |   value(_ValidValues)
 | 
|---|
| [adcfc6] | 93 | {};
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 | /** Constructor for class Parameter.
 | 
|---|
 | 96 |  *
 | 
|---|
 | 97 |  * @param _name name of this parameter
 | 
|---|
 | 98 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 99 |  * @param _value initial value to set
 | 
|---|
 | 100 |  */
 | 
|---|
 | 101 | template<typename T>
 | 
|---|
 | 102 | Parameter<T>::Parameter(const std::string &_name, const std::vector<T> &_ValidValues, const T &_value) :
 | 
|---|
| [6440c6] | 103 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 104 |   value(_ValidValues)
 | 
|---|
| [adcfc6] | 105 | {
 | 
|---|
| [cf1d82] | 106 |   value.set(_value);
 | 
|---|
| [adcfc6] | 107 | };
 | 
|---|
 | 108 | 
 | 
|---|
 | 109 | /** Constructor for class Parameter.
 | 
|---|
 | 110 |  *
 | 
|---|
 | 111 |  * @param _name name of this parameter
 | 
|---|
 | 112 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 113 |  */
 | 
|---|
 | 114 | template<typename T>
 | 
|---|
 | 115 | Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange) :
 | 
|---|
| [6440c6] | 116 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 117 |   value(_ValidRange)
 | 
|---|
| [adcfc6] | 118 | {};
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | /** Constructor for class Parameter.
 | 
|---|
 | 121 |  *
 | 
|---|
 | 122 |  * @param _name name of this parameter
 | 
|---|
 | 123 |  * @param _ValidRange valid range for this ContinuousValue
 | 
|---|
 | 124 |  * @param _value initial value to set
 | 
|---|
 | 125 |  */
 | 
|---|
 | 126 | template<typename T>
 | 
|---|
 | 127 | Parameter<T>::Parameter(const std::string &_name, const range<T> &_ValidRange, const T &_value) :
 | 
|---|
| [6440c6] | 128 |   ParameterInterface(_name),
 | 
|---|
| [cf1d82] | 129 |   value(_ValidRange)
 | 
|---|
| [adcfc6] | 130 | {
 | 
|---|
| [cf1d82] | 131 |   value.set(_value);
 | 
|---|
| [adcfc6] | 132 | };
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 | /** Destructor for class Parameter.
 | 
|---|
 | 135 |  *
 | 
|---|
 | 136 |  */
 | 
|---|
 | 137 | template<typename T>
 | 
|---|
 | 138 | Parameter<T>::~Parameter()
 | 
|---|
 | 139 | {};
 | 
|---|
 | 140 | 
 | 
|---|
| [cf1d82] | 141 | /** Catch call to value.isValidAsString() to add exception information.
 | 
|---|
 | 142 |  *
 | 
|---|
 | 143 |  * @param _value value to set to
 | 
|---|
 | 144 |  */
 | 
|---|
 | 145 | template<typename T>
 | 
|---|
 | 146 | inline
 | 
|---|
 | 147 | bool Parameter<T>::isValidAsString(const std::string &_value) const throw(ParameterValidatorException)
 | 
|---|
 | 148 | {
 | 
|---|
 | 149 |   try {
 | 
|---|
 | 150 |     return value.isValidAsString(_value);
 | 
|---|
 | 151 |   } catch(ParameterException &e) {
 | 
|---|
 | 152 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 153 |     throw;
 | 
|---|
 | 154 |   }
 | 
|---|
 | 155 | }
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | /** Catch call to value.getAsString() to add exception information.
 | 
|---|
| [e45c1d] | 159 |  *
 | 
|---|
 | 160 |  * @return parameter value as string
 | 
|---|
 | 161 |  */
 | 
|---|
 | 162 | template<typename T>
 | 
|---|
| [9e6722] | 163 | inline const std::string Parameter<T>::getAsString() const throw(ParameterValueException)
 | 
|---|
| [e45c1d] | 164 | {
 | 
|---|
 | 165 |   try {
 | 
|---|
| [cf1d82] | 166 |     return value.getAsString();
 | 
|---|
| [e45c1d] | 167 |   } catch(ParameterException &e) {
 | 
|---|
| [6440c6] | 168 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 169 |     throw;
 | 
|---|
 | 170 |   }
 | 
|---|
 | 171 | }
 | 
|---|
 | 172 | 
 | 
|---|
| [6d78b6f] | 173 | /** Catch call to value.getAsStringUnvalidated() to add exception information.
 | 
|---|
 | 174 |  *
 | 
|---|
 | 175 |  * @return parameter value as string
 | 
|---|
 | 176 |  */
 | 
|---|
 | 177 | template<typename T>
 | 
|---|
 | 178 | inline const std::string Parameter<T>::getAsStringUnvalidated() const throw(ParameterValueException)
 | 
|---|
 | 179 | {
 | 
|---|
 | 180 |   try {
 | 
|---|
 | 181 |     return value.getAsStringUnvalidated();
 | 
|---|
 | 182 |   } catch(ParameterException &e) {
 | 
|---|
 | 183 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 184 |     throw;
 | 
|---|
 | 185 |   }
 | 
|---|
 | 186 | }
 | 
|---|
 | 187 | 
 | 
|---|
| [cf1d82] | 188 | /** Catch call to value.isValid() to add exception information.
 | 
|---|
 | 189 |  *
 | 
|---|
 | 190 |  * @return parameter value as string
 | 
|---|
 | 191 |  */
 | 
|---|
 | 192 | template<typename T>
 | 
|---|
 | 193 | inline bool Parameter<T>::isValid(const T &_value) const throw(ParameterValidatorException)
 | 
|---|
 | 194 | {
 | 
|---|
 | 195 |   try {
 | 
|---|
 | 196 |     return value.isValid(_value);
 | 
|---|
 | 197 |   } catch(ParameterException &e) {
 | 
|---|
 | 198 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 199 |     throw;
 | 
|---|
 | 200 |   }
 | 
|---|
 | 201 | }
 | 
|---|
 | 202 | 
 | 
|---|
 | 203 | 
 | 
|---|
| [b56114] | 204 | /** Catch call to value.getUnvalidated() to add exception information.
 | 
|---|
 | 205 |  *
 | 
|---|
 | 206 |  * @return parameter value as string
 | 
|---|
 | 207 |  */
 | 
|---|
 | 208 | template<typename T>
 | 
|---|
 | 209 | inline const T & Parameter<T>::getUnvalidated() const throw(ParameterValueException)
 | 
|---|
 | 210 | {
 | 
|---|
 | 211 |   try {
 | 
|---|
 | 212 |     return value.getUnvalidated();
 | 
|---|
 | 213 |   } catch(ParameterException &e) {
 | 
|---|
 | 214 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
 | 215 |     throw;
 | 
|---|
 | 216 |   }
 | 
|---|
 | 217 | }
 | 
|---|
 | 218 | 
 | 
|---|
| [cf1d82] | 219 | /** Catch call to value.get() to add exception information.
 | 
|---|
| [e45c1d] | 220 |  *
 | 
|---|
 | 221 |  * @return parameter value as string
 | 
|---|
 | 222 |  */
 | 
|---|
 | 223 | template<typename T>
 | 
|---|
| [9e6722] | 224 | inline const T & Parameter<T>::get() const throw(ParameterValueException)
 | 
|---|
| [e45c1d] | 225 | {
 | 
|---|
 | 226 |   try {
 | 
|---|
| [cf1d82] | 227 |     return value.get();
 | 
|---|
| [e45c1d] | 228 |   } catch(ParameterException &e) {
 | 
|---|
| [6440c6] | 229 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 230 |     throw;
 | 
|---|
 | 231 |   }
 | 
|---|
 | 232 | }
 | 
|---|
 | 233 | 
 | 
|---|
| [cf1d82] | 234 | /** Catch call to value.set() to add exception information.
 | 
|---|
| [e45c1d] | 235 |  *
 | 
|---|
 | 236 |  * @param _value value to set to
 | 
|---|
 | 237 |  */
 | 
|---|
 | 238 | template<typename T>
 | 
|---|
| [9e6722] | 239 | inline void Parameter<T>::set(const T & _value) throw(ParameterValueException)
 | 
|---|
| [e45c1d] | 240 | {
 | 
|---|
 | 241 |   try {
 | 
|---|
| [cf1d82] | 242 |     value.set(_value);
 | 
|---|
| [e45c1d] | 243 |   } catch(ParameterException &e) {
 | 
|---|
| [6440c6] | 244 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 245 |     throw;
 | 
|---|
 | 246 |   }
 | 
|---|
 | 247 | }
 | 
|---|
 | 248 | 
 | 
|---|
| [cf1d82] | 249 | /** Catch call to value.set() to add exception information.
 | 
|---|
| [e45c1d] | 250 |  *
 | 
|---|
 | 251 |  * @param _value value to set to
 | 
|---|
 | 252 |  */
 | 
|---|
 | 253 | template<typename T>
 | 
|---|
| [b11f5e] | 254 | inline void Parameter<T>::setAsString(const std::string &_value) throw(ParameterValueException)
 | 
|---|
| [e45c1d] | 255 | {
 | 
|---|
 | 256 |   try {
 | 
|---|
| [cf1d82] | 257 |     value.setAsString(_value);
 | 
|---|
| [e45c1d] | 258 |   } catch(ParameterException &e) {
 | 
|---|
| [6440c6] | 259 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 260 |     throw;
 | 
|---|
 | 261 |   }
 | 
|---|
 | 262 | }
 | 
|---|
 | 263 | 
 | 
|---|
| [adcfc6] | 264 | /** Compares this continuous value against another \a _instance.
 | 
|---|
 | 265 |  *
 | 
|---|
 | 266 |  * @param _instance other value to compare to
 | 
|---|
 | 267 |  * @return true - if contained ContinuousValue and name are the same, false - else
 | 
|---|
 | 268 |  */
 | 
|---|
 | 269 | template <class T>
 | 
|---|
| [e45c1d] | 270 | bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException)
 | 
|---|
| [adcfc6] | 271 | {
 | 
|---|
 | 272 |   bool status = true;
 | 
|---|
| [e45c1d] | 273 |   try {
 | 
|---|
 | 274 |     status = status &&
 | 
|---|
| [61003d] | 275 |         (getUnvalidated() == _instance.getUnvalidated());
 | 
|---|
| [6440c6] | 276 |     status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 277 |   } catch(ParameterException &e) {
 | 
|---|
| [6440c6] | 278 |     e << ParameterName(ParameterInterface::getName());
 | 
|---|
| [e45c1d] | 279 |     throw;
 | 
|---|
 | 280 |   }
 | 
|---|
| [adcfc6] | 281 |   return status;
 | 
|---|
 | 282 | }
 | 
|---|
 | 283 | 
 | 
|---|
 | 284 | /** Creates a clone of this Parameter instance.
 | 
|---|
 | 285 |  *
 | 
|---|
 | 286 |  * @return cloned instance
 | 
|---|
 | 287 |  */
 | 
|---|
 | 288 | template<typename T>
 | 
|---|
| [6440c6] | 289 | inline ParameterInterface* Parameter<T>::clone() const
 | 
|---|
| [adcfc6] | 290 | {
 | 
|---|
| [cf1d82] | 291 |   Parameter<T> *instance = new Parameter<T>(ParameterInterface::getName(), value.getValidator());
 | 
|---|
| [0d4168] | 292 |   // do not use get, we do not check for validity here
 | 
|---|
| [61003d] | 293 |   if (value.isSet())
 | 
|---|
 | 294 |     instance->set(value.getUnvalidated());
 | 
|---|
| [adcfc6] | 295 |   return instance;
 | 
|---|
 | 296 | }
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 | 
 | 
|---|
 | 299 | #endif /* Parameter_IMPL_HPP_ */
 | 
|---|