| 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" | 
|---|
| 17 | #include "ParameterExceptions.hpp" | 
|---|
| 18 |  | 
|---|
| 19 |  | 
|---|
| 20 | template<typename T> | 
|---|
| 21 | Parameter<T>::Parameter(const Parameter<T> &instance) : | 
|---|
| 22 | ParameterInterface<T>(instance.getName()), | 
|---|
| 23 | Value<T>(instance.getValidator()) | 
|---|
| 24 | { | 
|---|
| 25 | Value<T>::set(instance.Value<T>::get()); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | /** Constructor for class Parameter. | 
|---|
| 29 | * | 
|---|
| 30 | */ | 
|---|
| 31 | template<typename T> | 
|---|
| 32 | Parameter<T>::Parameter() : | 
|---|
| 33 | ParameterInterface<T>("__no_name__"), | 
|---|
| 34 | Value<T>() | 
|---|
| 35 | {}; | 
|---|
| 36 |  | 
|---|
| 37 | /** Constructor for class Parameter. | 
|---|
| 38 | * | 
|---|
| 39 | */ | 
|---|
| 40 | template<typename T> | 
|---|
| 41 | Parameter<T>::Parameter(const std::string &_name) : | 
|---|
| 42 | ParameterInterface<T>(_name), | 
|---|
| 43 | Value<T>() | 
|---|
| 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) : | 
|---|
| 53 | ParameterInterface<T>(_name), | 
|---|
| 54 | Value<T>() | 
|---|
| 55 | { | 
|---|
| 56 | Value<T>::set(_value); | 
|---|
| 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) : | 
|---|
| 66 | ParameterInterface<T>(_name), | 
|---|
| 67 | Value<T>(_Validator) | 
|---|
| 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) : | 
|---|
| 78 | ParameterInterface<T>(_name), | 
|---|
| 79 | Value<T>(_Validator) | 
|---|
| 80 | { | 
|---|
| 81 | Value<T>::set(_value); | 
|---|
| 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) : | 
|---|
| 91 | ParameterInterface<T>(_name), | 
|---|
| 92 | Value<T>(_ValidValues) | 
|---|
| 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) : | 
|---|
| 103 | ParameterInterface<T>(_name), | 
|---|
| 104 | Value<T>(_ValidValues) | 
|---|
| 105 | { | 
|---|
| 106 | Value<T>::set(_value); | 
|---|
| 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) : | 
|---|
| 116 | ParameterInterface<T>(_name), | 
|---|
| 117 | Value<T>(_ValidRange) | 
|---|
| 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) : | 
|---|
| 128 | ParameterInterface<T>(_name), | 
|---|
| 129 | Value<T>(_ValidRange) | 
|---|
| 130 | { | 
|---|
| 131 | Value<T>::set(_value); | 
|---|
| 132 | }; | 
|---|
| 133 |  | 
|---|
| 134 | /** Destructor for class Parameter. | 
|---|
| 135 | * | 
|---|
| 136 | */ | 
|---|
| 137 | template<typename T> | 
|---|
| 138 | Parameter<T>::~Parameter() | 
|---|
| 139 | {}; | 
|---|
| 140 |  | 
|---|
| 141 | /** Catch call to Value<T>::getAsString() to add exception information. | 
|---|
| 142 | * | 
|---|
| 143 | * @return parameter value as string | 
|---|
| 144 | */ | 
|---|
| 145 | template<typename T> | 
|---|
| 146 | const std::string Parameter<T>::getAsString() const throw(ParameterValueException) | 
|---|
| 147 | { | 
|---|
| 148 | try { | 
|---|
| 149 | return Value<T>::getAsString(); | 
|---|
| 150 | } catch(ParameterException &e) { | 
|---|
| 151 | e << ParameterName(ParameterInterface<T>::getName()); | 
|---|
| 152 | throw; | 
|---|
| 153 | } | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | /** Catch call to Value<T>::get() to add exception information. | 
|---|
| 157 | * | 
|---|
| 158 | * @return parameter value as string | 
|---|
| 159 | */ | 
|---|
| 160 | template<typename T> | 
|---|
| 161 | const T & Parameter<T>::get() const throw(ParameterValueException) | 
|---|
| 162 | { | 
|---|
| 163 | try { | 
|---|
| 164 | return Value<T>::get(); | 
|---|
| 165 | } catch(ParameterException &e) { | 
|---|
| 166 | e << ParameterName(ParameterInterface<T>::getName()); | 
|---|
| 167 | throw; | 
|---|
| 168 | } | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | /** Catch call to Value<T>::set() to add exception information. | 
|---|
| 172 | * | 
|---|
| 173 | * @param _value value to set to | 
|---|
| 174 | */ | 
|---|
| 175 | template<typename T> | 
|---|
| 176 | void Parameter<T>::set(const T & _value) throw(ParameterValueException) | 
|---|
| 177 | { | 
|---|
| 178 | try { | 
|---|
| 179 | Value<T>::set(_value); | 
|---|
| 180 | } catch(ParameterException &e) { | 
|---|
| 181 | e << ParameterName(ParameterInterface<T>::getName()); | 
|---|
| 182 | throw; | 
|---|
| 183 | } | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | /** Catch call to Value<T>::set() to add exception information. | 
|---|
| 187 | * | 
|---|
| 188 | * @param _value value to set to | 
|---|
| 189 | */ | 
|---|
| 190 | template<typename T> | 
|---|
| 191 | void Parameter<T>::setAsString(const std::string _value) throw(ParameterValueException) | 
|---|
| 192 | { | 
|---|
| 193 | try { | 
|---|
| 194 | Value<T>::setAsString(_value); | 
|---|
| 195 | } catch(ParameterException &e) { | 
|---|
| 196 | e << ParameterName(ParameterInterface<T>::getName()); | 
|---|
| 197 | throw; | 
|---|
| 198 | } | 
|---|
| 199 | } | 
|---|
| 200 |  | 
|---|
| 201 | /** Compares this continuous value against another \a _instance. | 
|---|
| 202 | * | 
|---|
| 203 | * @param _instance other value to compare to | 
|---|
| 204 | * @return true - if contained ContinuousValue and name are the same, false - else | 
|---|
| 205 | */ | 
|---|
| 206 | template <class T> | 
|---|
| 207 | bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException) | 
|---|
| 208 | { | 
|---|
| 209 | bool status = true; | 
|---|
| 210 | try { | 
|---|
| 211 | status = status && | 
|---|
| 212 | (*dynamic_cast<const Value<T> *>(this) == dynamic_cast<const Value<T> &>(_instance)); | 
|---|
| 213 | status = status && (ParameterInterface<T>::getName() == _instance.ParameterInterface<T>::getName()); | 
|---|
| 214 | } catch(ParameterException &e) { | 
|---|
| 215 | e << ParameterName(ParameterInterface<T>::getName()); | 
|---|
| 216 | throw; | 
|---|
| 217 | } | 
|---|
| 218 | return status; | 
|---|
| 219 | } | 
|---|
| 220 |  | 
|---|
| 221 | /** Creates a clone of this Parameter instance. | 
|---|
| 222 | * | 
|---|
| 223 | * @return cloned instance | 
|---|
| 224 | */ | 
|---|
| 225 | template<typename T> | 
|---|
| 226 | ParameterAsString* Parameter<T>::clone() const | 
|---|
| 227 | { | 
|---|
| 228 | Parameter<T> *instance = new Parameter<T>(ParameterInterface<T>::getName(), Value<T>::getValidator()); | 
|---|
| 229 | if (Value<T>::ValueSet) | 
|---|
| 230 | instance->set(Value<T>::get()); | 
|---|
| 231 | return instance; | 
|---|
| 232 | } | 
|---|
| 233 |  | 
|---|
| 234 |  | 
|---|
| 235 | #endif /* Parameter_IMPL_HPP_ */ | 
|---|