18 #ifndef _SDF_PARAM_HH_ 19 #define _SDF_PARAM_HH_ 23 #include <boost/lexical_cast.hpp> 24 #include <boost/any.hpp> 25 #include <boost/variant.hpp> 34 #include <ignition/math.hh> 41 #pragma GCC diagnostic push 42 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 46 #pragma GCC diagnostic pop 75 public:
Param(
const std::string &_key,
const std::string &_typeName,
76 const std::string &_default,
bool _required,
77 const std::string &_description =
"");
80 public:
virtual ~
Param();
84 public: std::string GetAsString()
const;
88 public: std::string GetDefaultAsString()
const;
92 public:
bool SetFromString(
const std::string &_value);
99 public:
const std::string &GetKey()
const;
105 public:
const std::type_info &GetType()
const SDF_DEPRECATED(4.0);
110 public:
template<
typename Type>
115 public:
const std::string &GetTypeName()
const;
119 public:
bool GetRequired()
const;
123 public:
bool GetSet()
const;
127 public: ParamPtr Clone()
const;
132 public:
template<
typename T>
133 void SetUpdateFunc(T _updateFunc);
137 public:
void Update();
145 public:
template<
typename T>
146 bool Set(
const T &_value);
151 public:
bool GetAny(boost::any &_anyVal)
const;
157 public:
template<
typename T>
158 bool Get(T &_value)
const;
164 public:
template<
typename T>
165 bool GetDefault(T &_value)
const;
171 public:
Param &operator=(
const Param &_param);
175 public:
void SetDescription(
const std::string &_desc);
179 public: std::string GetDescription()
const;
194 private:
template<
typename T>
195 void Init(
const std::string &_value);
225 #pragma GCC diagnostic push 226 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 228 public:
typedef boost::variant<bool, char, std::string, int, uint64_t,
234 ignition::math::Vector3d, ignition::math::Vector2i,
235 ignition::math::Vector2d, ignition::math::Quaterniond,
238 #pragma GCC diagnostic pop 252 this->dataPtr->updateFunc = _updateFunc;
261 this->SetFromString(boost::lexical_cast<std::string>(_value));
265 sdferr <<
"Unable to set parameter[" 266 << this->dataPtr->key <<
"]." 267 <<
"Type type used must have a stream input and output" 268 <<
"operator, which allow boost::lexical_cast to" 269 <<
"function properly.\n";
281 if (
typeid(T) ==
typeid(
bool) &&
282 this->dataPtr->typeName ==
"string")
284 std::string strValue =
285 boost::lexical_cast<std::string>(this->dataPtr->value);
286 if (strValue ==
"true" || strValue ==
"1")
287 _value = boost::lexical_cast<T>(
"1");
289 _value = boost::lexical_cast<T>(
"0");
293 _value = boost::lexical_cast<T>(this->dataPtr->value);
298 sdferr <<
"Unable to convert parameter[" 299 << this->dataPtr->key <<
"] " 301 << this->dataPtr->typeName <<
"], to " 302 <<
"type[" <<
typeid(T).name() <<
"]\n";
314 _value = boost::lexical_cast<T>(this->dataPtr->defaultValue);
318 sdferr <<
"Unable to convert parameter[" 319 << this->dataPtr->key <<
"] " 321 << this->dataPtr->typeName <<
"], to " 322 <<
"type[" <<
typeid(T).name() <<
"]\n";
330 void Param::Init(
const std::string &_value)
334 this->dataPtr->value = boost::lexical_cast<T>(_value);
338 if (this->dataPtr->typeName ==
"bool")
340 std::string strValue = _value;
341 std::transform(strValue.begin(), strValue.end(),
342 strValue.begin(), ::tolower);
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[" 355 this->dataPtr->defaultValue = this->dataPtr->value;
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:169
A parameter class.
Definition: Param.hh:66
bool Set(const T &_value)
Set the parameter's value.
Definition: Param.hh:257
ParamVariant value
This parameter's value.
Definition: Param.hh:242
A quaternion class.
Definition: Types.hh:324
ParamVariant defaultValue
This parameter's default value.
Definition: Param.hh:245
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:236
friend std::ostream & operator<<(std::ostream &_out, const Param &_p)
Ostream operator.
Definition: Param.hh:185
class SDFORMAT_VISIBLE Param
Definition: Param.hh:51
void SetUpdateFunc(T _updateFunc)
Set the update function.
Definition: Param.hh:250
Generic integer x, y vector.
Definition: Types.hh:120
std::string typeName
Definition: Param.hh:215
std::function< boost::any()> updateFunc
Update function pointer.
Definition: Param.hh:221
bool Get(T &_value) const
Get the value of the parameter.
Definition: Param.hh:277
bool required
True if the parameter is required.
Definition: Param.hh:209
#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:218
std::shared_ptr< Param > ParamPtr
Definition: Param.hh:55
std::string GetAsString() const
Get the value as a string.
std::vector< ParamPtr > Param_V
Definition: Param.hh:59
Defines a color.
Definition: Types.hh:61
namespace for Simulation Description Format parser
Definition: Console.hh:29
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:696
std::string key
Key value.
Definition: Param.hh:206
Encapsulates a position and rotation in three space.
Definition: Types.hh:597
bool GetDefault(T &_value) const
Get the default value of the parameter.
Definition: Param.hh:310
#define SDF_DEPRECATED(version)
Definition: Types.hh:36
The Vector3 class represents the generic vector containing 3 elements.
Definition: Types.hh:222