MessagePack for C++
object_fwd.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2008-2014 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 
11 #ifndef MSGPACK_V1_OBJECT_FWD_HPP
12 #define MSGPACK_V1_OBJECT_FWD_HPP
13 
15 
16 namespace msgpack {
17 
21 
22 struct object_array {
23  uint32_t size;
25 };
26 
27 struct object_map {
28  uint32_t size;
30 };
31 
32 struct object_str {
33  uint32_t size;
34  const char* ptr;
35 };
36 
37 struct object_bin {
38  uint32_t size;
39  const char* ptr;
40 };
41 
42 struct object_ext {
43  int8_t type() const { return static_cast<int8_t>(ptr[0]); }
44  const char* data() const { return &ptr[1]; }
45  uint32_t size;
46  const char* ptr;
47 };
48 
49 
50 #if !defined(MSGPACK_USE_CPP03)
51 
52 template <typename T>
53 struct has_as {
54 private:
55  template <typename U>
56  static auto check(U*) ->
57  // Check v1 specialization
58  typename std::is_same<
59  decltype(adaptor::as<U>()(std::declval<msgpack::object>())),
60  T
61  >::type;
62  template <typename...>
63  static std::false_type check(...);
64 public:
65  using type = decltype(check<T>(MSGPACK_NULLPTR));
66  static constexpr bool value = type::value;
67 };
68 
69 #endif // !defined(MSGPACK_USE_CPP03)
70 
72 
75 struct object {
76  union union_type {
77  bool boolean;
78  uint64_t u64;
79  int64_t i64;
80 #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
81  MSGPACK_DEPRECATED("please use f64 instead")
82  double dec; // obsolete
83 #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
84  double f64;
90  };
91 
94 
96 
99  bool is_nil() const { return type == msgpack::type::NIL; }
100 
101 #if defined(MSGPACK_USE_CPP03)
102 
104 
109  template <typename T>
110  T as() const;
111 
112 #else // defined(MSGPACK_USE_CPP03)
113 
115 
120  template <typename T>
121  typename std::enable_if<msgpack::has_as<T>::value, T>::type as() const;
122 
124 
129  template <typename T>
130  typename std::enable_if<!msgpack::has_as<T>::value, T>::type as() const;
131 
132 #endif // defined(MSGPACK_USE_CPP03)
133 
135 
141  template <typename T>
142  typename msgpack::enable_if<
143  !msgpack::is_array<T>::value && !msgpack::is_pointer<T>::value,
144  T&
145  >::type
146  convert(T& v) const;
147 
148  template <typename T, std::size_t N>
149  T (&convert(T(&v)[N]) const)[N];
150 
151 
152 #if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
154 
160  template <typename T>
161  MSGPACK_DEPRECATED("please use reference version instead")
162  typename msgpack::enable_if<
163  msgpack::is_pointer<T>::value,
164  T
165  >::type
166  convert(T v) const;
167 #endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
168 
170 
176  template <typename T>
177  bool convert_if_not_nil(T& v) const;
178 
180  object();
181 
183 
190  template <typename T>
191  explicit object(const T& v);
192 
194 
202  template <typename T>
203  object(const T& v, msgpack::zone& z);
204 
206 
215  template <typename T>
216  MSGPACK_DEPRECATED("please use zone reference version instead of the pointer version")
217  object(const T& v, msgpack::zone* z);
218 
219  template <typename T>
220  object& operator=(const T& v);
221 
222  struct with_zone;
223 
224 protected:
225  struct implicit_type;
226 
227 public:
228  implicit_type convert() const;
229 };
230 
231 class type_error : public std::bad_cast { };
232 
234  implicit_type(object const& o) : obj(o) { }
236 
237  template <typename T>
238  operator T();
239 
240 private:
241  object const& obj;
242 };
243 
245 } // MSGPACK_API_VERSION_NAMESPACE(v1)
247 
248 } // namespace msgpack
249 
250 #endif // MSGPACK_V1_OBJECT_FWD_HPP
Definition: object_fwd.hpp:231
Definition: cpp03_zone.hpp:31
object_type
Definition: object_fwd_decl.hpp:27
@ NIL
Definition: object_fwd_decl.hpp:28
Definition: adaptor_base.hpp:15
void convert(T &v, msgpack::object const &o)
Definition: object.hpp:1173
Definition: object_fwd_decl.hpp:61
Definition: object_fwd.hpp:53
static constexpr bool value
Definition: object_fwd.hpp:66
decltype(check< T >(MSGPACK_NULLPTR)) type
Definition: object_fwd.hpp:65
Definition: object_fwd.hpp:233
~implicit_type()
Definition: object_fwd.hpp:235
implicit_type(object const &o)
Definition: object_fwd.hpp:234
Definition: object_fwd.hpp:22
uint32_t size
Definition: object_fwd.hpp:23
msgpack::object * ptr
Definition: object_fwd.hpp:24
Definition: object_fwd.hpp:37
uint32_t size
Definition: object_fwd.hpp:38
const char * ptr
Definition: object_fwd.hpp:39
Definition: object_fwd.hpp:42
const char * data() const
Definition: object_fwd.hpp:44
int8_t type() const
Definition: object_fwd.hpp:43
const char * ptr
Definition: object_fwd.hpp:46
uint32_t size
Definition: object_fwd.hpp:45
Definition: object.hpp:30
Definition: object_fwd.hpp:27
uint32_t size
Definition: object_fwd.hpp:28
msgpack::object_kv * ptr
Definition: object_fwd.hpp:29
Definition: object_fwd.hpp:32
const char * ptr
Definition: object_fwd.hpp:34
uint32_t size
Definition: object_fwd.hpp:33
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
bool is_nil() const
Cheking nil.
Definition: object_fwd.hpp:99
std::enable_if<!msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition: object_fwd.hpp:76
bool boolean
Definition: object_fwd.hpp:77
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::object_ext ext
Definition: object_fwd.hpp:89
msgpack::object_str str
Definition: object_fwd.hpp:87
uint64_t u64
Definition: object_fwd.hpp:78
int64_t i64
Definition: object_fwd.hpp:79
msgpack::object_bin bin
Definition: object_fwd.hpp:88
double f64
Definition: object_fwd.hpp:84
msgpack::object_map map
Definition: object_fwd.hpp:86
#define MSGPACK_DEPRECATED(msg)
Definition: cpp_config.hpp:138
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66