/src/msgpack-c/include/msgpack/v1/adaptor/bool.hpp
Line | Count | Source |
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" |
14 | | #include "msgpack/adaptor/adaptor_base.hpp" |
15 | | #include "msgpack/object.hpp" |
16 | | |
17 | | namespace msgpack { |
18 | | |
19 | | /// @cond |
20 | | MSGPACK_API_VERSION_NAMESPACE(v1) { |
21 | | /// @endcond |
22 | | |
23 | | namespace adaptor { |
24 | | |
25 | | template <> |
26 | | struct convert<bool> { |
27 | 0 | msgpack::object const& operator()(msgpack::object const& o, bool& v) const { |
28 | 0 | if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); } |
29 | 0 | v = o.via.boolean; |
30 | 0 | return o; |
31 | 0 | } |
32 | | }; |
33 | | |
34 | | template <> |
35 | | struct pack<bool> { |
36 | | template <typename Stream> |
37 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const bool& v) const { |
38 | | if(v) { o.pack_true(); } |
39 | | else { o.pack_false(); } |
40 | | return o; |
41 | | } |
42 | | }; |
43 | | |
44 | | template <> |
45 | | struct object<bool> { |
46 | 0 | void operator()(msgpack::object& o, bool v) const { |
47 | 0 | o.type = msgpack::type::BOOLEAN; |
48 | 0 | o.via.boolean = v; |
49 | 0 | } |
50 | | }; |
51 | | |
52 | | template <> |
53 | | struct object_with_zone<bool> { |
54 | 0 | void operator()(msgpack::object::with_zone& o, bool v) const { |
55 | 0 | static_cast<msgpack::object&>(o) << v; |
56 | 0 | } |
57 | | }; |
58 | | |
59 | | } // namespace adaptor |
60 | | |
61 | | /// @cond |
62 | | } // MSGPACK_API_VERSION_NAMESPACE(v1) |
63 | | /// @endcond |
64 | | |
65 | | } // namespace msgpack |
66 | | |
67 | | #endif // MSGPACK_V1_TYPE_BOOL_HPP |