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>
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;
111 public:
template<
typename T>
void SetUpdateFunc(T _updateFunc)
112 {this->updateFunc = _updateFunc;}
116 public:
void Update();
124 public:
template<
typename T>
125 bool Set(
const T &_value)
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 _value = boost::lexical_cast<T>(this->value);
155 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
156 <<
"whose type is[" << this->typeName <<
"], to "
157 <<
"type[" <<
typeid(T).name() <<
"]\n";
167 public:
template<
typename T>
168 bool GetDefault(T &_value)
172 _value = boost::lexical_cast<T>(this->defaultValue);
176 sdferr <<
"Unable to convert parameter[" << this->key <<
"] "
177 <<
"whose type is[" << this->typeName <<
"], to "
178 <<
"type[" <<
typeid(T).name() <<
"]\n";
190 this->value = _param.
value;
197 public:
void SetDescription(
const std::string &_desc);
201 public: std::string GetDescription()
const;
207 public:
friend std::ostream &operator<<(std::ostream &_out,
216 private:
template<
typename T>
217 void Init(
const std::string &_value)
221 this->value = boost::lexical_cast<T>(_value);
225 if (this->typeName ==
"bool")
227 std::string strValue = _value;
228 boost::algorithm::to_lower(strValue);
229 if (strValue ==
"true" || strValue ==
"1")
235 sdferr <<
"Unable to init parameter value from string["
239 this->defaultValue = this->value;
244 private: std::string key;
247 private:
bool required;
253 private: std::string typeName;
256 private: std::string description;
259 private: boost::function<boost::any ()> updateFunc;
263 private:
typedef boost::variant<bool, char, std::string, int,