MessagePack for C++
Loading...
Searching...
No Matches
unique_ptr.hpp
Go to the documentation of this file.
1//
2// MessagePack for C++ static resolution routine
3//
4// Copyright (C) 2015 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_TYPE_CPP11_UNIQUE_PTR_HPP
12#define MSGPACK_V1_TYPE_CPP11_UNIQUE_PTR_HPP
13
16#include "msgpack/object.hpp"
18
19#include <memory>
20
21namespace msgpack {
22
26
27namespace adaptor {
28
29template <typename T>
30struct as<std::unique_ptr<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
31 std::unique_ptr<T> operator()(msgpack::object const& o) const {
32 if(o.is_nil()) return MSGPACK_NULLPTR;
33 return std::unique_ptr<T>(new T(o.as<T>()));
34 }
35};
36
37template <typename T>
38struct convert<std::unique_ptr<T>> {
39 msgpack::object const& operator()(msgpack::object const& o, std::unique_ptr<T>& v) const {
40 if(o.is_nil()) v.reset();
41 else {
42 v.reset(new T);
44 }
45 return o;
46 }
47};
48
49template <typename T>
50struct pack<std::unique_ptr<T>> {
51 template <typename Stream>
52 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unique_ptr<T>& v) const {
53 if (v) o.pack(*v);
54 else o.pack_nil();
55 return o;
56 }
57};
58
59template <typename T>
60struct object<std::unique_ptr<T> > {
61 void operator()(msgpack::object& o, const std::unique_ptr<T>& v) const {
62 if (v) msgpack::adaptor::object<T>()(o, *v);
63 else o.type = msgpack::type::NIL;
64 }
65};
66
67template <typename T>
68struct object_with_zone<std::unique_ptr<T>> {
69 void operator()(msgpack::object::with_zone& o, const std::unique_ptr<T>& v) const {
71 else o.type = msgpack::type::NIL;
72 }
73};
74
75} // namespace adaptor
76
78} // MSGPACK_API_VERSION_NAMESPACE(v1)
80
81} // namespace msgpack
82
83#endif // MSGPACK_V1_TYPE_CPP11_UNIQUE_PTR_HPP
The class template that supports continuous packing.
Definition pack.hpp:33
packer< Stream > & pack_nil()
Packing nil.
Definition pack.hpp:1170
packer< Stream > & pack(const T &v)
Packing function template.
Definition adaptor_base.hpp:15
std::unique_ptr< T > operator()(msgpack::object const &o) const
Definition unique_ptr.hpp:31
Definition object_fwd_decl.hpp:61
msgpack::object const & operator()(msgpack::object const &o, std::unique_ptr< T > &v) const
Definition unique_ptr.hpp:39
Definition adaptor_base.hpp:27
void operator()(msgpack::object &o, const std::unique_ptr< T > &v) const
Definition unique_ptr.hpp:61
void operator()(msgpack::object::with_zone &o, const std::unique_ptr< T > &v) const
Definition unique_ptr.hpp:69
Definition adaptor_base.hpp:43
Definition adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const std::unique_ptr< T > &v) const
Definition unique_ptr.hpp:52
Definition adaptor_base.hpp:32
Definition object.hpp:35
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:75
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition object.hpp:1126
msgpack::type::object_type type
Definition object_fwd.hpp:92
bool is_nil() const
Cheking nil.
Definition object_fwd.hpp:99
#define MSGPACK_NULLPTR
Definition cpp_config_decl.hpp:85
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66