Bounded< ElementType, Bound1, Bound2 > Class Template Reference

Key for bounded values. More...

#include "keyvalue/key/generic/Bounded.h"

Inheritance diagram for Bounded< ElementType, Bound1, Bound2 >:
Inheritance graph
[legend]

List of all members.

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_

Detailed Description

template<typename ElementType, template< typename > class Bound1, template< typename > class Bound2 = NoBound>
class keyvalue::key::Bounded< ElementType, Bound1, 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,

where bound1_ and bound2_ are instances (for ElementType) of bound template classes Bound1 and Bound2, resp.

Bound template classes 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 classes 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);

Parameters:
ElementType : (template parameter) See description above;
Comp1 : (template parameter) 1st comparison class;
Comp2 : (template parameter) 2nd comparison class.

Constructor & Destructor Documentation

Bounded ( const string &  name,
const ElementType &  bound1 
) [inline]

Constructs a key accepting values which are bounded either from below or from above.

Parameters:
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.

Parameters:
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).

Member Function Documentation

void checkOutput ( ElementType  element  )  const [inline]

Compares element against the bound(s).

Parameters:
element : Element to be checked.
Exceptions:
RuntimeError : If element is out of bound(s).
string getName (  )  const [inherited]

Gets Key's name.

Returns:
The Key's name.

Reimplemented from Key.

void setName ( const string &  name  )  [inherited]

Sets name.

Parameters:
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.)

Parameters:
variant : A value::Variant containing the input to be mapped.
Returns:
The mapping result.

Generated on Sat Mar 20 15:08:30 2010 for KeyValue by  doxygen 1.6.1