MessagePack for C++
bool.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2008-2016 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_BOOL_HPP
11 #define MSGPACK_V1_TYPE_BOOL_HPP
12 
13 #include "msgpack/versioning.hpp"
15 
16 namespace msgpack {
17 
21 
22 namespace adaptor {
23 
24 template <>
25 struct convert<bool> {
26  msgpack::object const& operator()(msgpack::object const& o, bool& v) const {
27  if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); }
28  v = o.via.boolean;
29  return o;
30  }
31 };
32 
33 template <>
34 struct pack<bool> {
35  template <typename Stream>
37  if(v) { o.pack_true(); }
38  else { o.pack_false(); }
39  return o;
40  }
41 };
42 
43 template <>
44 struct object<bool> {
45  void operator()(msgpack::object& o, bool v) const {
47  o.via.boolean = v;
48  }
49 };
50 
51 template <>
52 struct object_with_zone<bool> {
53  void operator()(msgpack::object::with_zone& o, bool v) const {
54  static_cast<msgpack::object&>(o) << v;
55  }
56 };
57 
58 } // namespace adaptor
59 
61 } // MSGPACK_API_VERSION_NAMESPACE(v1)
63 
64 } // namespace msgpack
65 
66 #endif // MSGPACK_V1_TYPE_BOOL_HPP
The class template that supports continuous packing.
Definition: pack.hpp:33
packer< Stream > & pack_true()
Packing true.
Definition: pack.hpp:1178
packer< Stream > & pack_false()
Packing false.
Definition: pack.hpp:1186
Definition: object_fwd.hpp:231
@ BOOLEAN
Definition: object_fwd_decl.hpp:29
Definition: adaptor_base.hpp:15
msgpack::object const & operator()(msgpack::object const &o, bool &v) const
Definition: bool.hpp:26
Definition: adaptor_base.hpp:27
void operator()(msgpack::object &o, bool v) const
Definition: bool.hpp:45
void operator()(msgpack::object::with_zone &o, bool v) const
Definition: bool.hpp:53
Definition: adaptor_base.hpp:43
Definition: adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const bool &v) const
Definition: bool.hpp:36
Definition: adaptor_base.hpp:32
Definition: object.hpp:35
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
union_type via
Definition: object_fwd.hpp:93
msgpack::type::object_type type
Definition: object_fwd.hpp:92
bool boolean
Definition: object_fwd.hpp:77
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66