36 #ifndef __POINTMATCHER_PARAMETRIZABLE_H 37 #define __POINTMATCHER_PARAMETRIZABLE_H 44 #include <boost/lexical_cast.hpp> 46 #define BOOST_ASSIGN_MAX_PARAMS 6 47 #include <boost/assign/list_inserter.hpp> 53 template<
typename Target>
57 return std::numeric_limits<Target>::infinity();
58 else if (arg ==
"-inf")
59 return -std::numeric_limits<Target>::infinity();
60 else if (arg ==
"nan")
61 return std::numeric_limits<Target>::quiet_NaN();
63 return boost::lexical_cast<Target>(arg);
67 template<
typename Target>
70 return lexical_cast_scalar_to_string<Target>(std::string(arg));
75 template<
typename Target,
typename Source>
78 return boost::lexical_cast<Target>(arg);
83 inline float lexical_cast(
const std::string& arg) {
return lexical_cast_scalar_to_string<float>(arg); }
86 inline double lexical_cast(
const std::string& arg) {
return lexical_cast_scalar_to_string<double>(arg); }
94 return lexical_cast<std::string>(value);
111 static bool Comp(std::string a, std::string b)
113 return lexical_cast<S>(a) < lexical_cast<S>(b);
179 #endif // __POINTMATCHER_PARAMETRIZABLE_H friend std::ostream & operator<<(std::ostream &o, const Parametrizable &p)
Dump the documentation of this object to a stream.
Definition: Parametrizable.cpp:62
InvalidParameter(const std::string &reason)
Construct an invalid-parameter exception.
Definition: Parametrizable.cpp:46
virtual ~Parametrizable()
Virtual destructor, do nothing.
Definition: Parametrizable.cpp:195
std::string toParam(const S &value)
Return the a string value using lexical_cast.
Definition: Parametrizable.h:92
std::ostream & operator<<(std::ostream &o, const Parametrizable::ParametersDoc &p)
Dump the documentation of these parameters to a stream.
Definition: Parametrizable.cpp:69
ParametersUsed parametersUsed
parameters whose value has actually been read
Definition: Parametrizable.h:162
Parametrizable()
Construct a documentation of parameters from a description in the source.
Definition: Parametrizable.cpp:165
std::set< std::string > ParametersUsed
Parameters whose value has been read.
Definition: Parametrizable.h:157
Target lexical_cast_scalar_to_string(const std::string &arg)
A lexical casting function that is an improvements over boost::lexical_cast that can handle "inf",...
Definition: Parametrizable.h:54
bool(* LexicalComparison)(std::string a, std::string b)
A function that returns whether a is smaller than b.
Definition: Parametrizable.h:107
std::string minValue
if bounds are checked, minimum value
Definition: Parametrizable.h:122
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Definition: Parametrizable.h:156
LexicalComparison comp
pointer to comparison function
Definition: Parametrizable.h:124
Functions and classes that are not dependant on scalar type are defined in this namespace.
Definition: PointMatcher.h:78
std::string maxValue
if bounds are checked, maxmimu value
Definition: Parametrizable.h:123
Parameters parameters
parameters with their values encoded in string
Definition: Parametrizable.h:161
std::string Parameter
alias
Definition: Parametrizable.h:155
The documentation of a parameter.
Definition: Parametrizable.h:117
friend std::ostream & operator<<(std::ostream &o, const ParameterDoc &p)
Dump the documentation of this parameter to a stream.
Definition: Parametrizable.cpp:51
Target lexical_cast(const Source &arg)
General case of lexical cast, use boost.
Definition: Parametrizable.h:76
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:98
An exception thrown when one tries to fetch the value of an unexisting parameter.
Definition: Parametrizable.h:101
std::string getParamValueString(const std::string ¶mName)
Get the value of a parameter, as a string.
Definition: Parametrizable.cpp:199
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
Definition: Parametrizable.h:144
std::string defaultValue
default value
Definition: Parametrizable.h:121
static bool Comp(std::string a, std::string b)
Return whether a < b, lexically casted to S.
Definition: Parametrizable.h:111
S get(const std::string ¶mName)
Return the value of paramName, lexically-casted to S.
Definition: Parametrizable.h:172
const std::string className
name of the class
Definition: Parametrizable.h:159
std::string doc
short documentation
Definition: Parametrizable.h:120
const ParametersDoc parametersDoc
documentation of parameters
Definition: Parametrizable.h:160
std::string name
name
Definition: Parametrizable.h:119
ParameterDoc(const std::string &name, const std::string &doc, const std::string &defaultValue, const std::string &minValue, const std::string &maxValue, LexicalComparison comp)
Construct a parameter documentation with bounds.
Definition: Parametrizable.cpp:112