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-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 
11 #ifndef MSGPACK_V2_OBJECT_FWD_HPP
12 #define MSGPACK_V2_OBJECT_FWD_HPP
13 
15 #include "msgpack/object_fwd.hpp"
16 
17 namespace msgpack {
18 
22 
23 struct object : v1::object {
24  object() {}
25  object(v1::object const& o):v1::object(o) {}
27 
34  template <typename T>
35  explicit object(const T& v) {
36  *this << v;
37  }
38 
40 
48  template <typename T>
49  object(const T& v, msgpack::zone& z):v1::object(v, z) {}
50 
51 public:
53 
59  template <typename T>
60  T& convert(T& v) const { return v1::object::convert(v); }
61 
62  using v1::object::with_zone;
64 };
65 
66 #if !defined(MSGPACK_USE_CPP03)
67 
68 namespace adaptor {
69 
70 // If v1 has as specialization for T, then dispatch v1::adaptor::as<T>.
71 // So I call v1::has_as<T> meta function intentionally.
72 template <typename T>
73 struct as<T, typename std::enable_if<v1::has_as<T>::value>::type> : v1::adaptor::as<T> {
74 };
75 
76 } // namespace adaptor
77 
78 template <typename T>
79 struct has_as {
80 private:
81  template <typename U>
82  static auto check(U*) ->
83  typename std::enable_if<
84  // check v2 specialization
85  std::is_same<
86  decltype(adaptor::as<U>()(std::declval<msgpack::object>())),
87  U
88  >::value
89  ||
90  // check v1 specialization
91  v1::has_as<U>::value,
92  std::true_type
93  >::type;
94  template <typename...>
95  static std::false_type check(...);
96 public:
97  using type = decltype(check<T>(MSGPACK_NULLPTR));
98  static constexpr bool value = type::value;
99 };
100 
101 #endif // !defined(MSGPACK_USE_CPP03)
102 
104 } // MSGPACK_API_VERSION_NAMESPACE(v2)
106 
107 } // namespace msgpack
108 
109 #endif // MSGPACK_V2_OBJECT_FWD_HPP
Definition: cpp03_zone.hpp:31
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
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
implicit_type convert() const
object()
Definition: object_fwd.hpp:24
object(const T &v)
Construct object from T.
Definition: object_fwd.hpp:35
T & convert(T &v) const
Convert the object.
Definition: object_fwd.hpp:60
object(v1::object const &o)
Definition: object_fwd.hpp:25
object(const T &v, msgpack::zone &z)
Construct object from T.
Definition: object_fwd.hpp:49
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66