]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/multi_index/detail/index_node_base.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / multi_index / detail / index_node_base.hpp
1 /* Copyright 2003-2016 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/multi_index for library home page.
7 */
8
9 #ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_NODE_BASE_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_INDEX_NODE_BASE_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/type_traits/aligned_storage.hpp>
18 #include <boost/type_traits/alignment_of.hpp>
19
20 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
21 #include <boost/archive/archive_exception.hpp>
22 #include <boost/serialization/access.hpp>
23 #include <boost/throw_exception.hpp>
24 #endif
25
26 namespace boost{
27
28 namespace multi_index{
29
30 namespace detail{
31
32 /* index_node_base tops the node hierarchy of multi_index_container. It holds
33 * the value of the element contained.
34 */
35
36 template<typename Value>
37 struct pod_value_holder
38 {
39 typename aligned_storage<
40 sizeof(Value),
41 alignment_of<Value>::value
42 >::type space;
43 };
44
45 template<typename Value,typename Allocator>
46 struct index_node_base:private pod_value_holder<Value>
47 {
48 typedef index_node_base base_type; /* used for serialization purposes */
49 typedef Value value_type;
50 typedef Allocator allocator_type;
51
52 #include <boost/multi_index/detail/ignore_wstrict_aliasing.hpp>
53
54 value_type& value()
55 {
56 return *reinterpret_cast<value_type*>(&this->space);
57 }
58
59 const value_type& value()const
60 {
61 return *reinterpret_cast<const value_type*>(&this->space);
62 }
63
64 #include <boost/multi_index/detail/restore_wstrict_aliasing.hpp>
65
66 static index_node_base* from_value(const value_type* p)
67 {
68 return static_cast<index_node_base *>(
69 reinterpret_cast<pod_value_holder<Value>*>( /* std 9.2.17 */
70 const_cast<value_type*>(p)));
71 }
72
73 private:
74 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
75 friend class boost::serialization::access;
76
77 /* nodes do not emit any kind of serialization info. They are
78 * fed to Boost.Serialization so that pointers to nodes are
79 * tracked correctly.
80 */
81
82 template<class Archive>
83 void serialize(Archive&,const unsigned int)
84 {
85 }
86 #endif
87 };
88
89 template<typename Node,typename Value>
90 Node* node_from_value(const Value* p)
91 {
92 typedef typename Node::allocator_type allocator_type;
93 return static_cast<Node*>(
94 index_node_base<Value,allocator_type>::from_value(p));
95 }
96
97 } /* namespace multi_index::detail */
98
99 } /* namespace multi_index */
100
101 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
102 /* Index nodes never get constructed directly by Boost.Serialization,
103 * as archives are always fed pointers to previously existent
104 * nodes. So, if this is called it means we are dealing with a
105 * somehow invalid archive.
106 */
107
108 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
109 namespace serialization{
110 #else
111 namespace multi_index{
112 namespace detail{
113 #endif
114
115 template<class Archive,typename Value,typename Allocator>
116 inline void load_construct_data(
117 Archive&,boost::multi_index::detail::index_node_base<Value,Allocator>*,
118 const unsigned int)
119 {
120 throw_exception(
121 archive::archive_exception(archive::archive_exception::other_exception));
122 }
123
124 #if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
125 } /* namespace serialization */
126 #else
127 } /* namespace multi_index::detail */
128 } /* namespace multi_index */
129 #endif
130
131 #endif
132
133 } /* namespace boost */
134
135 #endif