// // MessagePack for C++ static resolution routine // // Copyright (C) 2008-2016 FURUHASHI Sadayuki // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef MSGPACK_V1_TYPE_INT_HPP #define MSGPACK_V1_TYPE_INT_HPP #include "rpc/msgpack/v1/adaptor/int_decl.hpp" #include "rpc/msgpack/object.hpp" #include namespace clmdep_msgpack { /// @cond MSGPACK_API_VERSION_NAMESPACE(v1){ /// @endcond namespace type { namespace detail { template struct convert_integer_sign { static T convert(clmdep_msgpack::object const& o) { if(o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { if(o.via.u64 > static_cast(std::numeric_limits::max())) { throw clmdep_msgpack::type_error(); } return static_cast(o.via.u64); } else if(o.type == clmdep_msgpack::type::NEGATIVE_INTEGER) { if(o.via.i64 < static_cast(std::numeric_limits::min())) { throw clmdep_msgpack::type_error(); } return static_cast(o.via.i64); } throw clmdep_msgpack::type_error(); } }; template struct convert_integer_sign { static T convert(clmdep_msgpack::object const& o) { if(o.type == clmdep_msgpack::type::POSITIVE_INTEGER) { if(o.via.u64 > static_cast(std::numeric_limits::max())) { throw clmdep_msgpack::type_error(); } return static_cast(o.via.u64); } throw clmdep_msgpack::type_error(); } }; template struct is_signed { static const bool value = std::numeric_limits::is_signed; }; template inline T convert_integer(clmdep_msgpack::object const& o) { return detail::convert_integer_sign::value>::convert(o); } template <> struct object_char_sign { template static typename clmdep_msgpack::enable_if::value>::type make(clmdep_msgpack::object& o, T v) { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else { o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object_char_sign { static void make(clmdep_msgpack::object& o, char v) { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; inline void object_char(clmdep_msgpack::object& o, char v) { return object_char_sign::value>::make(o, v); } } // namespace detail } // namespace type namespace adaptor { template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, char& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed char& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed short& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed int& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed long& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, signed long long& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned char& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned short& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned int& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned long& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct convert { clmdep_msgpack::object const& operator()(clmdep_msgpack::object const& o, unsigned long long& v) const { v = type::detail::convert_integer(o); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, char v) const { o.pack_char(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed char v) const { o.pack_signed_char(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed short v) const { o.pack_short(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed int v) const { o.pack_int(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed long v) const { o.pack_long(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, signed long long v) const { o.pack_long_long(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned char v) const { o.pack_unsigned_char(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned short v) const { o.pack_unsigned_short(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned int v) const { o.pack_unsigned_int(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned long v) const { o.pack_unsigned_long(v); return o; } }; template <> struct pack { template clmdep_msgpack::packer& operator()(clmdep_msgpack::packer& o, unsigned long long v) const { o.pack_unsigned_long_long(v); return o; } }; template <> struct object { void operator()(clmdep_msgpack::object& o, char v) const { type::detail::object_char(o, v); } }; template <> struct object { void operator()(clmdep_msgpack::object& o, signed char v) const { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else { o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object { void operator()(clmdep_msgpack::object& o, signed short v) const { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else { o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object { void operator()(clmdep_msgpack::object& o, signed int v) const { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else { o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object { void operator()(clmdep_msgpack::object& o, signed long v) const { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else { o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object { void operator()(clmdep_msgpack::object& o, signed long long v) const { if (v < 0) { o.type = clmdep_msgpack::type::NEGATIVE_INTEGER; o.via.i64 = v; } else{ o.type = clmdep_msgpack::type::POSITIVE_INTEGER; o.via.u64 = v; } } }; template <> struct object { void operator()(clmdep_msgpack::object& o, unsigned char v) const { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; template <> struct object { void operator()(clmdep_msgpack::object& o, unsigned short v) const { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; template <> struct object { void operator()(clmdep_msgpack::object& o, unsigned int v) const { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; template <> struct object { void operator()(clmdep_msgpack::object& o, unsigned long v) const { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; template <> struct object { void operator()(clmdep_msgpack::object& o, unsigned long long v) const { o.type = clmdep_msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, char v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, signed char v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, signed short v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, signed int v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, signed long v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, const signed long long& v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, unsigned char v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, unsigned short v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, unsigned int v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, unsigned long v) const { static_cast(o) << v; } }; template <> struct object_with_zone { void operator()(clmdep_msgpack::object::with_zone& o, const unsigned long long& v) const { static_cast(o) << v; } }; } // namespace adaptor /// @cond } // MSGPACK_API_VERSION_NAMESPACE(v1) /// @endcond } // namespace clmdep_msgpack #endif // MSGPACK_V1_TYPE_INT_HPP