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>
24 #include <boost/bind.hpp>
25 #include <boost/algorithm/string.hpp>
26 #include <boost/variant.hpp>
27 #include <boost/any.hpp>
28 #include <boost/function.hpp>
29 #include <boost/shared_ptr.hpp>
61 public:
Param(
const std::string &_key,
const std::string &_typeName,
62 const std::string &_default,
bool _required,
63 const std::string &_description =
"");
85 public:
const std::string &
GetKey()
const {
return this->key;}
89 public:
const std::type_info &
GetType()
const;
101 public:
bool GetSet()
const {
return this->set;}
105 public: boost::shared_ptr<Param>
Clone()
const;
111 {this->updateFunc = _updateFunc;}
123 public:
template<
typename T>
128 this->
SetFromString(boost::lexical_cast<std::string>(_value));
132 sdferr <<
"Unable to set parameter[" << this->key <<
"]."
133 <<
"Type type used must have a stream input and output"
134 <<
"operator, which allow boost::lexical_cast to"
135 <<
"function properly.\n";
145 public:
template<
typename T>
150 _value = boost::lexical_cast<T>(this->
value);
154 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
155 <<
"whose type is[" << this->typeName <<
"], to "
156 <<
"type[" <<
typeid(T).name() <<
"]\n";
166 public:
template<
typename T>
175 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
176 <<
"whose type is[" << this->typeName <<
"], to "
177 <<
"type[" <<
typeid(T).name() <<
"]\n";
215 private:
template<
typename T>
216 void Init(
const std::string &_value)
220 this->
value = boost::lexical_cast<T>(_value);
224 if (this->typeName ==
"bool")
226 std::string strValue = _value;
227 boost::algorithm::to_lower(strValue);
228 if (strValue ==
"true" || strValue ==
"1")
234 sdferr <<
"Unable to init parameter value from string["
243 private: std::string key;
246 private:
bool required;
252 private: std::string typeName;
255 private: std::string description;
258 private: boost::function<boost::any ()> updateFunc;
262 private:
typedef boost::variant<bool, char, std::string, int,
Generic double x, y vector.
Definition: Types.hh:155
std::string GetDefaultAsString() const
Get the default value as a string.
const std::string & GetTypeName() const
Get the type name value.
void SetDescription(const std::string &_desc)
Set the description of the parameter.
bool Get(T &_value)
Get the value of the parameter.
Definition: Param.hh:146
A parameter class.
Definition: Param.hh:52
ParamVariant defaultValue
This parameter's default value.
Definition: Param.hh:271
const std::string & GetKey() const
Get the key value.
Definition: Param.hh:85
bool Set(const T &_value)
Set the parameter's value.
Definition: Param.hh:124
std::string GetDescription() const
Get the description of the parameter.
bool GetDefault(T &_value)
Get the default value of the parameter.
Definition: Param.hh:167
ParamVariant value
This parameter's value.
Definition: Param.hh:268
A quaternion class.
Definition: Types.hh:308
bool GetRequired() const
Return whether the parameter is required.
Definition: Param.hh:97
friend std::ostream & operator<<(std::ostream &_out, const Param &_p)
Ostream operator.
Definition: Param.hh:206
void SetUpdateFunc(T _updateFunc)
Set the update function.
Definition: Param.hh:110
Generic integer x, y vector.
Definition: Types.hh:107
virtual ~Param()
Destructor.
Param & operator=(const Param &_param)
Equal operator.
Definition: Param.hh:187
void Update()
Set the parameter's value using the updateFunc.
#define sdferr
Output an error message.
Definition: Console.hh:45
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.
std::string GetAsString() const
Get the value as a string.
std::vector< ParamPtr > Param_V
Definition: Param.hh:48
Param * Clone() const
Clone the parameter.
void Reset()
Reset the parameter to the default value.
const std::type_info & GetType() const
Get the type of the value stored.
Defines a color.
Definition: Types.hh:49
Param * ParamPtr
Definition: Param.hh:44
bool GetSet() const
Return true if the parameter has been set.
Definition: Param.hh:101
A Time class, can be used to hold wall- or sim-time.
Definition: Types.hh:679
Encapsulates a position and rotation in three space.
Definition: Types.hh:580
The Vector3 class represents the generic vector containing 3 elements.
Definition: Types.hh:207