1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/value.hpp"
8 #include <boost/lexical_cast.hpp>
14 * Utility class for converting types.
22 static long ToLong(const T& val)
25 return boost::lexical_cast<long>(val);
26 } catch (const std::exception&) {
27 std::ostringstream msgbuf;
28 msgbuf << "Can't convert '" << val << "' to an integer.";
29 BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
34 static double ToDouble(const T& val)
37 return boost::lexical_cast<double>(val);
38 } catch (const std::exception&) {
39 std::ostringstream msgbuf;
40 msgbuf << "Can't convert '" << val << "' to a floating point number.";
41 BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
45 static long ToLong(const Value& val)
50 static long ToLong(double val)
52 return static_cast<long>(val);
55 static double ToDouble(const Value& val)
60 static bool ToBool(const Value& val)
66 static String ToString(const T& val)
68 return boost::lexical_cast<std::string>(val);
71 static String ToString(const String& val);
72 static String ToString(const Value& val);
73 static String ToString(double val);
75 static double ToDateTimeValue(double val);
76 static double ToDateTimeValue(const Value& val);
84 #endif /* CONVERT_H */