/* * DiscreteValue.hpp * * Created on: Sep 28, 2011 * Author: heber */ #ifndef DISCRETEVALUE_HPP_ #define DISCRETEVALUE_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "ValueInterface.hpp" class DiscreteValueTest; /** This class represents a discrete value. * */ template class DiscreteValue : virtual public ValueInterface { //!> unit test needs to have access to internal values friend class DiscreteValueTest; public: DiscreteValue(); DiscreteValue(const std::vector &_ValidValues); virtual ~DiscreteValue(); // functions for ValueInterface bool isValid(const T &_value) const; const T & get() const; void set(const T & _value); // comfortable setter void operator=(const T &_value) { set(_value); } // comparator bool operator==(const DiscreteValue &_instance) const; bool operator!=(const DiscreteValue &_instance) const { return !((*this)==(_instance)); } // setter/getter for valid values void appendValidValue(const T &_value); const std::vector &getValidValues() const; // string functions for ValueInterface bool isValidAsString(const std::string _value) const; const std::string getAsString() const; void setAsString(const std::string _value); const size_t getIndexOfValue() const { return value; } private: const size_t findIndexOfValue(const T &_value) const; private: //!> Typedef for the vector of valid values. typedef std::vector ValidRange; //!> whether a value has been set or not bool ValueSet; //!> we only store the index within the \a ValidValues for the value size_t value; //!> list of valid values std::vector ValidValues; }; #include "DiscreteValue_impl.hpp" #endif /* DISCRETEVALUE_HPP_ */