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())
180 const T v = boost::any_cast<T>(this->
updateFunc());
183 catch(boost::bad_any_cast &e)
185 gzerr <<
"boost any_cast error:" << e.what() <<
"\n";
193 std::ostringstream stream;
194 stream << std::fixed << this->
value;
200 {
return this->
Set(_value); }
204 return boost::lexical_cast<std::string>(this->
defaultValue);
208 public:
virtual bool Set(
const std::string &_str)
210 std::string str = _str;
214 gzerr <<
"Empty string used when setting a required parameter. Key["
215 << this->
GetKey() <<
"]\n";
218 else if (str.empty())
224 std::string tmp(str);
225 std::string lowerTmp(str);
226 boost::to_lower(lowerTmp);
229 if (lowerTmp ==
"true")
231 else if (lowerTmp ==
"false")
236 this->
value = boost::lexical_cast<T>(tmp);
238 catch(boost::bad_lexical_cast &e)
240 if (str ==
"inf" || str ==
"-inf")
244 gzmsg <<
"INFO [sdf::Param]: boost throws when lexical casting "
245 <<
"inf's, but the values are usually passed through correctly\n";
249 gzerr <<
"Unable to set value [" << str
250 <<
"] for key[" << this->
key <<
"]\n";
274 this->
value = _value;
285 public:
virtual boost::shared_ptr<Param>
Clone()
const
287 boost::shared_ptr<ParamT<T> > clone(