MessagePack for C++
nil.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2008-2009 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_TYPE_NIL_HPP
11 #define MSGPACK_TYPE_NIL_HPP
12 
13 #include "msgpack/versioning.hpp"
15 
16 namespace msgpack {
17 
21 
22 namespace type {
23 
24 struct nil_t { };
25 
26 #if !defined(MSGPACK_DISABLE_LEGACY_NIL)
27 
28 typedef nil_t nil;
29 
30 #endif // !defined(MSGPACK_DISABLE_LEGACY_NIL)
31 
32 inline bool operator<(nil_t const& lhs, nil_t const& rhs) {
33  return &lhs < &rhs;
34 }
35 
36 inline bool operator==(nil_t const& lhs, nil_t const& rhs) {
37  return &lhs == &rhs;
38 }
39 
40 } // namespace type
41 
42 namespace adaptor {
43 
44 template <>
45 struct convert<type::nil_t> {
47  if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
48  return o;
49  }
50 };
51 
52 template <>
53 struct pack<type::nil_t> {
54  template <typename Stream>
56  o.pack_nil();
57  return o;
58  }
59 };
60 
61 template <>
62 struct object<type::nil_t> {
65  }
66 };
67 
68 template <>
69 struct object_with_zone<type::nil_t> {
71  static_cast<msgpack::object&>(o) << v;
72  }
73 };
74 
75 } // namespace adaptor
76 
77 template <>
78 inline void msgpack::object::as<void>() const
79 {
81  convert(v);
82 }
83 
85 } // MSGPACK_API_VERSION_NAMESPACE(v1)
87 
88 } // namespace msgpack
89 
90 #endif // MSGPACK_TYPE_NIL_HPP
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
Definition: nil.hpp:24
nil_t nil
Definition: nil.hpp:28
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::nil_t &) const
Definition: nil.hpp:55
Definition: adaptor_base.hpp:15
void operator()(msgpack::object::with_zone &o, type::nil_t v) const
Definition: nil.hpp:70
void convert(T &v, msgpack::object const &o)
Definition: object.hpp:631
Definition: object_fwd.hpp:260
Definition: object_fwd.hpp:29
void operator()(msgpack::object &o, type::nil_t) const
Definition: nil.hpp:63
Definition: adaptor_base.hpp:45
Definition: object_fwd.hpp:253
Definition: adaptor_base.hpp:34
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:106
msgpack::type::object_type type
Definition: object_fwd.hpp:122
bool operator==(nil_t const &lhs, nil_t const &rhs)
Definition: nil.hpp:36
msgpack::object const & operator()(msgpack::object const &o, type::nil_t &) const
Definition: nil.hpp:46
Definition: adaptor_base.hpp:40
The class template that supports continuous packing.
Definition: adaptor_base.hpp:22
packer< Stream > & pack_nil()
Packing nil.
Definition: pack.hpp:1138
Definition: adaptor_base.hpp:29
bool operator<(nil_t const &lhs, nil_t const &rhs)
Definition: nil.hpp:32