Key for bounded values. More...
#include "keyvalue/key/generic/Bounded.h"
Public Types | |
enum | |
typedef Traits< ElementType, StdSingle, NoMap > | Traits_ |
typedef StdSingle< typename NoMap< ElementType > ::OutputType_ > | ConverterType_ |
typedef ConverterType_::InputType_ | InputType_ |
typedef ConverterType_::OutputType_ | OutputType_ |
Public Member Functions | |
Bounded (const string &name, const ElementType &bound1) | |
Constructs a key accepting values which are bounded either from below or from above. | |
Bounded (const string &name, const ElementType &bound1, const ElementType &bound2) | |
Constructs a key accepting values which are bounded both from below and from above. | |
void | checkOutput (ElementType element) const |
Compares element against the bound(s). | |
string | getName () const |
Gets Key's name. | |
void | setName (const string &name) |
Sets name. | |
ElementType | map (const value::Variant &variant) const |
Performs the mapping. | |
Private Attributes | |
const Bound1< ElementType > | bound1_ |
const Bound2< ElementType > | bound2_ |
Key for bounded values.
This is a template class
for keys corresponding to bounded values.
This template
is used, for instance, to define keys accepting double
values in intervals. More generally, a value x of type ElementType will be accepted if, and only if,
true
; and true
;where bound1_ and bound2_ are instances (for ElementType) of bound template class
es Bound1 and Bound2, resp.
Bound template class
es implement the method check whose signature is
bool
check(const ElementType& x) const;
This method compares its argument against a bound fixed at construction time and returns true
or false
depending on whether the argument is in the bound or not.
The following bound template class
es are implemented:
Bound1 cannot be NoBound and, by default, Bound2 is NoBound.
The two bounds are passed to constructors. If Bound2 is NoBound, then only bound1 must be provided (otherwise the compiler will complain).
Example 1: Consider a key for weights. It accepts only double
values (strictly) greater than 0.0, the template
instance and the key definition would be
Bounded<double, Greater> weight("Weight", 0.0);
Example 2: A key for probabilities may accept only double values in the interval [0,1]:
Bounded<double, Geq, Leq> probability("Probability", 0.0, 1.0);
ElementType | : (template parameter) See description above; | |
Comp1 | : (template parameter) 1st comparison class ; | |
Comp2 | : (template parameter) 2nd comparison class . |
Bounded | ( | const string & | name, | |
const ElementType & | bound1 | |||
) | [inline] |
Constructs a key accepting values which are bounded either from below or from above.
name | : The key name; | |
bound1 | : Bound which values are compared against (through Bound1). |
Bounded | ( | const string & | name, | |
const ElementType & | bound1, | |||
const ElementType & | bound2 | |||
) | [inline] |
Constructs a key accepting values which are bounded both from below and from above.
name | : The key name; | |
bound1 | : First bound which values are compared against (through by Bound1); | |
bound2 | : Second bound which values are compared against (through by Bound2). |
void checkOutput | ( | ElementType | element | ) | const [inline] |
Compares element against the bound(s).
element | : Element to be checked. |
RuntimeError | : If element is out of bound(s). |
string getName | ( | ) | const [inherited] |
void setName | ( | const string & | name | ) | [inherited] |
Sets name.
name | : The name. |
ElementType map | ( | const value::Variant & | variant | ) | const [inherited] |
Performs the mapping.
This method retrieves the content of value::Variant and, by considering enabled lexical convertions, converts it to Output. (See LexicalToolKit documentation.)
variant | : A value::Variant containing the input to be mapped. |