/* * Value.hpp * * Created on: Apr 13, 2012 * Author: ankele */ #ifndef VALUE_HPP_ #define VALUE_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "ValueInterface.hpp" #include "Validators/Validator.hpp" #include "StreamOperators.hpp" #include "CodePatterns/Range.hpp" #include "CodePatterns/toString.hpp" class ValueTest; template class Parameter; /** Converter for a string to a std::vector of any class * We use default conversion via stringstream as suggested by [Stroustrup]. * \param _&_object reference to object to convert. * \return converted \a _object of templated type */ template struct ConvertTo< std::vector > { std::vector operator()(std::string _object) { std::vector returnobjects; std::stringstream s; T object; s << _object; while (s.good()) { s >> object; returnobjects.push_back(object); } return returnobjects; } }; /** This class represents a general value. * */ template class Value : virtual public ValueInterface { //!> unit test needs to have access to internal values friend class ValueTest; friend class ContinuousValueTest; friend class Parameter; public: Value(); Value(const Validator &_validator); Value(const std::vector &_ValidValues); Value(const range &_ValidRange); virtual ~Value(); // functions for ValueInterface bool isValid(const T &_value) const; const T & get() const; void set(const T & _value); bool isSet() const; // string functions for ValueInterface bool isValidAsString(const std::string _value) const; const std::string getAsString() const; void setAsString(const std::string _value); // comfortable setter Value &operator=(const T &_value) { set(_value); return *this; } // comparator bool operator==(const Value &_instance) const; bool operator!=(const Value &_instance) const { return !((*this)==(_instance)); } const Validator & getValidator() const; Validator & getValidator(); // comfortable validator functions const range & getValidRange() const; void setValidRange(const range &_range); void appendValidValue(const T &_value); const std::vector &getValidValues() const; private: //!> Internal converter from string to internal type static ConvertTo Converter; //!> whether a value has been set or not bool ValueSet; //!> contained value T value; //!> the validator Validator *validator; }; #include "Value_impl.hpp" #endif /* VALUE_HPP_ */