/src/msgpack-c/include/msgpack/v1/adaptor/nil.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // MessagePack for C++ static resolution routine |
3 | | // |
4 | | // Copyright (C) 2008-2016 FURUHASHI Sadayuki and 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_NIL_HPP |
11 | | #define MSGPACK_V1_TYPE_NIL_HPP |
12 | | |
13 | | #include "msgpack/v1/adaptor/nil_decl.hpp" |
14 | | |
15 | | namespace msgpack { |
16 | | |
17 | | /// @cond |
18 | | MSGPACK_API_VERSION_NAMESPACE(v1) { |
19 | | /// @endcond |
20 | | |
21 | | namespace type { |
22 | | |
23 | | struct nil_t { }; |
24 | | |
25 | 0 | inline bool operator<(nil_t const& lhs, nil_t const& rhs) { |
26 | 0 | return &lhs < &rhs; |
27 | 0 | } |
28 | | |
29 | 0 | inline bool operator==(nil_t const& lhs, nil_t const& rhs) { |
30 | 0 | return &lhs == &rhs; |
31 | 0 | } |
32 | | |
33 | | } // namespace type |
34 | | |
35 | | namespace adaptor { |
36 | | |
37 | | template <> |
38 | | struct convert<type::nil_t> { |
39 | 0 | msgpack::object const& operator()(msgpack::object const& o, type::nil_t&) const { |
40 | 0 | if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); } |
41 | 0 | return o; |
42 | 0 | } |
43 | | }; |
44 | | |
45 | | template <> |
46 | | struct pack<type::nil_t> { |
47 | | template <typename Stream> |
48 | | msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil_t&) const { |
49 | | o.pack_nil(); |
50 | | return o; |
51 | | } |
52 | | }; |
53 | | |
54 | | template <> |
55 | | struct object<type::nil_t> { |
56 | 0 | void operator()(msgpack::object& o, type::nil_t) const { |
57 | 0 | o.type = msgpack::type::NIL; |
58 | 0 | } |
59 | | }; |
60 | | |
61 | | template <> |
62 | | struct object_with_zone<type::nil_t> { |
63 | 0 | void operator()(msgpack::object::with_zone& o, type::nil_t v) const { |
64 | 0 | static_cast<msgpack::object&>(o) << v; |
65 | 0 | } |
66 | | }; |
67 | | |
68 | | } // namespace adaptor |
69 | | |
70 | | /// @cond |
71 | | } // MSGPACK_API_VERSION_NAMESPACE(v1) |
72 | | /// @endcond |
73 | | |
74 | | } // namespace msgpack |
75 | | |
76 | | #endif // MSGPACK_V1_TYPE_NIL_HPP |