Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __POINTMATCHER_PARAMETRIZABLE_H
00037 #define __POINTMATCHER_PARAMETRIZABLE_H
00038
00039 #include <stdexcept>
00040 #include <vector>
00041 #include <map>
00042 #include <set>
00043 #include <string>
00044 #include <boost/lexical_cast.hpp>
00045 #include <limits>
00046 #define BOOST_ASSIGN_MAX_PARAMS 6
00047 #include <boost/assign/list_inserter.hpp>
00048
00049
00050 namespace PointMatcherSupport
00051 {
00053 template<typename Target>
00054 inline Target lexical_cast_scalar_to_string(const std::string& arg)
00055 {
00056 if (arg == "inf")
00057 return std::numeric_limits<Target>::infinity();
00058 else if (arg == "-inf")
00059 return -std::numeric_limits<Target>::infinity();
00060 else if (arg == "nan")
00061 return std::numeric_limits<Target>::quiet_NaN();
00062 else
00063 return boost::lexical_cast<Target>(arg);
00064 }
00065
00067 template<typename Target>
00068 inline Target lexical_cast_scalar_to_string(const char*& arg)
00069 {
00070 return lexical_cast_scalar_to_string<Target>(std::string(arg));
00071 }
00072
00073
00075 template<typename Target, typename Source>
00076 inline Target lexical_cast(const Source& arg)
00077 {
00078 return boost::lexical_cast<Target>(arg);
00079 }
00080
00082 template<>
00083 inline float lexical_cast(const std::string& arg) { return lexical_cast_scalar_to_string<float>(arg); }
00085 template<>
00086 inline double lexical_cast(const std::string& arg) { return lexical_cast_scalar_to_string<double>(arg); }
00087
00088
00089
00091 template<typename S>
00092 std::string toParam(const S& value)
00093 {
00094 return lexical_cast<std::string>(value);
00095 }
00096
00098 struct Parametrizable
00099 {
00101 struct InvalidParameter: std::runtime_error
00102 {
00103 InvalidParameter(const std::string& reason);
00104 };
00105
00107 typedef bool(*LexicalComparison)(std::string a, std::string b);
00108
00110 template<typename S>
00111 static bool Comp(std::string a, std::string b)
00112 {
00113 return lexical_cast<S>(a) < lexical_cast<S>(b);
00114 }
00115
00117 struct ParameterDoc
00118 {
00119 std::string name;
00120 std::string doc;
00121 std::string defaultValue;
00122 std::string minValue;
00123 std::string maxValue;
00124 LexicalComparison comp;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 ParameterDoc(const std::string& name, const std::string& doc, const std::string& defaultValue, const std::string& minValue, const std::string& maxValue, LexicalComparison comp);
00138 ParameterDoc(const std::string& name, const std::string& doc, const std::string& defaultValue);
00139
00140 friend std::ostream& operator<< (std::ostream& o, const ParameterDoc& p);
00141 };
00142
00144 typedef std::vector<ParameterDoc> ParametersDoc;
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 typedef std::string Parameter;
00156 typedef std::map<std::string, Parameter> Parameters;
00157 typedef std::set<std::string> ParametersUsed;
00158
00159 const std::string className;
00160 const ParametersDoc parametersDoc;
00161 Parameters parameters;
00162 ParametersUsed parametersUsed;
00163
00164 Parametrizable();
00165 Parametrizable(const std::string& className, const ParametersDoc paramsDoc, const Parameters& params);
00166 virtual ~Parametrizable();
00167
00168 std::string getParamValueString(const std::string& paramName);
00169
00171 template<typename S>
00172 S get(const std::string& paramName) { return lexical_cast<S>(getParamValueString(paramName)); }
00173
00174 friend std::ostream& operator<< (std::ostream& o, const Parametrizable& p);
00175 };
00176 std::ostream& operator<< (std::ostream& o, const Parametrizable::ParametersDoc& p);
00177 }
00178
00179 #endif // __POINTMATCHER_PARAMETRIZABLE_H