MessagePack for C++
Loading...
Searching...
No Matches
vector_bool.hpp
Go to the documentation of this file.
1//
2// MessagePack for C++ static resolution routine
3//
4// Copyright (C) 2015 KONDO Takatoshi
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_VECTOR_BOOL_HPP
11#define MSGPACK_V1_TYPE_VECTOR_BOOL_HPP
12
16
17#include <vector>
18
19namespace msgpack {
20
24
25namespace adaptor {
26
27template <typename Alloc>
28struct convert<std::vector<bool, Alloc> > {
29 msgpack::object const& operator()(msgpack::object const& o, std::vector<bool, Alloc>& v) const {
30 if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
31 if (o.via.array.size > 0) {
32 v.resize(o.via.array.size);
34 for (typename std::vector<bool, Alloc>::iterator it = v.begin(), end = v.end();
35 it != end;
36 ++it) {
37 *it = p->as<bool>();
38 ++p;
39 }
40 }
41 return o;
42 }
43};
44
45template <typename Alloc>
46struct pack<std::vector<bool, Alloc> > {
47 template <typename Stream>
48 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<bool, Alloc>& v) const {
49 uint32_t size = checked_get_container_size(v.size());
50 o.pack_array(size);
51 for(typename std::vector<bool, Alloc>::const_iterator it(v.begin()), it_end(v.end());
52 it != it_end; ++it) {
53 o.pack(static_cast<bool>(*it));
54 }
55 return o;
56 }
57};
58
59template <typename Alloc>
60struct object_with_zone<std::vector<bool, Alloc> > {
61 void operator()(msgpack::object::with_zone& o, const std::vector<bool, Alloc>& v) const {
62 o.type = msgpack::type::ARRAY;
63 if(v.empty()) {
65 o.via.array.size = 0;
66 } else {
67 uint32_t size = checked_get_container_size(v.size());
69 msgpack::object* const pend = p + size;
70 o.via.array.ptr = p;
71 o.via.array.size = size;
72 typename std::vector<bool, Alloc>::const_iterator it(v.begin());
73 do {
74 *p = msgpack::object(static_cast<bool>(*it), o.zone);
75 ++p;
76 ++it;
77 } while(p < pend);
78 }
79 }
80};
81
82} // namespace adaptor
83
85} // MSGPACK_API_VERSION_NAMESPACE(v1)
87
88} // namespace msgpack
89
90#endif // MSGPACK_V1_TYPE_VECTOR_BOOL_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
msgpack::object_kv * end(msgpack::object_map &map)
Definition iterator.hpp:25
uint32_t checked_get_container_size(T size)
Definition check_container_size.hpp:55
msgpack::object const & operator()(msgpack::object const &o, std::vector< bool, Alloc > &v) const
Definition vector_bool.hpp:29
Definition adaptor_base.hpp:27
void operator()(msgpack::object::with_zone &o, const std::vector< bool, Alloc > &v) const
Definition vector_bool.hpp:61
Definition adaptor_base.hpp:43
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const std::vector< bool, Alloc > &v) const
Definition vector_bool.hpp:48
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
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