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
18 #include <boost/interprocess/creation_tags.hpp>
19 #include <boost/interprocess/detail/type_traits.hpp>
20 #include <boost/interprocess/detail/mpl.hpp>
23 namespace interprocess {
26 struct named_creation_functor_no_arg{};
28 template <class T, class Arg = named_creation_functor_no_arg>
29 class named_creation_functor
31 typedef named_creation_functor_no_arg no_arg_t;
33 named_creation_functor(create_enum_t type, Arg arg = Arg())
34 : m_creation_type(type), m_arg(arg){}
36 template<class ArgType>
37 void construct(void *address, typename enable_if_c<is_same<ArgType, no_arg_t>::value>::type * = 0) const
40 template<class ArgType>
41 void construct(void *address, typename enable_if_c<!is_same<ArgType, no_arg_t>::value>::type * = 0) const
42 { new(address)T(m_arg); }
44 bool operator()(void *address, std::size_t, bool created) const
46 switch(m_creation_type){
53 construct<Arg>(address);
64 std::size_t get_min_size() const
68 create_enum_t m_creation_type;
72 } //namespace ipcdetail {
73 } //namespace interprocess {
76 #endif //BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP