File: cpp03_define_array.hpp.erb

package info (click to toggle)
msgpack-cxx 7.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,520 kB
  • sloc: cpp: 87,413; ansic: 3,571; sh: 56; makefile: 39
file content (110 lines) | stat: -rw-r--r-- 3,352 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// 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_CPP03_DEFINE_ARRAY_HPP
#define MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP

#include "msgpack/v1/adaptor/detail/cpp03_define_array_decl.hpp"
#include "msgpack/adaptor/msgpack_tuple.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object_fwd.hpp"

namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
namespace type {

<% GENERATION_LIMIT = 31 %>
template <>
struct define_array<> {
    typedef define_array<> value_type;
    typedef 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 = MSGPACK_NULLPTR;
        o->via.array.size = 0;
    }
};

/// @cond
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
struct define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
    typedef define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
    typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> tuple_type;
    define_array(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) :
        a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
    template <typename Packer>
    void msgpack_pack(Packer& pk) const
    {
        pk.pack_array(<%=i+1%>);
        <%0.upto(i) {|j|%>
        pk.pack(a<%=j%>);<%}%>
    }
    void msgpack_unpack(msgpack::object const& o)
    {
        if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
        const size_t size = o.via.array.size;
        if(size > 0) {
            msgpack::object *ptr = o.via.array.ptr;
            switch(size) {
            default:<%(i).downto(0) {|j|%>
            case <%=j+1%>: ptr[<%=j%>].convert(a<%=j%>);
            // fallthrough
<%}%>
            }
        }
    }
    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)*<%=i+1%>, MSGPACK_ZONE_ALIGNOF(msgpack::object)));
        o->via.array.size = <%=i+1%>;
        <%0.upto(i) {|j|%>
        o->via.array.ptr[<%=j%>] = msgpack::object(a<%=j%>, z);<%}%>
    }
    <%0.upto(i) {|j|%>
    A<%=j%>& a<%=j%>;<%}%>
};
<%}%>
/// @endcond

inline define_array<> make_define_array()
{
    return define_array<>();
}

/// @cond
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
inline define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define_array(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>)
{
    return define_array<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
/// @endcond

}  // namespace type
/// @cond
}  // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
}  // namespace msgpack

#endif // MSGPACK_V1_CPP03_DEFINE_ARRAY_HPP