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,