18 #ifndef SDFORMAT_PARAM_HH_
19 #define SDFORMAT_PARAM_HH_
21 #include <boost/any.hpp>
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wc++98-c++11-compat"
26 #include <boost/variant.hpp>
28 #pragma clang diagnostic pop
41 #include <ignition/math.hh>
51 #pragma warning(disable: 4251)
81 public:
Param(
const std::string &_key,
const std::string &_typeName,
82 const std::string &_default,
bool _required,
83 const std::string &_description =
"");
86 public:
virtual ~
Param();
90 public: std::string GetAsString()
const;
94 public: std::string GetDefaultAsString()
const;
98 public:
bool SetFromString(
const std::string &_value);
101 public:
void Reset();
105 public:
const std::string &GetKey()
const;
110 public:
template<
typename Type>
115 public:
const std::string &GetTypeName()
const;
119 public:
bool GetRequired()
const;
123 public:
bool GetSet()
const;
132 public:
template<
typename T>
133 void SetUpdateFunc(T _updateFunc);
137 public:
void Update();
144 public:
template<
typename T>
145 bool Set(
const T &_value);
150 public:
bool GetAny(boost::any &_anyVal)
const;
156 public:
template<
typename T>
157 bool Get(T &_value)
const;
163 public:
template<
typename T>
164 bool GetDefault(T &_value)
const;
170 public:
Param &operator=(
const Param &_param);
174 public:
void SetDescription(
const std::string &_desc);
178 public: std::string GetDescription()
const;
193 private:
bool ValueFromString(
const std::string &_value);
196 private: std::unique_ptr<ParamPrivate> dataPtr;
223 public:
typedef boost::variant<bool, char, std::string, int, std::uint64_t,
225 ignition::math::Color,
226 ignition::math::Vector2i,
227 ignition::math::Vector2d,
228 ignition::math::Vector3d,
229 ignition::math::Quaterniond,
243 this->dataPtr->updateFunc = _updateFunc;
252 std::stringstream ss;
258 sdferr <<
"Unable to set parameter["
259 << this->dataPtr->key <<
"]."
260 <<
"Type used must have a stream input and output operator,"
261 <<
"which allows proper functioning of Param.\n";
272 if (
typeid(T) ==
typeid(
bool) && this->dataPtr->typeName ==
"string")
274 std::stringstream ss;
275 ss << this->dataPtr->value;
277 std::string strValue;
280 std::transform(strValue.begin(), strValue.end(), strValue.begin(),
283 return static_cast<unsigned char>(std::tolower(c));
286 std::stringstream tmp;
287 if (strValue ==
"true" || strValue ==
"1")
297 else if (
typeid(T) == this->dataPtr->value.type())
299 #if BOOST_VERSION < 105800
300 _value = boost::get<T>(this->dataPtr->value);
302 _value = boost::relaxed_get<T>(this->dataPtr->value);
307 std::stringstream ss;
308 ss << this->dataPtr->value;
314 sdferr <<
"Unable to convert parameter["
315 << this->dataPtr->key <<
"] "
317 << this->dataPtr->typeName <<
"], to "
318 <<
"type[" <<
typeid(T).name() <<
"]\n";
328 std::stringstream ss;
332 ss << this->dataPtr->defaultValue;
337 sdferr <<
"Unable to convert parameter["
338 << this->dataPtr->key <<
"] "
340 << this->dataPtr->typeName <<
"], to "
341 <<
"type[" <<
typeid(T).name() <<
"]\n";
349 template<
typename Type>
352 return this->dataPtr->value.type() ==
typeid(Type);