int.hpp
Go to the documentation of this file.
//
// 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 "msgpack/v1/adaptor/int_decl.hpp"
#include "msgpack/object.hpp"
#include <limits>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1){
namespace type {
namespace detail {
template <typename T>
struct convert_integer_sign<T, true> {
static T convert(msgpack::object const& o) {
if(o.type == msgpack::type::POSITIVE_INTEGER) {
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
{ throw msgpack::type_error(); }
return static_cast<T>(o.via.u64);
} else if(o.type == msgpack::type::NEGATIVE_INTEGER) {
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
{ throw msgpack::type_error(); }
return static_cast<T>(o.via.i64);
}
throw msgpack::type_error();
}
};
template <typename T>
struct convert_integer_sign<T, false> {
static T convert(msgpack::object const& o) {
if(o.type == msgpack::type::POSITIVE_INTEGER) {
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
{ throw msgpack::type_error(); }
return static_cast<T>(o.via.u64);
}
throw msgpack::type_error();
}
};
template <typename T>
struct is_signed {
static const bool value = std::numeric_limits<T>::is_signed;
};
template <typename T>
inline T convert_integer(msgpack::object const& o)
{
return detail::convert_integer_sign<T, is_signed<T>::value>::convert(o);
}
template <>
struct object_char_sign<true> {
template <typename T>
static typename msgpack::enable_if<msgpack::is_same<T, char>::value>::type
make(msgpack::object& o, T v) {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else {
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object_char_sign<false> {
static void make(msgpack::object& o, char v) {
o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v;
}
};
inline void object_char(msgpack::object& o, char v) {
return object_char_sign<is_signed<char>::value>::make(o, v);
}
} // namespace detail
} // namespace type
namespace adaptor {
template <>
struct convert<char> {
msgpack::object const& operator()(msgpack::object const& o, char& v) const
{ v = type::detail::convert_integer<char>(o); return o; }
};
template <>
struct convert<signed char> {
msgpack::object const& operator()(msgpack::object const& o, signed char& v) const
{ v = type::detail::convert_integer<signed char>(o); return o; }
};
template <>
struct convert<signed short> {
msgpack::object const& operator()(msgpack::object const& o, signed short& v) const
{ v = type::detail::convert_integer<signed short>(o); return o; }
};
template <>
struct convert<signed int> {
msgpack::object const& operator()(msgpack::object const& o, signed int& v) const
{ v = type::detail::convert_integer<signed int>(o); return o; }
};
template <>
struct convert<signed long> {
msgpack::object const& operator()(msgpack::object const& o, signed long& v) const
{ v = type::detail::convert_integer<signed long>(o); return o; }
};
template <>
struct convert<signed long long> {
msgpack::object const& operator()(msgpack::object const& o, signed long long& v) const
{ v = type::detail::convert_integer<signed long long>(o); return o; }
};
template <>
struct convert<unsigned char> {
msgpack::object const& operator()(msgpack::object const& o, unsigned char& v) const
{ v = type::detail::convert_integer<unsigned char>(o); return o; }
};
template <>
struct convert<unsigned short> {
msgpack::object const& operator()(msgpack::object const& o, unsigned short& v) const
{ v = type::detail::convert_integer<unsigned short>(o); return o; }
};
template <>
struct convert<unsigned int> {
msgpack::object const& operator()(msgpack::object const& o, unsigned int& v) const
{ v = type::detail::convert_integer<unsigned int>(o); return o; }
};
template <>
struct convert<unsigned long> {
msgpack::object const& operator()(msgpack::object const& o, unsigned long& v) const
{ v = type::detail::convert_integer<unsigned long>(o); return o; }
};
template <>
struct convert<unsigned long long> {
msgpack::object const& operator()(msgpack::object const& o, unsigned long long& v) const
{ v = type::detail::convert_integer<unsigned long long>(o); return o; }
};
template <>
struct pack<char> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, char v) const
{ o.pack_char(v); return o; }
};
template <>
struct pack<signed char> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed char v) const
{ o.pack_signed_char(v); return o; }
};
template <>
struct pack<signed short> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed short v) const
{ o.pack_short(v); return o; }
};
template <>
struct pack<signed int> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed int v) const
{ o.pack_int(v); return o; }
};
template <>
struct pack<signed long> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long v) const
{ o.pack_long(v); return o; }
};
template <>
struct pack<signed long long> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long long v) const
{ o.pack_long_long(v); return o; }
};
template <>
struct pack<unsigned char> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned char v) const
{ o.pack_unsigned_char(v); return o; }
};
template <>
struct pack<unsigned short> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned short v) const
{ o.pack_unsigned_short(v); return o; }
};
template <>
struct pack<unsigned int> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned int v) const
{ o.pack_unsigned_int(v); return o; }
};
template <>
struct pack<unsigned long> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long v) const
{ o.pack_unsigned_long(v); return o; }
};
template <>
struct pack<unsigned long long> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long long v) const
{ o.pack_unsigned_long_long(v); return o; }
};
template <>
struct object<char> {
void operator()(msgpack::object& o, char v) const
{ type::detail::object_char(o, v); }
};
template <>
struct object<signed char> {
void operator()(msgpack::object& o, signed char v) const {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else {
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object<signed short> {
void operator()(msgpack::object& o, signed short v) const {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else {
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object<signed int> {
void operator()(msgpack::object& o, signed int v) const {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else {
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object<signed long> {
void operator()(msgpack::object& o, signed long v) const {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else {
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object<signed long long> {
void operator()(msgpack::object& o, signed long long v) const {
if (v < 0) {
o.type = msgpack::type::NEGATIVE_INTEGER;
o.via.i64 = v;
}
else{
o.type = msgpack::type::POSITIVE_INTEGER;
o.via.u64 = v;
}
}
};
template <>
struct object<unsigned char> {
void operator()(msgpack::object& o, unsigned char v) const
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
};
template <>
struct object<unsigned short> {
void operator()(msgpack::object& o, unsigned short v) const
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
};
template <>
struct object<unsigned int> {
void operator()(msgpack::object& o, unsigned int v) const
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
};
template <>
struct object<unsigned long> {
void operator()(msgpack::object& o, unsigned long v) const
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
};
template <>
struct object<unsigned long long> {
void operator()(msgpack::object& o, unsigned long long v) const
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
};
template <>
struct object_with_zone<char> {
void operator()(msgpack::object::with_zone& o, char v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<signed char> {
void operator()(msgpack::object::with_zone& o, signed char v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<signed short> {
void operator()(msgpack::object::with_zone& o, signed short v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<signed int> {
void operator()(msgpack::object::with_zone& o, signed int v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<signed long> {
void operator()(msgpack::object::with_zone& o, signed long v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<signed long long> {
void operator()(msgpack::object::with_zone& o, const signed long long& v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<unsigned char> {
void operator()(msgpack::object::with_zone& o, unsigned char v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<unsigned short> {
void operator()(msgpack::object::with_zone& o, unsigned short v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<unsigned int> {
void operator()(msgpack::object::with_zone& o, unsigned int v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<unsigned long> {
void operator()(msgpack::object::with_zone& o, unsigned long v) const
{ static_cast<msgpack::object&>(o) << v; }
};
template <>
struct object_with_zone<unsigned long long> {
void operator()(msgpack::object::with_zone& o, const unsigned long long& v) const
{ static_cast<msgpack::object&>(o) << v; }
};
} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_INT_HPP
msgpack::adaptor::object< unsigned short >::operator()
void operator()(msgpack::object &o, unsigned short v) const
Definition: int.hpp:329
msgpack::adaptor::convert< unsigned char >::operator()
msgpack::object const & operator()(msgpack::object const &o, unsigned char &v) const
Definition: int.hpp:137
msgpack::type::detail::object_char_sign< true >::make
static msgpack::enable_if< msgpack::is_same< T, char >::value >::type make(msgpack::object &o, T v)
Definition: int.hpp:70
msgpack::adaptor::object_with_zone< unsigned long >::operator()
void operator()(msgpack::object::with_zone &o, unsigned long v) const
Definition: int.hpp:408
msgpack::adaptor::object_with_zone< signed long long >::operator()
void operator()(msgpack::object::with_zone &o, const signed long long &v) const
Definition: int.hpp:384
msgpack::packer::pack_char
packer< Stream > & pack_char(char d)
Packing char.
Definition: pack.hpp:809
msgpack::adaptor::pack< unsigned long long >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, unsigned long long v) const
Definition: int.hpp:240
msgpack::packer::pack_long_long
packer< Stream > & pack_long_long(long long d)
Packing long long.
Definition: pack.hpp:930
msgpack::adaptor::pack< unsigned short >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, unsigned short v) const
Definition: int.hpp:219
msgpack::adaptor::object< unsigned long long >::operator()
void operator()(msgpack::object &o, unsigned long long v) const
Definition: int.hpp:347
msgpack::adaptor::object_with_zone< unsigned int >::operator()
void operator()(msgpack::object::with_zone &o, unsigned int v) const
Definition: int.hpp:402
msgpack::adaptor::object< signed int >::operator()
void operator()(msgpack::object &o, signed int v) const
Definition: int.hpp:281
msgpack::packer::pack_unsigned_int
packer< Stream > & pack_unsigned_int(unsigned int d)
Packing unsigned int.
Definition: pack.hpp:1004
msgpack::adaptor::convert< signed long >::operator()
msgpack::object const & operator()(msgpack::object const &o, signed long &v) const
Definition: int.hpp:124
msgpack::adaptor::convert< char >::operator()
msgpack::object const & operator()(msgpack::object const &o, char &v) const
Definition: int.hpp:100
msgpack::adaptor::object< char >::operator()
void operator()(msgpack::object &o, char v) const
Definition: int.hpp:247
msgpack::packer::pack_short
packer< Stream > & pack_short(short d)
Packing short.
Definition: pack.hpp:831
msgpack::adaptor::convert< signed long long >::operator()
msgpack::object const & operator()(msgpack::object const &o, signed long long &v) const
Definition: int.hpp:130
msgpack::adaptor::object< signed short >::operator()
void operator()(msgpack::object &o, signed short v) const
Definition: int.hpp:267
msgpack::adaptor::pack< unsigned char >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, unsigned char v) const
Definition: int.hpp:212
msgpack::adaptor::convert< signed char >::operator()
msgpack::object const & operator()(msgpack::object const &o, signed char &v) const
Definition: int.hpp:106
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::type::detail::object_char_sign< false >::make
static void make(msgpack::object &o, char v)
Definition: int.hpp:84
object.hpp
msgpack::adaptor::pack< signed char >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, signed char v) const
Definition: int.hpp:176
msgpack::packer::pack_long
packer< Stream > & pack_long(long d)
Packing long.
Definition: pack.hpp:897
msgpack::adaptor::object_with_zone< char >::operator()
void operator()(msgpack::object::with_zone &o, char v) const
Definition: int.hpp:354
msgpack
Definition: adaptor_base.hpp:15
msgpack::adaptor::pack< signed long >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, signed long v) const
Definition: int.hpp:197
msgpack::adaptor::convert< unsigned short >::operator()
msgpack::object const & operator()(msgpack::object const &o, unsigned short &v) const
Definition: int.hpp:143
msgpack::adaptor::object_with_zone< signed char >::operator()
void operator()(msgpack::object::with_zone &o, signed char v) const
Definition: int.hpp:360
msgpack::adaptor::object_with_zone< signed short >::operator()
void operator()(msgpack::object::with_zone &o, signed short v) const
Definition: int.hpp:366
msgpack::convert
void convert(T &v, msgpack::object const &o)
Definition: object.hpp:666
msgpack::object::with_zone
Definition: object.hpp:34
msgpack::adaptor::object_with_zone< unsigned short >::operator()
void operator()(msgpack::object::with_zone &o, unsigned short v) const
Definition: int.hpp:396
msgpack::adaptor::pack< signed long long >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, signed long long v) const
Definition: int.hpp:204
msgpack::object::union_type::i64
int64_t i64
Definition: object_fwd.hpp:79
msgpack::type::NEGATIVE_INTEGER
Definition: object_fwd_decl.hpp:32
msgpack::adaptor::object_with_zone
Definition: adaptor_base.hpp:43
msgpack::type::detail::is_signed
Definition: int.hpp:56
msgpack::adaptor::object_with_zone< unsigned long long >::operator()
void operator()(msgpack::object::with_zone &o, const unsigned long long &v) const
Definition: int.hpp:414
msgpack::type::detail::object_char
void object_char(msgpack::object &o, char v)
Definition: int.hpp:89
msgpack::adaptor::object< signed long >::operator()
void operator()(msgpack::object &o, signed long v) const
Definition: int.hpp:295
msgpack::adaptor::convert< signed short >::operator()
msgpack::object const & operator()(msgpack::object const &o, signed short &v) const
Definition: int.hpp:112
msgpack::type_error
Definition: object_fwd.hpp:236
msgpack::adaptor::object< signed long long >::operator()
void operator()(msgpack::object &o, signed long long v) const
Definition: int.hpp:309
msgpack::adaptor::pack
Definition: adaptor_base.hpp:32
msgpack::adaptor::pack< signed int >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, signed int v) const
Definition: int.hpp:190
msgpack::adaptor::object_with_zone< signed int >::operator()
void operator()(msgpack::object::with_zone &o, signed int v) const
Definition: int.hpp:372
msgpack::type::detail::convert_integer_sign< T, true >::convert
static T convert(msgpack::object const &o)
Definition: int.hpp:29
msgpack::packer::pack_unsigned_short
packer< Stream > & pack_unsigned_short(unsigned short d)
Packing unsigned short.
Definition: pack.hpp:971
msgpack::adaptor::pack< char >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, char v) const
Definition: int.hpp:169
msgpack::adaptor::object_with_zone< unsigned char >::operator()
void operator()(msgpack::object::with_zone &o, unsigned char v) const
Definition: int.hpp:390
msgpack::enable_if
Definition: cpp_config_decl.hpp:56
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::adaptor::convert< unsigned long long >::operator()
msgpack::object const & operator()(msgpack::object const &o, unsigned long long &v) const
Definition: int.hpp:161
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::adaptor::pack< unsigned int >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, unsigned int v) const
Definition: int.hpp:226
msgpack::type::detail::convert_integer
T convert_integer(msgpack::object const &o)
Definition: int.hpp:61
msgpack::adaptor::object< signed char >::operator()
void operator()(msgpack::object &o, signed char v) const
Definition: int.hpp:253
msgpack::adaptor::object< unsigned char >::operator()
void operator()(msgpack::object &o, unsigned char v) const
Definition: int.hpp:323
msgpack::adaptor::object< unsigned int >::operator()
void operator()(msgpack::object &o, unsigned int v) const
Definition: int.hpp:335
msgpack::adaptor::object_with_zone< signed long >::operator()
void operator()(msgpack::object::with_zone &o, signed long v) const
Definition: int.hpp:378
msgpack::type::detail::convert_integer_sign< T, false >::convert
static T convert(msgpack::object const &o)
Definition: int.hpp:45
msgpack::adaptor::object
Definition: adaptor_base.hpp:38
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
msgpack::adaptor::convert< unsigned long >::operator()
msgpack::object const & operator()(msgpack::object const &o, unsigned long &v) const
Definition: int.hpp:155
msgpack::type::detail::convert_integer_sign
Definition: int_decl.hpp:27
int_decl.hpp
msgpack::packer::pack_signed_char
packer< Stream > & pack_signed_char(signed char d)
Packing signed char.
Definition: pack.hpp:824
msgpack::adaptor::convert< signed int >::operator()
msgpack::object const & operator()(msgpack::object const &o, signed int &v) const
Definition: int.hpp:118
msgpack::adaptor::convert< unsigned int >::operator()
msgpack::object const & operator()(msgpack::object const &o, unsigned int &v) const
Definition: int.hpp:149
msgpack::adaptor::object< unsigned long >::operator()
void operator()(msgpack::object &o, unsigned long v) const
Definition: int.hpp:341
msgpack::adaptor::convert
Definition: adaptor_base.hpp:27
msgpack::packer::pack_unsigned_long
packer< Stream > & pack_unsigned_long(unsigned long d)
Packing unsigned long.
Definition: pack.hpp:1037
msgpack::packer::pack_unsigned_long_long
packer< Stream > & pack_unsigned_long_long(unsigned long long d)
Packing unsigned long long.
Definition: pack.hpp:1070
msgpack::packer::pack_int
packer< Stream > & pack_int(int d)
Packing int.
Definition: pack.hpp:864
msgpack::type::detail::object_char_sign
Definition: int_decl.hpp:36
msgpack::adaptor::pack< unsigned long >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, unsigned long v) const
Definition: int.hpp:233
msgpack::type::POSITIVE_INTEGER
Definition: object_fwd_decl.hpp:31
msgpack::adaptor::pack< signed short >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, signed short v) const
Definition: int.hpp:183
msgpack::object::union_type::u64
uint64_t u64
Definition: object_fwd.hpp:78
msgpack::packer::pack_unsigned_char
packer< Stream > & pack_unsigned_char(unsigned char d)
Packing unsigned char.
Definition: pack.hpp:964