25 #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
26 # include <boost/lexical_cast.hpp>
28 #include <boost/bind.hpp>
29 #include <boost/algorithm/string.hpp>
30 #include <boost/any.hpp>
31 #include <boost/function.hpp>
48 typedef boost::shared_ptr< Param >
ParamPtr;
55 public:
Param(
Param *_newParam) GAZEBO_DEPRECATED(1.6);
58 public:
virtual ~Param() GAZEBO_DEPRECATED(1.6);
61 public:
virtual std::string
GetAsString() const GAZEBO_DEPRECATED(1.6)
62 {
return std::string();}
64 GAZEBO_DEPRECATED(1.6)
65 {
return std::string();}
69 GAZEBO_DEPRECATED(1.6)
72 public:
virtual void Reset() GAZEBO_DEPRECATED(1.6) = 0;
74 public: const std::
string &
GetKey() const GAZEBO_DEPRECATED(1.6)
76 public: std::string
GetTypeName() const GAZEBO_DEPRECATED(1.6);
80 public:
bool GetSet() const GAZEBO_DEPRECATED(1.6)
82 public:
virtual boost::shared_ptr<Param>
Clone() const
83 GAZEBO_DEPRECATED(1.6) = 0;
88 public:
virtual void Update() GAZEBO_DEPRECATED(1.6) = 0;
94 public: template<typename T>
99 _value = boost::lexical_cast<T>(this->
GetAsString());
103 gzerr <<
"Unable to convert parameter[" << this->
key <<
"] "
104 <<
"whose type is[" << this->
typeName <<
"], to "
105 <<
"type[" <<
typeid(T).name() <<
"]\n";
111 public:
bool IsBool() const GAZEBO_DEPRECATED(1.6);
112 public:
bool IsInt() const GAZEBO_DEPRECATED(1.6);
113 public:
bool IsUInt() const GAZEBO_DEPRECATED(1.6);
114 public:
bool IsFloat() const GAZEBO_DEPRECATED(1.6);
115 public:
bool IsDouble() const GAZEBO_DEPRECATED(1.6);
116 public:
bool IsChar() const GAZEBO_DEPRECATED(1.6);
117 public:
bool IsStr() const GAZEBO_DEPRECATED(1.6);
118 public:
bool IsVector3() const GAZEBO_DEPRECATED(1.6);
119 public:
bool IsVector2i() const GAZEBO_DEPRECATED(1.6);
120 public:
bool IsVector2d() const GAZEBO_DEPRECATED(1.6);
121 public:
bool IsQuaternion() const GAZEBO_DEPRECATED(1.6);
122 public:
bool IsPose() const GAZEBO_DEPRECATED(1.6);
123 public:
bool IsColor() const GAZEBO_DEPRECATED(1.6);
124 public:
bool IsTime() const GAZEBO_DEPRECATED(1.6);
126 public:
bool Set(const
bool &_value) GAZEBO_DEPRECATED(1.6);
127 public:
bool Set(const
int &_value) GAZEBO_DEPRECATED(1.6);
128 public:
bool Set(const
unsigned int &_value) GAZEBO_DEPRECATED(1.6);
129 public:
bool Set(const
float &_value) GAZEBO_DEPRECATED(1.6);
130 public:
bool Set(const
double &_value) GAZEBO_DEPRECATED(1.6);
131 public:
bool Set(const
char &_value) GAZEBO_DEPRECATED(1.6);
132 public:
bool Set(const std::
string &_value) GAZEBO_DEPRECATED(1.6);
133 public:
bool Set(const
char *_value) GAZEBO_DEPRECATED(1.6);
135 const gazebo::math::Vector3 &_value) GAZEBO_DEPRECATED(1.6);
137 const gazebo::math::Vector2i &_value) GAZEBO_DEPRECATED(1.6);
139 const gazebo::math::Vector2d &_value) GAZEBO_DEPRECATED(1.6);
141 const gazebo::math::Quaternion &_value) GAZEBO_DEPRECATED(1.6);
143 const gazebo::math::Pose &_value) GAZEBO_DEPRECATED(1.6);
145 const gazebo::common::Color &_value) GAZEBO_DEPRECATED(1.6);
147 const gazebo::common::Time &_value) GAZEBO_DEPRECATED(1.6);
149 public:
bool Get(
bool &_value) GAZEBO_DEPRECATED(1.6);
150 public:
bool Get(
int &_value) GAZEBO_DEPRECATED(1.6);
151 public:
bool Get(
unsigned int &_value) GAZEBO_DEPRECATED(1.6);
152 public:
bool Get(
float &_value) GAZEBO_DEPRECATED(1.6);
153 public:
bool Get(
double &_value) GAZEBO_DEPRECATED(1.6);
154 public:
bool Get(
char &_value) GAZEBO_DEPRECATED(1.6);
155 public:
bool Get(std::
string &_value) GAZEBO_DEPRECATED(1.6);
156 public:
bool Get(gazebo::math::Vector3 &_value) GAZEBO_DEPRECATED(1.6);
157 public:
bool Get(gazebo::math::Vector2i &_value) GAZEBO_DEPRECATED(1.6);
158 public:
bool Get(gazebo::math::Vector2d &_value) GAZEBO_DEPRECATED(1.6);
159 public:
bool Get(gazebo::math::Quaternion &_value) GAZEBO_DEPRECATED(1.6);
160 public:
bool Get(gazebo::math::Pose &_value) GAZEBO_DEPRECATED(1.6);
161 public:
bool Get(gazebo::common::Color &_value) GAZEBO_DEPRECATED(1.6);
162 public:
bool Get(gazebo::common::Time &_value) GAZEBO_DEPRECATED(1.6);
166 const std::
string &_desc) GAZEBO_DEPRECATED(1.6);
169 public: std::
string GetDescription() const GAZEBO_DEPRECATED(1.6);
172 private: static std::vector<
Param*> *params GAZEBO_DEPRECATED(1.6);
174 protected: std::
string key;
184 template< typename T>
188 public:
ParamT(
const std::string &_key,
const std::string &_default,
189 bool _required,
const std::string &_typeName =
"",
190 const std::string &_description =
"")
191 GAZEBO_DEPRECATED(1.6)
195 this->required = _required;
196 if (_typeName.empty())
197 this->typeName =
typeid(T).name();
199 this->typeName = _typeName;
200 this->description = _description;
203 this->defaultValue = this->value;
208 public:
virtual ~ParamT() GAZEBO_DEPRECATED(1.6) {}
211 public:
virtual void Update() GAZEBO_DEPRECATED(1.6)
213 if (this->updateFunc)
217 const T v = boost::any_cast<T>(this->
updateFunc());
220 catch(boost::bad_any_cast &e)
222 gzerr <<
"boost any_cast error:" << e.what() <<
"\n";
228 public:
virtual std::string
GetAsString() const GAZEBO_DEPRECATED(1.6)
230 std::ostringstream stream;
231 stream << std::fixed << this->value;
237 GAZEBO_DEPRECATED(1.6)
238 {
return this->
Set(_value); }
241 GAZEBO_DEPRECATED(1.6)
243 return boost::lexical_cast<std::string>(this->defaultValue);
247 public:
virtual bool Set(
const std::string &_str)
248 GAZEBO_DEPRECATED(1.6)
250 std::string str = _str;
254 gzerr <<
"Empty string used when setting a required parameter. Key["
255 << this->
GetKey() <<
"]\n";
258 else if (str.empty())
260 this->value = this->defaultValue;
264 std::string tmp(str);
265 std::string lowerTmp(str);
266 boost::to_lower(lowerTmp);
269 if (lowerTmp ==
"true")
271 else if (lowerTmp ==
"false")
276 this->value = boost::lexical_cast<T>(tmp);
278 catch(boost::bad_lexical_cast &e)
280 if (str ==
"inf" || str ==
"-inf")
284 gzmsg <<
"INFO [sdf::Param]: boost throws when lexical casting "
285 <<
"inf's, but the values are usually passed through correctly\n";
289 gzerr <<
"Unable to set value [" << str
290 <<
"] for key[" << this->key <<
"]\n";
300 public: T GetValue() const GAZEBO_DEPRECATED(1.6)
306 public: T GetDefaultValue() const GAZEBO_DEPRECATED(1.6)
308 return this->defaultValue;
312 public:
void SetValue(
const T &_value) GAZEBO_DEPRECATED(1.6)
314 this->value = _value;
319 public:
virtual void Reset() GAZEBO_DEPRECATED(1.6)
321 this->value = this->defaultValue;
325 public:
virtual boost::shared_ptr<Param>
Clone() const
326 GAZEBO_DEPRECATED(1.6)
328 boost::shared_ptr<ParamT<T> > clone(
330 this->required, this->typeName,
335 public:
inline T
operator*() const GAZEBO_DEPRECATED(1.6) {
return value;}
336 public:
friend std::ostream &operator<<(std::ostream &_out,
337 const ParamT<T> &_p) GAZEBO_DEPRECATED(1.6)