18 #ifndef SDFORMAT_PARAM_HH_
19 #define SDFORMAT_PARAM_HH_
23 #include <boost/any.hpp>
24 #include <boost/variant.hpp>
36 #include <ignition/math.hh>
46 #pragma warning(disable: 4251)
76 public:
Param(
const std::string &_key,
const std::string &_typeName,
77 const std::string &_default,
bool _required,
78 const std::string &_description =
"");
81 public:
virtual ~
Param();
85 public: std::string GetAsString()
const;
89 public: std::string GetDefaultAsString()
const;
93 public:
bool SetFromString(
const std::string &_value);
100 public:
const std::string &GetKey()
const;
105 public:
template<
typename Type>
110 public:
const std::string &GetTypeName()
const;
114 public:
bool GetRequired()
const;
118 public:
bool GetSet()
const;
127 public:
template<
typename T>
128 void SetUpdateFunc(T _updateFunc);
132 public:
void Update();
139 public:
template<
typename T>
140 bool Set(
const T &_value);
145 public:
bool GetAny(boost::any &_anyVal)
const;
151 public:
template<
typename T>
152 bool Get(T &_value)
const;
158 public:
template<
typename T>
159 bool GetDefault(T &_value)
const;
165 public:
Param &operator=(
const Param &_param);
169 public:
void SetDescription(
const std::string &_desc);
173 public: std::string GetDescription()
const;
188 private:
bool ValueFromString(
const std::string &_value);
191 private: std::unique_ptr<ParamPrivate> dataPtr;
218 public:
typedef boost::variant<bool, char, std::string, int, std::uint64_t,
220 ignition::math::Color,
221 ignition::math::Vector2i,
222 ignition::math::Vector2d,
223 ignition::math::Vector3d,
224 ignition::math::Quaterniond,
238 this->dataPtr->updateFunc = _updateFunc;
247 std::stringstream ss;
253 sdferr <<
"Unable to set parameter["
254 << this->dataPtr->key <<
"]."
255 <<
"Type used must have a stream input and output operator,"
256 <<
"which allows proper functioning of Param.\n";
267 if (
typeid(T) ==
typeid(
bool) && this->dataPtr->typeName ==
"string")
269 std::stringstream ss;
270 ss << this->dataPtr->value;
272 std::string strValue;
275 std::transform(strValue.begin(), strValue.end(),
276 strValue.begin(), ::tolower);
278 std::stringstream tmp;
279 if (strValue ==
"true" || strValue ==
"1")
289 else if (
typeid(T) == this->dataPtr->value.type())
291 #if BOOST_VERSION < 105800
292 _value = boost::get<T>(this->dataPtr->value);
294 _value = boost::relaxed_get<T>(this->dataPtr->value);
299 std::stringstream ss;
300 ss << this->dataPtr->value;
306 sdferr <<
"Unable to convert parameter["
307 << this->dataPtr->key <<
"] "
309 << this->dataPtr->typeName <<
"], to "
310 <<
"type[" <<
typeid(T).name() <<
"]\n";
320 std::stringstream ss;
324 ss << this->dataPtr->defaultValue;
329 sdferr <<
"Unable to convert parameter["
330 << this->dataPtr->key <<
"] "
332 << this->dataPtr->typeName <<
"], to "
333 <<
"type[" <<
typeid(T).name() <<
"]\n";
341 template<
typename Type>
344 return this->dataPtr->value.type() ==
typeid(Type);