| 1 | /* | 
|---|
| 2 | * Value_vector.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Mar 29, 2017 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef VALUE_VECTOR_HPP_ | 
|---|
| 9 | #define VALUE_VECTOR_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <string> | 
|---|
| 17 |  | 
|---|
| 18 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| 19 |  | 
|---|
| 20 | #include "Parameters/Value.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | /** This class represents a the Vector class specialization of a general value. | 
|---|
| 23 | * | 
|---|
| 24 | * Instead of a Vector we internally store a string. | 
|---|
| 25 | * This allows us to override the default get() behavior and allows us to first | 
|---|
| 26 | * do the parsing of the string into vector components. | 
|---|
| 27 | * | 
|---|
| 28 | */ | 
|---|
| 29 | template <> | 
|---|
| 30 | class Value<Vector> : | 
|---|
| 31 | public ValueAsString, | 
|---|
| 32 | public ValueInterface<Vector> | 
|---|
| 33 | { | 
|---|
| 34 | //!> unit test needs to have access to internal values | 
|---|
| 35 | friend class ValueTest; | 
|---|
| 36 | friend class ContinuousValueTest; | 
|---|
| 37 | friend class Parameter<Vector>; | 
|---|
| 38 | public: | 
|---|
| 39 | Value(); | 
|---|
| 40 | Value(const Validator<Vector> &_validator); | 
|---|
| 41 | Value(const std::vector<Vector> &_ValidValues); | 
|---|
| 42 | Value(const range<Vector> &_ValidRange); | 
|---|
| 43 | virtual ~Value(); | 
|---|
| 44 |  | 
|---|
| 45 | // functions for ValueInterface | 
|---|
| 46 | bool isValid(const Vector &_value) const throw(ParameterValidatorException); | 
|---|
| 47 | const Vector & getUnvalidated() const throw(ParameterValueException); | 
|---|
| 48 | const Vector & get() const throw(ParameterValueException); | 
|---|
| 49 | void set(const Vector & _value) throw(ParameterException); | 
|---|
| 50 | bool isSet() const; | 
|---|
| 51 |  | 
|---|
| 52 | // string functions for ValueInterface | 
|---|
| 53 | bool isValidAsString(const std::string &_value) const throw(ParameterValidatorException); | 
|---|
| 54 | const std::string getAsString() const throw(ParameterValueException); | 
|---|
| 55 | const std::string getAsStringUnvalidated() const throw(ParameterValueException); | 
|---|
| 56 | void setAsString(const std::string &_value) throw(ParameterException); | 
|---|
| 57 |  | 
|---|
| 58 | // comfortable setter | 
|---|
| 59 | Value<Vector> &operator=(const Vector &_value) | 
|---|
| 60 | { set(_value);  return *this;  } | 
|---|
| 61 |  | 
|---|
| 62 | // comparator | 
|---|
| 63 | bool operator==(const Value<Vector> &_instance) const throw(ParameterValidatorException); | 
|---|
| 64 | bool operator!=(const Value<Vector> &_instance) const throw(ParameterValidatorException) | 
|---|
| 65 | { return !((*this)==(_instance)); } | 
|---|
| 66 |  | 
|---|
| 67 | const Validator<Vector> & getValidator() const; | 
|---|
| 68 | Validator<Vector> & getValidator(); | 
|---|
| 69 |  | 
|---|
| 70 | // comfortable validator functions | 
|---|
| 71 | const range<Vector> & getValidRange() const throw(ParameterValidatorException); | 
|---|
| 72 | void setValidRange(const range<Vector> &_range) throw(ParameterValueException); | 
|---|
| 73 | void appendValidValue(const Vector &_value) throw(ParameterValidatorException); | 
|---|
| 74 | const std::vector<Vector> &getValidValues() const throw(ParameterValidatorException); | 
|---|
| 75 |  | 
|---|
| 76 | static const Vector parseAsVector(const std::string &_value); | 
|---|
| 77 | static const std::string setFromVector(const Vector &_vec); | 
|---|
| 78 |  | 
|---|
| 79 | private: | 
|---|
| 80 | //!> whether a value has been set or not | 
|---|
| 81 | bool ValueSet; | 
|---|
| 82 | //!> contained value | 
|---|
| 83 | std::string value; | 
|---|
| 84 | //!> converted value for allowing to return a ref | 
|---|
| 85 | mutable Vector converted_value; | 
|---|
| 86 |  | 
|---|
| 87 | //!> the validator | 
|---|
| 88 | Validator<Vector> *validator; | 
|---|
| 89 | }; | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | #endif /* VALUE_VECTOR_HPP_ */ | 
|---|