/* * Parameter_impl.hpp * * Created on: Apr 16, 2012 * Author: ankele */ #ifndef PARAMETER_IMPL_HPP_ #define PARAMETER_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Parameter.hpp" #include "ParameterExceptions.hpp" template Parameter::Parameter(const Parameter &instance) : ParameterInterface(instance.getName()), Value(instance.getValidator()) { Value::set(instance.Value::get()); } /** Constructor for class Parameter. * */ template Parameter::Parameter() : ParameterInterface("__no_name__"), Value() {}; /** Constructor for class Parameter. * */ template Parameter::Parameter(const std::string &_name) : ParameterInterface(_name), Value() {}; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _value initial value to set */ template Parameter::Parameter(const std::string &_name, const T &_value) : ParameterInterface(_name), Value() { Value::set(_value); }; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue */ template Parameter::Parameter(const std::string &_name, const Validator &_Validator) : ParameterInterface(_name), Value(_Validator) {}; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue * @param _value initial value to set */ template Parameter::Parameter(const std::string &_name, const Validator &_Validator, const T &_value) : ParameterInterface(_name), Value(_Validator) { Value::set(_value); }; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue */ template Parameter::Parameter(const std::string &_name, const std::vector &_ValidValues) : ParameterInterface(_name), Value(_ValidValues) {}; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue * @param _value initial value to set */ template Parameter::Parameter(const std::string &_name, const std::vector &_ValidValues, const T &_value) : ParameterInterface(_name), Value(_ValidValues) { Value::set(_value); }; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue */ template Parameter::Parameter(const std::string &_name, const range &_ValidRange) : ParameterInterface(_name), Value(_ValidRange) {}; /** Constructor for class Parameter. * * @param _name name of this parameter * @param _ValidRange valid range for this ContinuousValue * @param _value initial value to set */ template Parameter::Parameter(const std::string &_name, const range &_ValidRange, const T &_value) : ParameterInterface(_name), Value(_ValidRange) { Value::set(_value); }; /** Destructor for class Parameter. * */ template Parameter::~Parameter() {}; /** Catch call to Value::getAsString() to add exception information. * * @return parameter value as string */ template const std::string Parameter::getAsString() const throw(ParameterValueException) { try { return Value::getAsString(); } catch(ParameterException &e) { e << ParameterName(ParameterInterface::getName()); throw; } } /** Catch call to Value::get() to add exception information. * * @return parameter value as string */ template const T & Parameter::get() const throw(ParameterValueException) { try { return Value::get(); } catch(ParameterException &e) { e << ParameterName(ParameterInterface::getName()); throw; } } /** Catch call to Value::set() to add exception information. * * @param _value value to set to */ template void Parameter::set(const T & _value) throw(ParameterValueException) { try { Value::set(_value); } catch(ParameterException &e) { e << ParameterName(ParameterInterface::getName()); throw; } } /** Catch call to Value::set() to add exception information. * * @param _value value to set to */ template void Parameter::setAsString(const std::string _value) throw(ParameterValueException) { try { Value::setAsString(_value); } catch(ParameterException &e) { e << ParameterName(ParameterInterface::getName()); throw; } } /** Compares this continuous value against another \a _instance. * * @param _instance other value to compare to * @return true - if contained ContinuousValue and name are the same, false - else */ template bool Parameter::operator==(const Parameter &_instance) const throw(ParameterException) { bool status = true; try { status = status && (*dynamic_cast *>(this) == dynamic_cast &>(_instance)); status = status && (ParameterInterface::getName() == _instance.ParameterInterface::getName()); } catch(ParameterException &e) { e << ParameterName(ParameterInterface::getName()); throw; } return status; } /** Creates a clone of this Parameter instance. * * @return cloned instance */ template ParameterAsString* Parameter::clone() const { Parameter *instance = new Parameter(ParameterInterface::getName(), Value::getValidator()); if (Value::ValueSet) instance->set(Value::get()); return instance; } #endif /* Parameter_IMPL_HPP_ */