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));