MessagePack for C++
Loading...
Searching...
No Matches
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
16namespace msgpack {
17
21
23 uint32_t size;
25};
26
27struct object_map {
28 uint32_t size;
30};
31
32struct object_str {
33 uint32_t size;
34 const char* ptr;
35};
36
37struct object_bin {
38 uint32_t size;
39 const char* ptr;
40};
41
42struct 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
52template <typename T>
53struct has_as {
54private:
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_(...);
64public:
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
74
77struct object {
78 union union_type {
79 bool boolean;
80 uint64_t u64;
81 int64_t i64;
82#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
83 MSGPACK_DEPRECATED("please use f64 instead")
84 double dec; // obsolete
85#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
86 double f64;
92 };
93
96
98
101 bool is_nil() const { return type == msgpack::type::NIL; }
102
103#if defined(MSGPACK_USE_CPP03)
104
106
111 template <typename T>
112 T as() const;
113
114#else // defined(MSGPACK_USE_CPP03)
115
117
122 template <typename T>
123 typename std::enable_if<msgpack::has_as<T>::value, T>::type as() const;
124
126
131 template <typename T>
132 typename std::enable_if<!msgpack::has_as<T>::value, T>::type as() const;
133
134#endif // defined(MSGPACK_USE_CPP03)
135
137
143 template <typename T>
144 typename msgpack::enable_if<
145 !msgpack::is_array<T>::value && !msgpack::is_pointer<T>::value,
146 T&
147 >::type
148 convert(T& v) const;
149
150 template <typename T, std::size_t N>
151 T (&convert(T(&v)[N]) const)[N];
152
153
154#if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
156
162 template <typename T>
163 MSGPACK_DEPRECATED("please use reference version instead")
164 typename msgpack::enable_if<
165 msgpack::is_pointer<T>::value,
166 T
167 >::type
168 convert(T v) const;
169#endif // !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
170
172
178 template <typename T>
179 bool convert_if_not_nil(T& v) const;
180
182 object();
183
185
192 template <typename T>
193 explicit object(const T& v);
194
196
204 template <typename T>
205 object(const T& v, msgpack::zone& z);
206
208
217 template <typename T>
218 MSGPACK_DEPRECATED("please use zone reference version instead of the pointer version")
219 object(const T& v, msgpack::zone* z);
220
221 template <typename T>
222 object& operator=(const T& v);
223
224 // Not a nested struct (i.e. 'struct with_zone;') to work around MSVC C++20 modules error C2504
226
227protected:
228 struct implicit_type;
229
230public:
231 implicit_type convert() const;
232};
233
234class type_error : public std::bad_cast { };
235
237 implicit_type(object const& o) : obj(o) { }
239
240 template <typename T>
241 operator T();
242
243private:
244 object const& obj;
245};
246
248} // MSGPACK_API_VERSION_NAMESPACE(v1)
250
251} // namespace msgpack
252
253#endif // MSGPACK_V1_OBJECT_FWD_HPP
Definition object_fwd.hpp:234
Definition cpp03_zone.hpp:30
Definition array_ref.hpp:24
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:1178
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:236
~implicit_type()
Definition object_fwd.hpp:238
implicit_type(object const &o)
Definition object_fwd.hpp:237
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
int8_t type() const
Definition object_fwd.hpp:43
const char * ptr
Definition object_fwd.hpp:46
const char * data() const
Definition object_fwd.hpp:44
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
Definition object.hpp:35
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:77
msgpack::enable_if<!msgpack::is_array< T >::value &&!msgpack::is_pointer< T >::value, T & >::type convert(T &v) const
Convert the object.
Definition object.hpp:1076
object()
Default constructor. The object is set to nil.
Definition object.hpp:1139
std::enable_if<!msgpack::has_as< T >::value, T >::type as() const
Get value as T.
union_type via
Definition object_fwd.hpp:95
bool convert_if_not_nil(T &v) const
Convert the object if not nil.
Definition object.hpp:1104
msgpack::type::object_type type
Definition object_fwd.hpp:94
object_with_zone_type with_zone
Definition object_fwd.hpp:225
bool is_nil() const
Cheking nil.
Definition object_fwd.hpp:101
Definition object_fwd.hpp:78
bool boolean
Definition object_fwd.hpp:79
msgpack::object_array array
Definition object_fwd.hpp:87
msgpack::object_ext ext
Definition object_fwd.hpp:91
msgpack::object_str str
Definition object_fwd.hpp:89
uint64_t u64
Definition object_fwd.hpp:80
int64_t i64
Definition object_fwd.hpp:81
msgpack::object_bin bin
Definition object_fwd.hpp:90
double f64
Definition object_fwd.hpp:86
msgpack::object_map map
Definition object_fwd.hpp:88
#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