From f8feaf6ea867aec5c3118bd504ef043f0a47c248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gro=C3=9F?= Date: Fri, 29 Jun 2012 16:48:53 +0200 Subject: [PATCH] Add toString function to Boxed_Number. For uint8_t, int8_t and char the value is first converted to an appropriate int type. This way the value is converted to a number rather than a character. --- .../chaiscript/dispatchkit/boxed_number.hpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index ccb93d1..4a2f94e 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -305,6 +305,14 @@ namespace chaiscript return static_cast(*static_cast(bv.get_const_ptr())); } + template + std::string toStringAux(const Boxed_Value &v) + { + std::ostringstream oss; + oss << *static_cast(v.get_const_ptr()); + return oss.str(); + } + public: Boxed_Number() @@ -365,6 +373,47 @@ namespace chaiscript } } + std::string toString() + { + const Type_Info &inp_ = bv.get_type_info(); + + if (inp_ == typeid(int)) { + return toStringAux(bv); + } else if (inp_ == typeid(double)) { + return toStringAux(bv); + } else if (inp_ == typeid(float)) { + return toStringAux(bv); + } else if (inp_ == typeid(long double)) { + return toStringAux(bv); + } else if (inp_ == typeid(char)) { + return toStringAux(Boxed_Value(getAsAux())); + } else if (inp_ == typeid(unsigned int)) { + return toStringAux(bv); + } else if (inp_ == typeid(long)) { + return toStringAux(bv); + } else if (inp_ == typeid(unsigned long)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::int8_t)) { + return toStringAux(Boxed_Value(getAsAux())); + } else if (inp_ == typeid(boost::int16_t)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::int32_t)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::int64_t)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::uint8_t)) { + return toStringAux(Boxed_Value(getAsAux())); + } else if (inp_ == typeid(boost::uint16_t)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::uint32_t)) { + return toStringAux(bv); + } else if (inp_ == typeid(boost::uint64_t)) { + return toStringAux(bv); + } else { + throw boost::bad_any_cast(); + } + } + bool operator==(const Boxed_Number &t_rhs) const { return boxed_cast(oper(Operators::equals, this->bv, t_rhs.bv));