cpp11_define_array.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
//
// 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_CPP11_DEFINE_ARRAY_HPP
#define MSGPACK_V1_CPP11_DEFINE_ARRAY_HPP
#include "msgpack/v1/adaptor/detail/cpp11_define_array_decl.hpp"
#include <tuple>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename Tuple, std::size_t N>
struct define_array_imp {
template <typename Packer>
static void pack(Packer& pk, Tuple const& t) {
define_array_imp<Tuple, N-1>::pack(pk, t);
pk.pack(std::get<N-1>(t));
}
static void unpack(msgpack::object const& o, Tuple& t) {
define_array_imp<Tuple, N-1>::unpack(o, t);
const size_t size = o.via.array.size;
if(size <= N-1) { return; }
o.via.array.ptr[N-1].convert(std::get<N-1>(t));
}
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
define_array_imp<Tuple, N-1>::object(o, z, t);
o->via.array.ptr[N-1] = msgpack::object(std::get<N-1>(t), z);
}
};
template <typename Tuple>
struct define_array_imp<Tuple, 1> {
template <typename Packer>
static void pack(Packer& pk, Tuple const& t) {
pk.pack(std::get<0>(t));
}
static void unpack(msgpack::object const& o, Tuple& t) {
const size_t size = o.via.array.size;
if(size <= 0) { return; }
o.via.array.ptr[0].convert(std::get<0>(t));
}
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
o->via.array.ptr[0] = msgpack::object(std::get<0>(t), z);
}
};
template <typename... Args>
struct define_array {
typedef define_array<Args...> value_type;
typedef std::tuple<Args...> tuple_type;
define_array(Args&... args) :
a(args...) {}
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(sizeof...(Args));
define_array_imp<std::tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
define_array_imp<std::tuple<Args&...>, sizeof...(Args)>::unpack(o, a);
}
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
{
o->type = msgpack::type::ARRAY;
o->via.array.ptr = static_cast<msgpack::object*>(z.allocate_align(sizeof(msgpack::object)*sizeof...(Args), MSGPACK_ZONE_ALIGNOF(msgpack::object)));
o->via.array.size = sizeof...(Args);
define_array_imp<std::tuple<Args&...>, sizeof...(Args)>::object(o, z, a);
}
std::tuple<Args&...> a;
};
template <>
struct define_array<> {
typedef define_array<> value_type;
typedef std::tuple<> tuple_type;
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(0);
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
}
void msgpack_object(msgpack::object* o, msgpack::zone&) const
{
o->type = msgpack::type::ARRAY;
o->via.array.ptr = NULL;
o->via.array.size = 0;
}
};
inline define_array<> make_define_array()
{
return define_array<>();
}
template <typename... Args>
inline define_array<Args...> make_define_array(Args&... args)
{
return define_array<Args...>(args...);
}
} // namespace type
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_CPP11_DEFINE_ARRAY_HPP
msgpack::type::make_define_array
define_array make_define_array()
Definition: cpp03_define_array.hpp:4274
msgpack::type::define_array::value_type
define_array< Args... > value_type
Definition: cpp11_define_array.hpp:60
msgpack::object_array::size
uint32_t size
Definition: object_fwd.hpp:23
msgpack::zone::allocate_align
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition: cpp03_zone.hpp:246
msgpack::type::define_array_imp::unpack
static void unpack(msgpack::object const &o, Tuple &t)
Definition: cpp11_define_array.hpp:30
msgpack::type::define_array<>::msgpack_object
void msgpack_object(msgpack::object *o, msgpack::zone &) const
Definition: cpp11_define_array.hpp:102
msgpack::type::define_array<>::tuple_type
std::tuple tuple_type
Definition: cpp11_define_array.hpp:92
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::type::define_array::msgpack_pack
void msgpack_pack(Packer &pk) const
Definition: cpp11_define_array.hpp:65
msgpack::type::define_array_imp
Definition: cpp11_define_array.hpp:24
msgpack::type::define_array<>::msgpack_unpack
void msgpack_unpack(msgpack::object const &o)
Definition: cpp11_define_array.hpp:98
msgpack::type::define_array_imp::object
static void object(msgpack::object *o, msgpack::zone &z, Tuple const &t)
Definition: cpp11_define_array.hpp:36
msgpack::type::define_array
Definition: cpp11_define_array.hpp:59
msgpack::type::define_array_imp< Tuple, 1 >::object
static void object(msgpack::object *o, msgpack::zone &z, Tuple const &t)
Definition: cpp11_define_array.hpp:53
msgpack::object_array::ptr
msgpack::object * ptr
Definition: object_fwd.hpp:24
msgpack::type::define_array_imp::pack
static void pack(Packer &pk, Tuple const &t)
Definition: cpp11_define_array.hpp:26
msgpack
Definition: adaptor_base.hpp:15
msgpack::zone
Definition: cpp03_zone.hpp:22
cpp11_define_array_decl.hpp
msgpack::type::define_array<>::msgpack_pack
void msgpack_pack(Packer &pk) const
Definition: cpp11_define_array.hpp:94
msgpack::type_error
Definition: object_fwd.hpp:236
msgpack::type::define_array_imp< Tuple, 1 >::pack
static void pack(Packer &pk, Tuple const &t)
Definition: cpp11_define_array.hpp:45
msgpack::type::size
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
msgpack::type::define_array::define_array
define_array(Args &... args)
Definition: cpp11_define_array.hpp:62
msgpack::object::union_type::array
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::type::define_array::a
std::tuple< Args &... > a
Definition: cpp11_define_array.hpp:86
msgpack::type::define_array::msgpack_unpack
void msgpack_unpack(msgpack::object const &o)
Definition: cpp11_define_array.hpp:71
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
msgpack::type::define_array::msgpack_object
void msgpack_object(msgpack::object *o, msgpack::zone &z) const
Definition: cpp11_define_array.hpp:77
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::type::ARRAY
Definition: object_fwd_decl.hpp:41
msgpack::type::define_array::tuple_type
std::tuple< Args... > tuple_type
Definition: cpp11_define_array.hpp:61
msgpack::type::define_array_imp< Tuple, 1 >::unpack
static void unpack(msgpack::object const &o, Tuple &t)
Definition: cpp11_define_array.hpp:48
MSGPACK_ZONE_ALIGNOF
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
msgpack::object::convert
msgpack::enable_if< !msgpack::is_array< T >::value &&!msgpack::is_pointer< T >::value, T &>::type convert(T &v) const
Convert the object.
Definition: object.hpp:543
msgpack::type::define_array<>::value_type
define_array value_type
Definition: cpp11_define_array.hpp:91
msgpack::type::define_array<>
Definition: cpp03_define_array.hpp:26