| 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(instance.getName()),
|
|---|
| 23 | value(instance.value.getValidator())
|
|---|
| 24 | {
|
|---|
| 25 | value.set(instance.value.value);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | /** Constructor for class Parameter.
|
|---|
| 29 | *
|
|---|
| 30 | */
|
|---|
| 31 | template<typename T>
|
|---|
| 32 | Parameter<T>::Parameter() :
|
|---|
| 33 | ParameterInterface("__no_name__"),
|
|---|
| 34 | value()
|
|---|
| 35 | {};
|
|---|
| 36 |
|
|---|
| 37 | /** Constructor for class Parameter.
|
|---|
| 38 | *
|
|---|
| 39 | */
|
|---|
| 40 | template<typename T>
|
|---|
| 41 | Parameter<T>::Parameter(const std::string &_name) :
|
|---|
| 42 | ParameterInterface(_name),
|
|---|
| 43 | value()
|
|---|
| 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(_name),
|
|---|
| 54 | value()
|
|---|
| 55 | {
|
|---|
| 56 | value.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(_name),
|
|---|
| 67 | value(_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(_name),
|
|---|
| 79 | value(_Validator)
|
|---|
| 80 | {
|
|---|
| 81 | value.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(_name),
|
|---|
| 92 | value(_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(_name),
|
|---|
| 104 | value(_ValidValues)
|
|---|
| 105 | {
|
|---|
| 106 | value.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(_name),
|
|---|
| 117 | value(_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(_name),
|
|---|
| 129 | value(_ValidRange)
|
|---|
| 130 | {
|
|---|
| 131 | value.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.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.
|
|---|
| 159 | *
|
|---|
| 160 | * @return parameter value as string
|
|---|
| 161 | */
|
|---|
| 162 | template<typename T>
|
|---|
| 163 | inline const std::string Parameter<T>::getAsString() const throw(ParameterValueException)
|
|---|
| 164 | {
|
|---|
| 165 | try {
|
|---|
| 166 | return value.getAsString();
|
|---|
| 167 | } catch(ParameterException &e) {
|
|---|
| 168 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 169 | throw;
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | /** Catch call to value.isValid() to add exception information.
|
|---|
| 174 | *
|
|---|
| 175 | * @return parameter value as string
|
|---|
| 176 | */
|
|---|
| 177 | template<typename T>
|
|---|
| 178 | inline bool Parameter<T>::isValid(const T &_value) const throw(ParameterValidatorException)
|
|---|
| 179 | {
|
|---|
| 180 | try {
|
|---|
| 181 | return value.isValid(_value);
|
|---|
| 182 | } catch(ParameterException &e) {
|
|---|
| 183 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 184 | throw;
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | /** Catch call to value.get() to add exception information.
|
|---|
| 190 | *
|
|---|
| 191 | * @return parameter value as string
|
|---|
| 192 | */
|
|---|
| 193 | template<typename T>
|
|---|
| 194 | inline const T & Parameter<T>::get() const throw(ParameterValueException)
|
|---|
| 195 | {
|
|---|
| 196 | try {
|
|---|
| 197 | return value.get();
|
|---|
| 198 | } catch(ParameterException &e) {
|
|---|
| 199 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 200 | throw;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | /** Catch call to value.set() to add exception information.
|
|---|
| 205 | *
|
|---|
| 206 | * @param _value value to set to
|
|---|
| 207 | */
|
|---|
| 208 | template<typename T>
|
|---|
| 209 | inline void Parameter<T>::set(const T & _value) throw(ParameterValueException)
|
|---|
| 210 | {
|
|---|
| 211 | try {
|
|---|
| 212 | value.set(_value);
|
|---|
| 213 | } catch(ParameterException &e) {
|
|---|
| 214 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 215 | throw;
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | /** Catch call to value.set() to add exception information.
|
|---|
| 220 | *
|
|---|
| 221 | * @param _value value to set to
|
|---|
| 222 | */
|
|---|
| 223 | template<typename T>
|
|---|
| 224 | inline void Parameter<T>::setAsString(const std::string &_value) throw(ParameterValueException)
|
|---|
| 225 | {
|
|---|
| 226 | try {
|
|---|
| 227 | value.setAsString(_value);
|
|---|
| 228 | } catch(ParameterException &e) {
|
|---|
| 229 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 230 | throw;
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | /** Compares this continuous value against another \a _instance.
|
|---|
| 235 | *
|
|---|
| 236 | * @param _instance other value to compare to
|
|---|
| 237 | * @return true - if contained ContinuousValue and name are the same, false - else
|
|---|
| 238 | */
|
|---|
| 239 | template <class T>
|
|---|
| 240 | bool Parameter<T>::operator==(const Parameter<T> &_instance) const throw(ParameterException)
|
|---|
| 241 | {
|
|---|
| 242 | bool status = true;
|
|---|
| 243 | try {
|
|---|
| 244 | status = status &&
|
|---|
| 245 | (value == _instance.value);
|
|---|
| 246 | status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName());
|
|---|
| 247 | } catch(ParameterException &e) {
|
|---|
| 248 | e << ParameterName(ParameterInterface::getName());
|
|---|
| 249 | throw;
|
|---|
| 250 | }
|
|---|
| 251 | return status;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | /** Creates a clone of this Parameter instance.
|
|---|
| 255 | *
|
|---|
| 256 | * @return cloned instance
|
|---|
| 257 | */
|
|---|
| 258 | template<typename T>
|
|---|
| 259 | inline ParameterInterface* Parameter<T>::clone() const
|
|---|
| 260 | {
|
|---|
| 261 | Parameter<T> *instance = new Parameter<T>(ParameterInterface::getName(), value.getValidator());
|
|---|
| 262 | // do not use get, we do not check for validity here
|
|---|
| 263 | if (value.ValueSet)
|
|---|
| 264 | instance->set(value.value);
|
|---|
| 265 | return instance;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 | #endif /* Parameter_IMPL_HPP_ */
|
|---|