1 | /*
|
---|
2 | * DiscreteValue.hpp
|
---|
3 | *
|
---|
4 | * Created on: Sep 28, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef DISCRETEVALUE_HPP_
|
---|
9 | #define DISCRETEVALUE_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <string>
|
---|
17 | #include <vector>
|
---|
18 |
|
---|
19 | #include "ValueInterface.hpp"
|
---|
20 |
|
---|
21 | class DiscreteValueTest;
|
---|
22 |
|
---|
23 | /** This class represents a discrete value.
|
---|
24 | *
|
---|
25 | */
|
---|
26 | template <class T>
|
---|
27 | class DiscreteValue : virtual public ValueInterface<T>
|
---|
28 | {
|
---|
29 | //!> unit test needs to have access to internal values
|
---|
30 | friend class DiscreteValueTest;
|
---|
31 | public:
|
---|
32 | DiscreteValue();
|
---|
33 | DiscreteValue(const std::vector<T> &_ValidValues);
|
---|
34 | virtual ~DiscreteValue();
|
---|
35 |
|
---|
36 | // functions for ValueInterface
|
---|
37 | bool isValid(const T &_value) const;
|
---|
38 | const T & get() const;
|
---|
39 | void set(const T & _value);
|
---|
40 |
|
---|
41 | // comfortable setter
|
---|
42 | void operator=(const T &_value)
|
---|
43 | { set(_value); }
|
---|
44 |
|
---|
45 | // comparator
|
---|
46 | bool operator==(const DiscreteValue<T> &_instance) const;
|
---|
47 | bool operator!=(const DiscreteValue<T> &_instance) const
|
---|
48 | { return !((*this)==(_instance)); }
|
---|
49 |
|
---|
50 | // setter/getter for valid values
|
---|
51 | void appendValidValue(const T &_value);
|
---|
52 | const std::vector<T> &getValidValues() const;
|
---|
53 |
|
---|
54 | // string functions for ValueInterface
|
---|
55 | bool isValidAsString(const std::string _value) const;
|
---|
56 | const std::string getAsString() const;
|
---|
57 | void setAsString(const std::string _value);
|
---|
58 | const size_t getIndexOfValue() const { return value; }
|
---|
59 |
|
---|
60 | private:
|
---|
61 | const size_t findIndexOfValue(const T &_value) const;
|
---|
62 |
|
---|
63 | private:
|
---|
64 | //!> Typedef for the vector of valid values.
|
---|
65 | typedef std::vector<T> ValidRange;
|
---|
66 |
|
---|
67 | //!> whether a value has been set or not
|
---|
68 | bool ValueSet;
|
---|
69 |
|
---|
70 | //!> we only store the index within the \a ValidValues for the value
|
---|
71 | size_t value;
|
---|
72 | //!> list of valid values
|
---|
73 | std::vector<T> ValidValues;
|
---|
74 | };
|
---|
75 |
|
---|
76 | #include "DiscreteValue_impl.hpp"
|
---|
77 |
|
---|
78 | #endif /* DISCRETEVALUE_HPP_ */
|
---|