| 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 | void setAsString(const std::string &_value) throw(ParameterException);
|
|---|
| 56 |
|
|---|
| 57 | // comfortable setter
|
|---|
| 58 | Value<Vector> &operator=(const Vector &_value)
|
|---|
| 59 | { set(_value); return *this; }
|
|---|
| 60 |
|
|---|
| 61 | // comparator
|
|---|
| 62 | bool operator==(const Value<Vector> &_instance) const throw(ParameterValidatorException);
|
|---|
| 63 | bool operator!=(const Value<Vector> &_instance) const throw(ParameterValidatorException)
|
|---|
| 64 | { return !((*this)==(_instance)); }
|
|---|
| 65 |
|
|---|
| 66 | const Validator<Vector> & getValidator() const;
|
|---|
| 67 | Validator<Vector> & getValidator();
|
|---|
| 68 |
|
|---|
| 69 | // comfortable validator functions
|
|---|
| 70 | const range<Vector> & getValidRange() const throw(ParameterValidatorException);
|
|---|
| 71 | void setValidRange(const range<Vector> &_range) throw(ParameterValueException);
|
|---|
| 72 | void appendValidValue(const Vector &_value) throw(ParameterValidatorException);
|
|---|
| 73 | const std::vector<Vector> &getValidValues() const throw(ParameterValidatorException);
|
|---|
| 74 |
|
|---|
| 75 | static const Vector parseAsVector(const std::string &_value);
|
|---|
| 76 | static const std::string setFromVector(const Vector &_vec);
|
|---|
| 77 |
|
|---|
| 78 | private:
|
|---|
| 79 | //!> whether a value has been set or not
|
|---|
| 80 | bool ValueSet;
|
|---|
| 81 | //!> contained value
|
|---|
| 82 | std::string value;
|
|---|
| 83 | //!> converted value for allowing to return a ref
|
|---|
| 84 | mutable Vector converted_value;
|
|---|
| 85 |
|
|---|
| 86 | //!> the validator
|
|---|
| 87 | Validator<Vector> *validator;
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | #endif /* VALUE_VECTOR_HPP_ */
|
|---|