18#ifndef SDFORMAT_PARAM_HH_
19#define SDFORMAT_PARAM_HH_
21#include <boost/any.hpp>
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wc++98-c++11-compat"
26#include <boost/variant.hpp>
28 #pragma clang diagnostic pop
41#include <ignition/math.hh>
51#pragma warning(disable: 4251)
81 public:
Param(
const std::string &_key,
const std::string &_typeName,
82 const std::string &_default,
bool _required,
83 const std::string &_description =
"");
105 public:
const std::string &
GetKey()
const;
110 public:
template<
typename Type>
132 public:
template<
typename T>
144 public:
template<
typename T>
145 bool Set(
const T &_value);
150 public:
bool GetAny(boost::any &_anyVal)
const;
156 public:
template<
typename T>
157 bool Get(T &_value)
const;
163 public:
template<
typename T>
193 private:
bool ValueFromString(
const std::string &_value);
196 private: std::unique_ptr<ParamPrivate> dataPtr;
223 public:
typedef boost::variant<bool, char, std::string, int, std::uint64_t,
225 ignition::math::Color,
226 ignition::math::Vector2i,
227 ignition::math::Vector2d,
228 ignition::math::Vector3d,
229 ignition::math::Quaterniond,
243 this->dataPtr->updateFunc = _updateFunc;
252 std::stringstream ss;
258 sdferr <<
"Unable to set parameter["
259 << this->dataPtr->key <<
"]."
260 <<
"Type used must have a stream input and output operator,"
261 <<
"which allows proper functioning of Param.\n";
272 if (
typeid(T) ==
typeid(
bool) && this->dataPtr->typeName ==
"string")
274 std::stringstream ss;
275 ss << this->dataPtr->value;
277 std::string strValue;
280 std::transform(strValue.begin(), strValue.end(), strValue.begin(),
283 return static_cast<unsigned char>(std::tolower(c));
286 std::stringstream tmp;
287 if (strValue ==
"true" || strValue ==
"1")
297 else if (
typeid(T) == this->dataPtr->value.type())
299#if BOOST_VERSION < 105800
300 _value = boost::get<T>(this->dataPtr->value);
302 _value = boost::relaxed_get<T>(this->dataPtr->value);
307 std::stringstream ss;
308 ss << this->dataPtr->value;
314 sdferr <<
"Unable to convert parameter["
315 << this->dataPtr->key <<
"] "
317 << this->dataPtr->typeName <<
"], to "
318 <<
"type[" <<
typeid(T).name() <<
"]\n";
328 std::stringstream ss;
332 ss << this->dataPtr->defaultValue;
337 sdferr <<
"Unable to convert parameter["
338 << this->dataPtr->key <<
"] "
340 << this->dataPtr->typeName <<
"], to "
341 <<
"type[" <<
typeid(T).name() <<
"]\n";
349 template<
typename Type>
352 return this->dataPtr->value.type() ==
typeid(Type);
std::string description
Description of the parameter.
Definition Param.hh:216
ParamVariant value
This parameter's value.
Definition Param.hh:233
bool required
True if the parameter is required.
Definition Param.hh:207
bool set
True if the parameter is set.
Definition Param.hh:210
std::string key
Key value.
Definition Param.hh:204
boost::variant< bool, char, std::string, int, std::uint64_t, unsigned int, double, float, sdf::Time, ignition::math::Color, ignition::math::Vector2i, ignition::math::Vector2d, ignition::math::Vector3d, ignition::math::Quaterniond, ignition::math::Pose3d > ParamVariant
Definition Param.hh:230
std::string typeName
Definition Param.hh:213
ParamVariant defaultValue
This parameter's default value.
Definition Param.hh:236
std::function< boost::any()> updateFunc
Update function pointer.
Definition Param.hh:219
A parameter class.
Definition Param.hh:72
ParamPtr Clone() const
Clone the parameter.
std::string GetDescription() const
Get the description of the parameter.
bool Get(T &_value) const
Get the value of the parameter.
Definition Param.hh:268
const std::string & GetKey() const
Get the key value.
void SetUpdateFunc(T _updateFunc)
Set the update function.
Definition Param.hh:241
bool GetRequired() const
Return whether the parameter is required.
const std::string & GetTypeName() const
Get the type name value.
void Update()
Set the parameter's value using the updateFunc.
void SetDescription(const std::string &_desc)
Set the description of the parameter.
std::string GetDefaultAsString() const
Get the default value as a string.
bool GetSet() const
Return true if the parameter has been set.
friend std::ostream & operator<<(std::ostream &_out, const Param &_p)
Ostream operator.
Definition Param.hh:184
Param(const std::string &_key, const std::string &_typeName, const std::string &_default, bool _required, const std::string &_description="")
Constructor.
bool SetFromString(const std::string &_value)
Set the parameter value from a string.
virtual ~Param()
Destructor.
std::string GetAsString() const
Get the value as a string.
void Reset()
Reset the parameter to the default value.
bool Set(const T &_value)
Set the parameter's value.
Definition Param.hh:248
bool GetAny(boost::any &_anyVal) const
Get the value of the parameter as a boost::any.
bool GetDefault(T &_value) const
Get the default value of the parameter.
Definition Param.hh:326
bool IsType() const
Return true if the param is a particular type.
Definition Param.hh:350
Param & operator=(const Param &_param)
Equal operator.
A Time class, can be used to hold wall- or sim-time.
Definition Types.hh:134
#define sdferr
Output an error message.
Definition Console.hh:52
namespace for Simulation Description Format parser
Definition Console.hh:36
std::vector< ParamPtr > Param_V
Definition Param.hh:64
std::shared_ptr< Param > ParamPtr
Definition Param.hh:60
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:48