]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/include/boost/interprocess/sync/shm/named_creation_functor.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / interprocess / include / boost / interprocess / sync / shm / named_creation_functor.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2007-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
12 #define BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/interprocess/creation_tags.hpp>
23 #include <boost/interprocess/detail/type_traits.hpp>
24 #include <boost/interprocess/detail/mpl.hpp>
25 #include <boost/container/detail/placement_new.hpp>
26
27 namespace boost {
28 namespace interprocess {
29 namespace ipcdetail {
30
31 struct named_creation_functor_no_arg{};
32
33 template <class T, class Arg = named_creation_functor_no_arg>
34 class named_creation_functor
35 {
36 typedef named_creation_functor_no_arg no_arg_t;
37 public:
38 named_creation_functor(create_enum_t type, Arg arg = Arg())
39 : m_creation_type(type), m_arg(arg){}
40
41 template<class ArgType>
42 void construct(void *address, typename enable_if_c<is_same<ArgType, no_arg_t>::value>::type * = 0) const
43 { ::new(address, boost_container_new_t())T; }
44
45 template<class ArgType>
46 void construct(void *address, typename enable_if_c<!is_same<ArgType, no_arg_t>::value>::type * = 0) const
47 { ::new(address, boost_container_new_t())T(m_arg); }
48
49 bool operator()(void *address, std::size_t, bool created) const
50 {
51 switch(m_creation_type){
52 case DoOpen:
53 return true;
54 break;
55 case DoCreate:
56 case DoOpenOrCreate:
57 if(created){
58 construct<Arg>(address);
59 }
60 return true;
61 break;
62
63 default:
64 return false;
65 break;
66 }
67 }
68
69 static std::size_t get_min_size()
70 { return sizeof(T); }
71
72 private:
73 create_enum_t m_creation_type;
74 Arg m_arg;
75 };
76
77 } //namespace ipcdetail {
78 } //namespace interprocess {
79 } //namespace boost {
80
81 #endif //BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP