18 #ifndef _SDF_PARAM_HH_
19 #define _SDF_PARAM_HH_
23 #include <boost/lexical_cast.hpp>
24 #include <boost/bind.hpp>
25 #include <boost/algorithm/string.hpp>
26 #include <boost/any.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/variant.hpp>
29 #include <boost/function.hpp>
35 #include <ignition/math.hh>
42 #pragma GCC diagnostic push
43 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
47 #pragma GCC diagnostic pop
76 public:
Param(
const std::string &_key,
const std::string &_typeName,
77 const std::string &_default,
bool _required,
78 const std::string &_description =
"");
81 public:
virtual ~
Param();
85 public: std::string GetAsString()
const;
89 public: std::string GetDefaultAsString()
const;
93 public:
bool SetFromString(
const std::string &_value);
100 public:
const std::string &GetKey()
const;
106 public:
const std::type_info &GetType()
const SDF_DEPRECATED(4.0);
111 public:
template<
typename Type>
116 public:
const std::string &GetTypeName()
const;
120 public:
bool GetRequired()
const;
124 public:
bool GetSet()
const;
128 public: boost::shared_ptr<Param> Clone()
const;
133 public:
template<
typename T>
134 void SetUpdateFunc(T _updateFunc);
138 public:
void Update();
146 public:
template<
typename T>
147 bool Set(
const T &_value);
152 public:
bool GetAny(boost::any &_anyVal)
const;
158 public:
template<
typename T>
159 bool Get(T &_value)
const;
165 public:
template<
typename T>
166 bool GetDefault(T &_value)
const;
172 public:
Param &operator=(
const Param &_param);
176 public:
void SetDescription(
const std::string &_desc);
180 public: std::string GetDescription()
const;
195 private:
template<
typename T>
196 void Init(
const std::string &_value);
226 #pragma GCC diagnostic push
227 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
229 public:
typedef boost::variant<bool, char, std::string, int, uint64_t,
235 ignition::math::Vector3d, ignition::math::Vector2i,
236 ignition::math::Vector2d, ignition::math::Quaterniond,
239 #pragma GCC diagnostic pop
262 this->
SetFromString(boost::lexical_cast<std::string>(_value));
266 sdferr <<
"Unable to set parameter["
267 << this->dataPtr->
key <<
"]."
268 <<
"Type type used must have a stream input and output"
269 <<
"operator, which allow boost::lexical_cast to"
270 <<
"function properly.\n";
282 if (
typeid(T) ==
typeid(
bool) &&
283 this->dataPtr->
typeName ==
"string")
285 std::string strValue =
286 boost::lexical_cast<std::string>(this->dataPtr->
value);
287 if (strValue ==
"true" || strValue ==
"1")
288 _value = boost::lexical_cast<T>(
"1");
290 _value = boost::lexical_cast<T>(
"0");
294 _value = boost::lexical_cast<T>(this->dataPtr->
value);
299 sdferr <<
"Unable to convert parameter["
300 << this->dataPtr->
key <<
"] "
302 << this->dataPtr->
typeName <<
"], to "
303 <<
"type[" <<
typeid(T).name() <<
"]\n";
315 _value = boost::lexical_cast<T>(this->dataPtr->
defaultValue);
319 sdferr <<
"Unable to convert parameter["
320 << this->dataPtr->
key <<
"] "
322 << this->dataPtr->
typeName <<
"], to "
323 <<
"type[" <<
typeid(T).name() <<
"]\n";
331 void Param::Init(
const std::string &_value)
335 this->dataPtr->
value = boost::lexical_cast<T>(_value);
339 if (this->dataPtr->
typeName ==
"bool")
341 std::string strValue = _value;
342 boost::algorithm::to_lower(strValue);
343 if (strValue ==
"true" || strValue ==
"1")
344 this->dataPtr->
value =
true;
346 this->dataPtr->
value =
false;
350 sdferr <<
"Unable to init parameter value from string["
356 this->dataPtr->
set =
false;
360 template<
typename Type>
363 return this->dataPtr->
value.type() ==
typeid(Type);
Generic double x, y vector.
Definition: Types.hh:170
A parameter class.
Definition: Param.hh:67
bool Set(const T &_value)
Set the parameter's value.
Definition: Param.hh:258
ParamVariant value
This parameter's value.
Definition: Param.hh:243
boost::function< boost::any()> updateFunc
Update function pointer.
Definition: Param.hh:222
A quaternion class.
Definition: Types.hh:325
ParamVariant defaultValue
This parameter's default value.
Definition: Param.hh:246
boost::variant< bool, char, std::string, int, uint64_t, unsigned int, double, float, sdf::Time, sdf::Color, sdf::Vector3, sdf::Vector2i, sdf::Vector2d, sdf::Quaternion, sdf::Pose, ignition::math::Vector3d, ignition::math::Vector2i, ignition::math::Vector2d, ignition::math::Quaterniond, ignition::math::Pose3d > ParamVariant
Definition: Param.hh:237
friend std::ostream & operator<<(std::ostream &_out, const Param &_p)
Ostream operator.
Definition: Param.hh:186
class SDFORMAT_VISIBLE Param
Definition: Param.hh:52
void SetUpdateFunc(T _updateFunc)
Set the update function.
Definition: Param.hh:251
Generic integer x, y vector.
Definition: Types.hh:121
bool set
True if the parameter is set.
Definition: Param.hh:213
std::string typeName
Definition: Param.hh:216
bool Get(T &_value) const
Get the value of the parameter.
Definition: Param.hh:278
bool required
True if the parameter is required.
Definition: Param.hh:210
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
#define sdferr
Output an error message.
Definition: Console.hh:47
std::string description
Description of the parameter.
Definition: Param.hh:219
bool SetFromString(const std::string &_value)
Set the parameter value from a string.
std::string GetAsString() const
Get the value as a string.
std::vector< ParamPtr > Param_V
Definition: Param.hh:60
Defines a color.
Definition: Types.hh:62
Param * ParamPtr
Definition: Param.hh:56
bool IsType() const
Return true if the param is a particular type.
Definition: Param.hh:361
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:697
std::string key
Key value.
Definition: Param.hh:207
Encapsulates a position and rotation in three space.
Definition: Types.hh:598
bool GetDefault(T &_value) const
Get the default value of the parameter.
Definition: Param.hh:311
#define SDF_DEPRECATED(version)
Definition: Types.hh:37
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Types.hh:223