nil.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "msgpack/v1/adaptor/nil_decl.hpp"
  13. namespace msgpack {
  14. /// @cond
  15. MSGPACK_API_VERSION_NAMESPACE(v1) {
  16. /// @endcond
  17. namespace type {
  18. struct nil_t { };
  19. inline bool operator<(nil_t const& lhs, nil_t const& rhs) {
  20. return &lhs < &rhs;
  21. }
  22. inline bool operator==(nil_t const& lhs, nil_t const& rhs) {
  23. return &lhs == &rhs;
  24. }
  25. } // namespace type
  26. namespace adaptor {
  27. template <>
  28. struct convert<type::nil_t> {
  29. msgpack::object const& operator()(msgpack::object const& o, type::nil_t&) const {
  30. if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
  31. return o;
  32. }
  33. };
  34. template <>
  35. struct pack<type::nil_t> {
  36. template <typename Stream>
  37. msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil_t&) const {
  38. o.pack_nil();
  39. return o;
  40. }
  41. };
  42. template <>
  43. struct object<type::nil_t> {
  44. void operator()(msgpack::object& o, type::nil_t) const {
  45. o.type = msgpack::type::NIL;
  46. }
  47. };
  48. template <>
  49. struct object_with_zone<type::nil_t> {
  50. void operator()(msgpack::object::with_zone& o, type::nil_t v) const {
  51. static_cast<msgpack::object&>(o) << v;
  52. }
  53. };
  54. } // namespace adaptor
  55. /// @cond
  56. } // MSGPACK_API_VERSION_NAMESPACE(v1)
  57. /// @endcond
  58. } // namespace msgpack
  59. #endif // MSGPACK_V1_TYPE_NIL_HPP