1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
12 #define BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
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>
28 namespace interprocess {
31 struct named_creation_functor_no_arg{};
33 template <class T, class Arg = named_creation_functor_no_arg>
34 class named_creation_functor
36 typedef named_creation_functor_no_arg no_arg_t;
38 named_creation_functor(create_enum_t type, Arg arg = Arg())
39 : m_creation_type(type), m_arg(arg){}
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; }
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); }
49 bool operator()(void *address, std::size_t, bool created) const
51 switch(m_creation_type){
58 construct<Arg>(address);
69 static std::size_t get_min_size()
73 create_enum_t m_creation_type;
77 } //namespace ipcdetail {
78 } //namespace interprocess {
81 #endif //BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP