Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:31

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2007-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
0012 #define BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/interprocess/creation_tags.hpp>
0023 #include <boost/interprocess/detail/type_traits.hpp>
0024 #include <boost/interprocess/detail/mpl.hpp>
0025 #include <boost/container/detail/placement_new.hpp>
0026 
0027 namespace boost {
0028 namespace interprocess {
0029 namespace ipcdetail {
0030 
0031 struct named_creation_functor_no_arg{};
0032 
0033 template <class T, class Arg = named_creation_functor_no_arg>
0034 class named_creation_functor
0035 {
0036    typedef named_creation_functor_no_arg no_arg_t;
0037    public:
0038    named_creation_functor(create_enum_t type, Arg arg = Arg())
0039       :  m_creation_type(type), m_arg(arg){}
0040 
0041    template<class ArgType>
0042    void construct(void *address, typename enable_if_c<is_same<ArgType, no_arg_t>::value>::type * = 0) const
0043    {  ::new(address, boost_container_new_t())T; }
0044 
0045    template<class ArgType>
0046    void construct(void *address, typename enable_if_c<!is_same<ArgType, no_arg_t>::value>::type * = 0) const
0047    {  ::new(address, boost_container_new_t())T(m_arg); }
0048 
0049    bool operator()(void *address, std::size_t, bool created) const
0050    {
0051       switch(m_creation_type){
0052          case DoOpen:
0053             return true;
0054          break;
0055          case DoCreate:
0056          case DoOpenOrCreate:
0057             if(created){
0058                construct<Arg>(address);
0059             }
0060             return true;
0061          break;
0062 
0063          default:
0064             return false;
0065          break;
0066       }
0067    }
0068 
0069    static std::size_t get_min_size()
0070    {  return sizeof(T);  }
0071 
0072    private:
0073    create_enum_t m_creation_type;
0074    Arg m_arg;
0075 };
0076 
0077 }  //namespace ipcdetail {
0078 }  //namespace interprocess {
0079 }  //namespace boost {
0080 
0081 #endif   //BOOST_INTERPROCESS_SYNC_NAMED_CREATION_FUNCTOR_HPP