MessagePack for C++
Loading...
Searching...
No Matches
list.hpp
Go to the documentation of this file.
1//
2// MessagePack for C++ static resolution routine
3//
4// Copyright (C) 2008-2015 FURUHASHI Sadayuki
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10#ifndef MSGPACK_V1_TYPE_LIST_HPP
11#define MSGPACK_V1_TYPE_LIST_HPP
12
15#include "msgpack/object.hpp"
17
18#include <list>
19
20namespace msgpack {
21
25
26namespace adaptor {
27
28#if !defined(MSGPACK_USE_CPP03)
29
30template <typename T, typename Alloc>
31struct as<std::list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
32 std::list<T, Alloc> operator()(msgpack::object const& o) const {
33 if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
34 std::list<T, Alloc> v;
36 msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
37 for (; p < pend; ++p) {
38 v.push_back(p->as<T>());
39 }
40 return v;
41 }
42};
43
44#endif // !defined(MSGPACK_USE_CPP03)
45
46template <typename T, typename Alloc>
47struct convert<std::list<T, Alloc> > {
48 msgpack::object const& operator()(msgpack::object const& o, std::list<T, Alloc>& v) const {
49 if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
50 v.resize(o.via.array.size);
52 msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
53 typename std::list<T, Alloc>::iterator it = v.begin();
54 for (; p < pend; ++p, ++it) {
55 p->convert(*it);
56 }
57 return o;
58 }
59};
60
61template <typename T, typename Alloc>
62struct pack<std::list<T, Alloc> > {
63 template <typename Stream>
64 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::list<T, Alloc>& v) const {
65 uint32_t size = checked_get_container_size(v.size());
66 o.pack_array(size);
67 for (typename std::list<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
68 it != it_end; ++it) {
69 o.pack(*it);
70 }
71 return o;
72 }
73};
74
75template <typename T, typename Alloc>
76struct object_with_zone<std::list<T, Alloc> > {
77 void operator()(msgpack::object::with_zone& o, const std::list<T, Alloc>& v) const {
78 o.type = msgpack::type::ARRAY;
79 if (v.empty()) {
81 o.via.array.size = 0;
82 }
83 else {
84 uint32_t size = checked_get_container_size(v.size());
86 msgpack::object* const pend = p + size;
87 o.via.array.ptr = p;
88 o.via.array.size = size;
89 typename std::list<T, Alloc>::const_iterator it(v.begin());
90 do {
91 *p = msgpack::object(*it, o.zone);
92 ++p;
93 ++it;
94 } while(p < pend);
95 }
96 }
97};
98
99} // namespace adaptor
100
102} // MSGPACK_API_VERSION_NAMESPACE(v1)
104
105} // namespace msgpack
106
107#endif // MSGPACK_V1_TYPE_LIST_HPP
The class template that supports continuous packing.
Definition pack.hpp:33
packer< Stream > & pack_array(uint32_t n)
Packing array header and size.
Definition pack.hpp:1195
packer< Stream > & pack(const T &v)
Packing function template.
Definition object_fwd.hpp:231
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition cpp03_zone.hpp:255
Definition adaptor_base.hpp:15
uint32_t checked_get_container_size(T size)
Definition check_container_size.hpp:55
std::list< T, Alloc > operator()(msgpack::object const &o) const
Definition list.hpp:32
Definition object_fwd_decl.hpp:61
msgpack::object const & operator()(msgpack::object const &o, std::list< T, Alloc > &v) const
Definition list.hpp:48
Definition adaptor_base.hpp:27
void operator()(msgpack::object::with_zone &o, const std::list< T, Alloc > &v) const
Definition list.hpp:77
Definition adaptor_base.hpp:43
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const std::list< T, Alloc > &v) const
Definition list.hpp:64
Definition adaptor_base.hpp:32
Definition object.hpp:35
msgpack::zone & zone
Definition object.hpp:37
uint32_t size
Definition object_fwd.hpp:23
msgpack::object * ptr
Definition object_fwd.hpp:24
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:75
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:1076
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition object.hpp:1126
union_type via
Definition object_fwd.hpp:93
msgpack::type::object_type type
Definition object_fwd.hpp:92
msgpack::object_array array
Definition object_fwd.hpp:85
#define MSGPACK_NULLPTR
Definition cpp_config_decl.hpp:85
#define MSGPACK_ZONE_ALIGNOF(type)
Definition cpp03_zone_decl.hpp:30
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66