From 3d36ea61996d9d32f9c2572f33d8cbf3ac245022 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 16 Jun 2015 17:01:01 -0600 Subject: [PATCH 1/4] Add back CONSTEXPR for Type_Info --- include/chaiscript/dispatchkit/type_info.hpp | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 1db31be..81ec083 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -29,7 +29,7 @@ namespace chaiscript class Type_Info { public: - Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, + CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti) : m_type_info(t_ti), m_bare_type_info(t_bare_ti), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), @@ -38,7 +38,7 @@ namespace chaiscript { } - Type_Info() + CHAISCRIPT_CONSTEXPR Type_Info() : m_type_info(nullptr), m_bare_type_info(nullptr), m_is_const(false), m_is_reference(false), m_is_pointer(false), m_is_void(false), m_is_arithmetic(false), @@ -55,40 +55,40 @@ namespace chaiscript Type_Info& operator=(const Type_Info&) = default; - bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { return m_type_info < ti.m_type_info; } - bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { return ti.m_type_info == m_type_info || (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info); } - bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT { return m_type_info != nullptr && (*m_type_info) == ti; } - bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { return ti.m_bare_type_info == m_bare_type_info || (ti.m_bare_type_info && m_bare_type_info && *ti.m_bare_type_info == *m_bare_type_info); } - bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT { return m_bare_type_info != nullptr && (*m_bare_type_info) == ti; } - bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; } - bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } - bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } - bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } - bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef || m_bare_type_info == nullptr; } - bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } + CHAISCRIPT_CONSTEXPR bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; } + CHAISCRIPT_CONSTEXPR bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } + CHAISCRIPT_CONSTEXPR bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } + CHAISCRIPT_CONSTEXPR bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } + CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef || m_bare_type_info == nullptr; } + CHAISCRIPT_CONSTEXPR bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } std::string name() const { @@ -110,7 +110,7 @@ namespace chaiscript } } - const std::type_info *bare_type_info() const + CHAISCRIPT_CONSTEXPR const std::type_info *bare_type_info() const { return m_bare_type_info; } From 60a497b0a69240d5852bb8f46bfbcab514d34dc9 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 16 Jun 2015 17:09:07 -0600 Subject: [PATCH 2/4] Move to codecov --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 458ccd8..8fb7cca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ script: - if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug . ; fi - if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then make -j2 ; fi - make test - - if [ ${COVERAGE} = 1 ]; then coveralls -e "unittests/catch.hpp" -E ".*\.cpp" --gcov $GCOV --gcov-options '\-lp' ; fi + - if [ ${COVERAGE} = 1 ]; then bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -x $GCOV -a "-s `pwd`" ; fi after_script: - if [ ${CPPCHECK} = 1 ]; then contrib/codeanalysis/runcppcheck.sh ; fi From 0dcac05f2f80066208641360e5441451e8c2d4d2 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 18 Jun 2015 11:57:58 -0600 Subject: [PATCH 3/4] Add numeric support for wide characters --- .../chaiscript/dispatchkit/boxed_number.hpp | 351 ++++++++++-------- 1 file changed, 192 insertions(+), 159 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 15b4f8c..e1503da 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -59,6 +59,20 @@ namespace chaiscript class Boxed_Number { private: + enum class Common_Types { + t_int32, + t_double, + t_uint8, + t_int8, + t_uint16, + t_int16, + t_uint32, + t_uint64, + t_int64, + t_float, + t_long_double + }; + template static inline void check_divide_by_zero(T t, typename std::enable_if::value>::type* = nullptr) { @@ -74,6 +88,67 @@ namespace chaiscript { } + static CHAISCRIPT_CONSTEXPR Common_Types get_common_type(size_t t_size, bool t_signed) + { + return (t_size == 1 && t_signed)?(Common_Types::t_int8) + :(t_size == 1)?(Common_Types::t_uint8) + :(t_size == 2 && t_signed)?(Common_Types::t_int16) + :(t_size == 2)?(Common_Types::t_uint16) + :(t_size == 4 && t_signed)?(Common_Types::t_int32) + :(t_size == 4)?(Common_Types::t_uint32) + :(t_size == 8 && t_signed)?(Common_Types::t_int64) + :(Common_Types::t_uint64); + } + + static Common_Types get_common_type(const Boxed_Value &t_bv) + { + const Type_Info &inp_ = t_bv.get_type_info(); + + if (inp_ == typeid(int)) { + return get_common_type(sizeof(int), true); + } else if (inp_ == typeid(double)) { + return Common_Types::t_double; + } else if (inp_ == typeid(long double)) { + return Common_Types::t_long_double; + } else if (inp_ == typeid(float)) { + return Common_Types::t_float; + } else if (inp_ == typeid(char)) { + return get_common_type(sizeof(char), std::is_signed::value); + } else if (inp_ == typeid(unsigned char)) { + return get_common_type(sizeof(unsigned char), false); + } else if (inp_ == typeid(unsigned int)) { + return get_common_type(sizeof(unsigned int), false); + } else if (inp_ == typeid(long)) { + return get_common_type(sizeof(long), true); + } else if (inp_ == typeid(unsigned long)) { + return get_common_type(sizeof(unsigned long), false); + } else if (inp_ == typeid(std::int8_t)) { + return Common_Types::t_int8; + } else if (inp_ == typeid(std::int16_t)) { + return Common_Types::t_int16; + } else if (inp_ == typeid(std::int32_t)) { + return Common_Types::t_int32; + } else if (inp_ == typeid(std::int64_t)) { + return Common_Types::t_int64; + } else if (inp_ == typeid(std::uint8_t)) { + return Common_Types::t_uint8; + } else if (inp_ == typeid(std::uint16_t)) { + return Common_Types::t_uint16; + } else if (inp_ == typeid(std::uint32_t)) { + return Common_Types::t_uint32; + } else if (inp_ == typeid(std::uint64_t)) { + return Common_Types::t_uint64; + } else if (inp_ == typeid(wchar_t)) { + return get_common_type(sizeof(wchar_t), std::is_signed::value); + } else if (inp_ == typeid(char16_t)) { + return get_common_type(sizeof(char16_t), std::is_signed::value); + } else if (inp_ == typeid(char32_t)) { + return get_common_type(sizeof(char32_t), std::is_signed::value); + } else { + throw chaiscript::detail::exception::bad_any_cast(); + } + } + template static Boxed_Value boolean_go(Operators::Opers t_oper, const T &t, const T &u) { @@ -215,15 +290,15 @@ namespace chaiscript typedef typename std::common_type::type common_type; if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { - return boolean_go(t_oper, get_as_aux_impl(t_lhs), get_as_aux_impl(t_rhs)); + return boolean_go(t_oper, get_as_aux(t_lhs), get_as_aux(t_rhs)); } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { - return binary_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux_impl(t_rhs), t_lhs); + return binary_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux(t_rhs), t_lhs); } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { - return binary_int_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux_impl(t_rhs), t_lhs); + return binary_int_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux(t_rhs), t_lhs); } else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) { - return const_binary_int_go(t_oper, get_as_aux_impl(t_lhs), get_as_aux_impl(t_rhs)); + return const_binary_int_go(t_oper, get_as_aux(t_lhs), get_as_aux(t_rhs)); } else if (t_oper > Operators::const_flag) { - return const_binary_go(t_oper, get_as_aux_impl(t_lhs), get_as_aux_impl(t_rhs)); + return const_binary_go(t_oper, get_as_aux(t_lhs), get_as_aux(t_rhs)); } else { throw chaiscript::detail::exception::bad_any_cast(); } @@ -236,15 +311,15 @@ namespace chaiscript typedef typename std::common_type::type common_type; if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { - return boolean_go(t_oper, get_as_aux_impl(t_lhs), get_as_aux_impl(t_rhs)); + return boolean_go(t_oper, get_as_aux(t_lhs), get_as_aux(t_rhs)); } else if (t_oper > Operators::non_const_flag && t_oper < Operators::non_const_int_flag && !t_lhs.is_const() && !t_lhs.is_return_value()) { - return binary_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux_impl(t_rhs), t_lhs); + return binary_go(t_oper, *static_cast(t_lhs.get_ptr()), get_as_aux(t_rhs), t_lhs); } else if (t_oper > Operators::non_const_int_flag && t_oper < Operators::const_int_flag) { throw chaiscript::detail::exception::bad_any_cast(); } else if (t_oper > Operators::const_int_flag && t_oper < Operators::const_flag) { throw chaiscript::detail::exception::bad_any_cast(); } else if (t_oper > Operators::const_flag) { - return const_binary_go(t_oper, get_as_aux_impl(t_lhs), get_as_aux_impl(t_rhs)); + return const_binary_go(t_oper, get_as_aux(t_lhs), get_as_aux(t_rhs)); } else { throw chaiscript::detail::exception::bad_any_cast(); } @@ -253,94 +328,66 @@ namespace chaiscript template inline static Boxed_Value oper_rhs(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { - const auto &inp_ = t_rhs.get_type_info(); - - if (inp_ == typeid(int)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(double)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(float)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(long double)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(char)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(unsigned int)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(long)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(unsigned long)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int8_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int16_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int32_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int64_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint8_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint16_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint32_t)) { - return go(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint64_t)) { - return go(t_oper, t_lhs, t_rhs); - } else { - throw chaiscript::detail::exception::bad_any_cast(); + switch (get_common_type(t_rhs)) { + case Common_Types::t_int32: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint8: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_int8: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint16: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_int16: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint32: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint64: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_int64: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_double: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_float: + return go(t_oper, t_lhs, t_rhs); + case Common_Types::t_long_double: + return go(t_oper, t_lhs, t_rhs); } + + throw chaiscript::detail::exception::bad_any_cast(); } inline static Boxed_Value oper(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { - const Type_Info &inp_ = t_lhs.get_type_info(); - - if (inp_ == typeid(int)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(double)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(long double)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(float)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(char)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(unsigned int)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(long)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(unsigned long)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int8_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int32_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::int64_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint8_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint16_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint32_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else if (inp_ == typeid(std::uint64_t)) { - return oper_rhs(t_oper, t_lhs, t_rhs); - } else { - throw chaiscript::detail::exception::bad_any_cast(); + switch (get_common_type(t_lhs)) { + case Common_Types::t_int32: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint8: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_int8: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint16: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_int16: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint32: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_uint64: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_int64: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_double: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_float: + return oper_rhs(t_oper, t_lhs, t_rhs); + case Common_Types::t_long_double: + return oper_rhs(t_oper, t_lhs, t_rhs); } + + throw chaiscript::detail::exception::bad_any_cast(); } template - inline Target get_as_aux() const - { - return get_as_aux_impl(bv); - } - - template - static inline Target get_as_aux_impl(const Boxed_Value &t_bv) + static inline Target get_as_aux(const Boxed_Value &t_bv) { return static_cast(*static_cast(t_bv.get_const_ptr())); } @@ -390,6 +437,14 @@ namespace chaiscript return Boxed_Number(get_as()); } else if (inp_.bare_equal_type_info(typeid(char))) { return Boxed_Number(get_as()); + } else if (inp_.bare_equal_type_info(typeid(unsigned char))) { + return Boxed_Number(get_as()); + } else if (inp_.bare_equal_type_info(typeid(wchar_t))) { + return Boxed_Number(get_as()); + } else if (inp_.bare_equal_type_info(typeid(char16_t))) { + return Boxed_Number(get_as()); + } else if (inp_.bare_equal_type_info(typeid(char32_t))) { + return Boxed_Number(get_as()); } else if (inp_.bare_equal_type_info(typeid(unsigned int))) { return Boxed_Number(get_as()); } else if (inp_.bare_equal_type_info(typeid(long))) { @@ -420,84 +475,62 @@ namespace chaiscript template Target get_as() const { - const Type_Info &inp_ = bv.get_type_info(); - - if (inp_ == typeid(int)) { - return get_as_aux(); - } else if (inp_ == typeid(double)) { - return get_as_aux(); - } else if (inp_ == typeid(float)) { - return get_as_aux(); - } else if (inp_ == typeid(long double)) { - return get_as_aux(); - } else if (inp_ == typeid(char)) { - return get_as_aux(); - } else if (inp_ == typeid(unsigned int)) { - return get_as_aux(); - } else if (inp_ == typeid(long)) { - return get_as_aux(); - } else if (inp_ == typeid(unsigned long)) { - return get_as_aux(); - } else if (inp_ == typeid(std::int8_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::int16_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::int32_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::int64_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::uint8_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::uint16_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::uint32_t)) { - return get_as_aux(); - } else if (inp_ == typeid(std::uint64_t)) { - return get_as_aux(); - } else { - throw chaiscript::detail::exception::bad_any_cast(); + switch (get_common_type(bv)) { + case Common_Types::t_int32: + return get_as_aux(bv); + case Common_Types::t_uint8: + return get_as_aux(bv); + case Common_Types::t_int8: + return get_as_aux(bv); + case Common_Types::t_uint16: + return get_as_aux(bv); + case Common_Types::t_int16: + return get_as_aux(bv); + case Common_Types::t_uint32: + return get_as_aux(bv); + case Common_Types::t_uint64: + return get_as_aux(bv); + case Common_Types::t_int64: + return get_as_aux(bv); + case Common_Types::t_double: + return get_as_aux(bv); + case Common_Types::t_float: + return get_as_aux(bv); + case Common_Types::t_long_double: + return get_as_aux(bv); } + + throw chaiscript::detail::exception::bad_any_cast(); } std::string to_string() const { - const Type_Info &inp_ = bv.get_type_info(); - - if (inp_ == typeid(int)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(double)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(float)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(long double)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(char)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(unsigned int)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(long)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(unsigned long)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::int8_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::int16_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::int32_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::int64_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::uint8_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::uint16_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::uint32_t)) { - return std::to_string(get_as()); - } else if (inp_ == typeid(std::uint64_t)) { - return std::to_string(get_as()); - } else { - throw chaiscript::detail::exception::bad_any_cast(); + switch (get_common_type(bv)) { + case Common_Types::t_int32: + return std::to_string(get_as()); + case Common_Types::t_uint8: + return std::to_string(get_as()); + case Common_Types::t_int8: + return std::to_string(get_as()); + case Common_Types::t_uint16: + return std::to_string(get_as()); + case Common_Types::t_int16: + return std::to_string(get_as()); + case Common_Types::t_uint32: + return std::to_string(get_as()); + case Common_Types::t_uint64: + return std::to_string(get_as()); + case Common_Types::t_int64: + return std::to_string(get_as()); + case Common_Types::t_double: + return std::to_string(get_as()); + case Common_Types::t_float: + return std::to_string(get_as()); + case Common_Types::t_long_double: + return std::to_string(get_as()); } + + throw chaiscript::detail::exception::bad_any_cast(); } bool operator==(const Boxed_Number &t_rhs) const From 2442e9ae20c22b7943873483a4a5426ca5d070fd Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 18 Jun 2015 13:01:54 -0600 Subject: [PATCH 4/4] Register all character types --- include/chaiscript/dispatchkit/bootstrap.hpp | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 5dcc4a8..d6600f4 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -157,7 +157,12 @@ namespace chaiscript /// Internal function for converting from a string to a value /// uses ostream operator >> to perform the conversion template - Input parse_string(const std::string &i) + auto parse_string(const std::string &i) + -> typename std::enable_if< + !std::is_same::value + && !std::is_same::value + && !std::is_same::value, + Input>::type { std::stringstream ss(i); Input t; @@ -165,6 +170,17 @@ namespace chaiscript return t; } + template + auto parse_string(const std::string &) + -> typename std::enable_if< + std::is_same::value + || std::is_same::value + || std::is_same::value, + Input>::type + { + throw std::runtime_error("Parsing of wide characters is not yet supported"); + } + /// Add all common functions for a POD type. All operators, and /// common conversions @@ -486,6 +502,9 @@ namespace chaiscript bootstrap_pod_type("unsigned_long", m); bootstrap_pod_type("size_t", m); bootstrap_pod_type("char", m); + bootstrap_pod_type("wchar_t", m); + bootstrap_pod_type("char16_t", m); + bootstrap_pod_type("char32_t", m); bootstrap_pod_type("int8_t", m); bootstrap_pod_type("int16_t", m); bootstrap_pod_type("int32_t", m);