25 #include <boost/lexical_cast.hpp>
26 #include <boost/bind.hpp>
27 #include <boost/algorithm/string.hpp>
28 #include <boost/any.hpp>
29 #include <boost/function.hpp>
46 typedef boost::shared_ptr< Param >
ParamPtr;
60 {
return std::string();}
62 {
return std::string();}
68 public:
virtual void Reset() = 0;
70 public:
const std::string &
GetKey()
const {
return this->
key;}
74 public:
bool GetSet()
const {
return this->
set; }
75 public:
virtual boost::shared_ptr<Param>
Clone()
const = 0;
80 public:
virtual void Update() = 0;
82 public:
bool IsBool()
const;
83 public:
bool IsInt()
const;
84 public:
bool IsUInt()
const;
87 public:
bool IsChar()
const;
88 public:
bool IsStr()
const;
93 public:
bool IsPose()
const;
95 public:
bool IsTime()
const;
97 public:
bool Set(
const bool &_value);
98 public:
bool Set(
const int &_value);
99 public:
bool Set(
const unsigned int &_value);
100 public:
bool Set(
const float &_value);
101 public:
bool Set(
const double &_value);
102 public:
bool Set(
const char &_value);
103 public:
bool Set(
const std::string &_value);
104 public:
bool Set(
const char *_value);
113 public:
bool Get(
bool &_value);
114 public:
bool Get(
int &_value);
115 public:
bool Get(
unsigned int &_value);
116 public:
bool Get(
float &_value);
117 public:
bool Get(
double &_value);
118 public:
bool Get(
char &_value);
119 public:
bool Get(std::string &_value);
135 private:
static std::vector<Param*> *params;
137 protected: std::string
key;
148 template<
typename T>
152 public:
ParamT(
const std::string &_key,
const std::string &_default,
153 bool _required,
const std::string &_typeName =
"",
154 const std::string &_description =
"")
159 if (_typeName.empty())
176 const T v = boost::any_cast<T>(this->
updateFunc());
184 std::ostringstream stream;
185 stream << std::fixed << this->
value;
191 {
return this->
Set(_value); }
195 return boost::lexical_cast<std::string>(this->
defaultValue);
199 public:
virtual bool Set(
const std::string &_str)
201 std::string str = _str;
205 gzerr <<
"Empty string used when setting a required parameter. Key["
206 << this->
GetKey() <<
"]\n";
209 else if (str.empty())
215 std::string tmp(str);
216 std::string lowerTmp(str);
217 boost::to_lower(lowerTmp);
220 if (lowerTmp ==
"true")
222 else if (lowerTmp ==
"false")
227 this->
value = boost::lexical_cast<T>(tmp);
229 catch(boost::bad_lexical_cast &e)
231 if (str ==
"inf" || str ==
"-inf")
235 gzmsg <<
"INFO [sdf::Param]: boost throws when lexical casting "
236 <<
"inf's, but the values are usually passed through correctly\n";
240 gzerr <<
"Unable to set value [" << str
241 <<
"] for key[" << this->
key <<
"]\n";
265 this->
value = _value;
276 public:
virtual boost::shared_ptr<Param>
Clone()
const
278 boost::shared_ptr<ParamT<T> > clone(