18 #ifndef _SDF_PARAM_HH_
19 #define _SDF_PARAM_HH_
21 #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
22 # include <boost/lexical_cast.hpp>
23 # include <boost/bind.hpp>
24 # include <boost/algorithm/string.hpp>
25 # include <boost/variant.hpp>
26 # include <boost/any.hpp>
27 # include <boost/function.hpp>
28 # include <boost/shared_ptr.hpp>
62 public:
Param(
const std::string &_key,
const std::string &_typeName,
63 const std::string &_default,
bool _required,
64 const std::string &_description =
"");
67 public:
virtual ~
Param();
71 public: std::string GetAsString()
const;
75 public: std::string GetDefaultAsString()
const;
79 public:
bool SetFromString(
const std::string &_value);
86 public:
const std::string &
GetKey()
const {
return this->key;}
90 public:
const std::type_info &GetType()
const;
94 public:
const std::string &GetTypeName()
const;
102 public:
bool GetSet()
const {
return this->set;}
106 public: boost::shared_ptr<Param> Clone()
const;
112 {this->updateFunc = _updateFunc;}
116 public:
void Update();
124 public:
template<
typename T>
129 this->SetFromString(boost::lexical_cast<std::string>(_value));
133 sdferr <<
"Unable to set parameter[" << this->key <<
"]."
134 <<
"Type type used must have a stream input and output"
135 <<
"operator, which allow boost::lexical_cast to"
136 <<
"function properly.\n";
146 public:
template<
typename T>
151 if (
typeid(T) ==
typeid(
bool) && this->typeName ==
"string")
153 std::string strValue =
154 boost::lexical_cast<std::string>(this->value);
155 if (strValue ==
"true" || strValue ==
"1")
156 _value = boost::lexical_cast<T>(
"1");
158 _value = boost::lexical_cast<T>(
"0");
162 _value = boost::lexical_cast<T>(this->value);
167 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
168 <<
"whose type is[" << this->typeName <<
"], to "
169 <<
"type[" <<
typeid(T).name() <<
"]\n";
179 public:
template<
typename T>
184 _value = boost::lexical_cast<T>(this->defaultValue);
188 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
189 <<
"whose type is[" << this->typeName <<
"], to "
190 <<
"type[" <<
typeid(T).name() <<
"]\n";
202 this->value = _param.
value;
209 public:
void SetDescription(
const std::string &_desc);
213 public: std::string GetDescription()
const;
228 private:
template<
typename T>
229 void Init(
const std::string &_value)
233 this->value = boost::lexical_cast<T>(_value);
237 if (this->typeName ==
"bool")
239 std::string strValue = _value;
240 boost::algorithm::to_lower(strValue);
241 if (strValue ==
"true" || strValue ==
"1")
247 sdferr <<
"Unable to init parameter value from string["
251 this->defaultValue = this->value;
256 private: std::string key;
259 private:
bool required;
265 private: std::string typeName;
268 private: std::string description;
271 private: boost::function<boost::any ()> updateFunc;
275 private:
typedef boost::variant<bool, char, std::string, int,
Generic double x, y vector.
Definition: Types.hh:157
bool Get(T &_value)
Get the value of the parameter.
Definition: Param.hh:147
A parameter class.
Definition: Param.hh:53
ParamVariant defaultValue
This parameter's default value.
Definition: Param.hh:284
const std::string & GetKey() const
Get the key value.
Definition: Param.hh:86
bool Set(const T &_value)
Set the parameter's value.
Definition: Param.hh:125
bool GetDefault(T &_value)
Get the default value of the parameter.
Definition: Param.hh:180
ParamVariant value
This parameter's value.
Definition: Param.hh:281
A quaternion class.
Definition: Types.hh:310
bool GetRequired() const
Return whether the parameter is required.
Definition: Param.hh:98
friend std::ostream & operator<<(std::ostream &_out, const Param &_p)
Ostream operator.
Definition: Param.hh:219
class SDFORMAT_VISIBLE Param
Definition: Param.hh:41
void SetUpdateFunc(T _updateFunc)
Set the update function.
Definition: Param.hh:111
Generic integer x, y vector.
Definition: Types.hh:109
#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 GetAsString() const
Get the value as a string.
std::vector< ParamPtr > Param_V
Definition: Param.hh:49
Defines a color.
Definition: Types.hh:51
Param * ParamPtr
Definition: Param.hh:45
namespace for Simulation Description Format parser
Definition: Console.hh:29
bool GetSet() const
Return true if the parameter has been set.
Definition: Param.hh:102
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:681
Encapsulates a position and rotation in three space.
Definition: Types.hh:582
The Vector3 class represents the generic vector containing 3 elements.
Definition: Types.hh:209