MessagePack for C++
size_equal_only.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2016 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_SIZE_EQUAL_ONLY_HPP
11 #define MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
12 
14 
15 namespace msgpack {
16 
20 
21 namespace type {
22 
23 template <typename T>
24 inline std::size_t size(T const& t) {
25  return t.size();
26 }
27 
28 template <typename T, std::size_t N>
29 inline std::size_t size(const T(&)[N]) {
30  return N;
31 }
32 
33 
34 #if !defined(MSGPACK_USE_CPP03)
35 
36 template <typename... T>
37 inline std::size_t size(std::tuple<T...> const&) {
38  return sizeof...(T);
39 }
40 
41 #endif // !defined(MSGPACK_USE_CPP03)
42 
43 
44 template <typename T>
46  size_equal_only(T& t):m_t(t) {}
47  T& m_t;
48 };
49 
50 template <typename T>
52  return size_equal_only<T>(t);
53 }
54 
55 template <typename T>
56 inline bool operator<(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
57  return lhs.m_t < rhs.m_t;
58 }
59 
60 template <typename T>
61 inline bool operator==(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
62  return lhs.m_t == &rhs.m_t;
63 }
64 
65 } // namespace type
66 
67 namespace adaptor {
68 
69 template <typename T>
70 struct convert<type::size_equal_only<T> > {
72  switch(o.type) {
75  break;
76  case msgpack::type::MAP:
78  break;
79  default:
80  throw msgpack::type_error();
81  }
82  o >> v.m_t;
83  return o;
84  }
85 };
86 
87 template <typename T>
88 struct pack<type::size_equal_only<T> > {
89  template <typename Stream>
91  o << v.m_t;
92  return o;
93  }
94 };
95 
96 template <typename T>
97 struct object<type::size_equal_only<T> > {
99  o << v.m_t;
100  }
101 };
102 
103 template <typename T>
104 struct object_with_zone<type::size_equal_only<T> > {
106  o << v.m_t;
107  }
108 };
109 
110 } // namespace adaptor
111 
113 } // MSGPACK_API_VERSION_NAMESPACE(v1)
115 
116 } // namespace msgpack
117 
118 #endif // MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
The class template that supports continuous packing.
Definition: pack.hpp:33
Definition: object_fwd.hpp:231
size_equal_only< T > make_size_equal_only(T &t)
Definition: size_equal_only.hpp:51
bool operator<(basic_variant< STR, BIN, EXT > const &lhs, basic_variant< STR, BIN, EXT > const &rhs)
Definition: msgpack_variant.hpp:258
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
@ MAP
Definition: object_fwd_decl.hpp:41
@ ARRAY
Definition: object_fwd_decl.hpp:40
bool operator==(basic_variant< STR, BIN, EXT > const &lhs, basic_variant< STR, BIN, EXT > const &rhs)
Definition: msgpack_variant.hpp:265
Definition: adaptor_base.hpp:15
msgpack::object const & operator()(msgpack::object const &o, type::size_equal_only< T > &v) const
Definition: size_equal_only.hpp:71
Definition: adaptor_base.hpp:27
void operator()(msgpack::object &o, type::size_equal_only< T > const &v) const
Definition: size_equal_only.hpp:98
void operator()(msgpack::object::with_zone &o, type::size_equal_only< T > v) const
Definition: size_equal_only.hpp:105
Definition: adaptor_base.hpp:43
Definition: adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::size_equal_only< T > &v) const
Definition: size_equal_only.hpp:90
Definition: adaptor_base.hpp:32
Definition: object.hpp:35
uint32_t size
Definition: object_fwd.hpp:23
uint32_t size
Definition: object_fwd.hpp:28
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
Definition: size_equal_only.hpp:45
size_equal_only(T &t)
Definition: size_equal_only.hpp:46
T & m_t
Definition: size_equal_only.hpp:47
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::object_map map
Definition: object_fwd.hpp:86
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66