Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 08:05:19

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-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_NAMED_PROXY_HPP
0012 #define BOOST_INTERPROCESS_NAMED_PROXY_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 
0026 // interprocess/detail
0027 #include <boost/interprocess/detail/mpl.hpp>
0028 #include <boost/move/utility_core.hpp>
0029 #ifndef BOOST_INTERPROCESS_PERFECT_FORWARDING
0030 #include <boost/move/detail/fwd_macros.hpp>
0031 #else
0032 #include <boost/move/utility_core.hpp>
0033 #include <boost/interprocess/detail/variadic_templates_tools.hpp>
0034 #endif   //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
0035 #include <boost/container/detail/placement_new.hpp>
0036 
0037 #include <cstddef>
0038 
0039 //!\file
0040 //!Describes a proxy class that implements named allocation syntax.
0041 
0042 namespace boost {
0043 namespace interprocess {
0044 namespace ipcdetail {
0045 
0046 template<class T>
0047 inline void named_construct_placement_destroy(void *mem, std::size_t num)
0048 {
0049    T* memory = static_cast<T*>(mem); \
0050    for(std::size_t destroyed = 0; destroyed < num; ++destroyed)
0051       (memory++)->~T();
0052 }
0053 
0054 
0055 #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
0056 
0057 template<class T, bool is_iterator, class ...Args>
0058 struct CtorArgN
0059 {
0060    typedef T object_type;
0061    typedef bool_<is_iterator> IsIterator;
0062    typedef CtorArgN<T, is_iterator, Args...> self_t;
0063    typedef typename build_number_seq<sizeof...(Args)>::type index_tuple_t;
0064 
0065    self_t& operator++()
0066    {
0067       this->do_increment(IsIterator(), index_tuple_t());
0068       return *this;
0069    }
0070 
0071    self_t  operator++(int) {  return ++*this;   *this;  }
0072 
0073    CtorArgN(Args && ...args)
0074       :  args_(args...)
0075    {}
0076 
0077    virtual void construct_n(void *mem, std::size_t num)
0078    {
0079       std::size_t constructed = 0;
0080       BOOST_INTERPROCESS_TRY{
0081          T* memory      = static_cast<T*>(mem);
0082          for(constructed = 0; constructed < num; ++constructed){
0083             this->construct(memory++, IsIterator(), index_tuple_t());
0084             this->do_increment(IsIterator(), index_tuple_t());
0085          }
0086       }
0087       BOOST_INTERPROCESS_CATCH(...) {
0088          named_construct_placement_destroy<T>(mem, constructed);
0089          BOOST_INTERPROCESS_RETHROW
0090       } BOOST_INTERPROCESS_CATCH_END
0091    }
0092 
0093    private:
0094    template<std::size_t ...IdxPack>
0095    void construct(void *mem, true_, const index_tuple<IdxPack...>&)
0096    {  ::new((void*)mem, boost_container_new_t())T(*boost::forward<Args>((get<IdxPack>)(args_))...); }
0097 
0098    template<std::size_t ...IdxPack>
0099    void construct(void *mem, false_, const index_tuple<IdxPack...>&)
0100    {  ::new((void*)mem, boost_container_new_t())T(boost::forward<Args>((get<IdxPack>)(args_))...); }
0101 
0102    template<std::size_t ...IdxPack>
0103    void do_increment(true_, const index_tuple<IdxPack...>&)
0104    {
0105       this->expansion_helper(++(get<IdxPack>)(args_)...);
0106    }
0107 
0108    template<class ...ExpansionArgs>
0109    void expansion_helper(ExpansionArgs &&...)
0110    {}
0111 
0112    template<std::size_t ...IdxPack>
0113    void do_increment(false_, const index_tuple<IdxPack...>&)
0114    {}
0115 
0116    tuple<Args&...> args_;
0117 };
0118 
0119 //!Describes a proxy class that implements named
0120 //!allocation syntax.
0121 template
0122    < class SegmentManager  //segment manager to construct the object
0123    , class T               //type of object to build
0124    , bool is_iterator      //passing parameters are normal object or iterators?
0125    >
0126 class named_proxy
0127 {
0128    typedef typename SegmentManager::char_type char_type;
0129    const char_type *    mp_name;
0130    SegmentManager *     mp_mngr;
0131    mutable std::size_t  m_num;
0132    const bool           m_find;
0133    const bool           m_dothrow;
0134 
0135    public:
0136    named_proxy(SegmentManager *mngr, const char_type *name, bool find, bool dothrow)
0137       :  mp_name(name), mp_mngr(mngr), m_num(1)
0138       ,  m_find(find),  m_dothrow(dothrow)
0139    {}
0140 
0141    template<class ...Args>
0142    T *operator()(Args &&...args) const
0143    {
0144       CtorArgN<T, is_iterator, Args...> &&ctor_obj = CtorArgN<T, is_iterator, Args...>
0145          (boost::forward<Args>(args)...);
0146       return mp_mngr->generic_construct(ctor_obj, mp_name, m_num, m_find, m_dothrow);
0147    }
0148 
0149    //This operator allows --> named_new("Name")[3]; <-- syntax
0150    const named_proxy &operator[](std::size_t num) const
0151    {  m_num *= num; return *this;  }
0152 };
0153 
0154 #else //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
0155 
0156 #define BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN(N)\
0157 \
0158 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >  \
0159 struct CtorArg##N\
0160 {\
0161    typedef T object_type;\
0162    typedef CtorArg##N self_t;\
0163    \
0164    CtorArg##N ( BOOST_MOVE_UREF##N  )\
0165       BOOST_MOVE_COLON##N BOOST_MOVE_FWD_INIT##N{}\
0166    \
0167    virtual void construct_n(void *mem, std::size_t num)\
0168    {\
0169       std::size_t constructed = 0;\
0170       BOOST_INTERPROCESS_TRY{\
0171          T* memory = static_cast<T*>(mem);\
0172          for (constructed = 0; constructed < num; ++constructed) {\
0173             ::new((void*)memory++) T ( BOOST_MOVE_MFWD##N );\
0174          }\
0175       }\
0176       BOOST_INTERPROCESS_CATCH(...) {\
0177          named_construct_placement_destroy<T>(mem, constructed);\
0178          BOOST_INTERPROCESS_RETHROW\
0179       } BOOST_INTERPROCESS_CATCH_END\
0180    }\
0181    \
0182    private:\
0183    BOOST_MOVE_MREF##N\
0184 };\
0185 //!
0186 BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN)
0187 #undef BOOST_INTERPROCESS_NAMED_PROXY_CTORARGN
0188 
0189 #define BOOST_INTERPROCESS_NAMED_PROXY_CTORITN(N)\
0190 \
0191 template<class T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \
0192 struct CtorIt##N\
0193 {\
0194    typedef T object_type;\
0195    typedef CtorIt##N self_t;\
0196    \
0197    self_t& operator++()\
0198    {  BOOST_MOVE_MINC##N;  return *this;  }\
0199    \
0200    self_t  operator++(int) {  return ++*this; *this;  }\
0201    \
0202    CtorIt##N ( BOOST_MOVE_VAL##N  )\
0203       BOOST_MOVE_COLON##N BOOST_MOVE_VAL_INIT##N{}\
0204    \
0205    virtual void construct_n(void *mem, std::size_t num)\
0206    {\
0207       std::size_t constructed = 0;\
0208       BOOST_INTERPROCESS_TRY{\
0209          T* memory      = static_cast<T*>(mem);\
0210          for(constructed = 0; constructed < num; ++constructed){\
0211             ::new((void*)memory++) T( BOOST_MOVE_MITFWD##N );\
0212             ++(*this);\
0213          }\
0214       }\
0215       BOOST_INTERPROCESS_CATCH(...) {\
0216          named_construct_placement_destroy<T>(mem, constructed);\
0217          BOOST_INTERPROCESS_RETHROW\
0218       } BOOST_INTERPROCESS_CATCH_END\
0219    }\
0220    \
0221    private:\
0222    BOOST_MOVE_MEMB##N\
0223 };\
0224 //!
0225 BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CTORITN)
0226 #undef BOOST_INTERPROCESS_NAMED_PROXY_CTORITN
0227 
0228 //!Describes a proxy class that implements named
0229 //!allocation syntax.
0230 template
0231    < class SegmentManager  //segment manager to construct the object
0232    , class T               //type of object to build
0233    , bool is_iterator      //passing parameters are normal object or iterators?
0234    >
0235 class named_proxy
0236 {
0237    typedef T         object_type;
0238    typedef typename SegmentManager::char_type char_type;
0239    const char_type *    mp_name;
0240    SegmentManager *     mp_mngr;
0241    mutable std::size_t  m_num;
0242    const bool           m_find;
0243    const bool           m_dothrow;
0244 
0245    public:
0246    named_proxy(SegmentManager *mngr, const char_type *name, bool find, bool dothrow)
0247       :  mp_name(name), mp_mngr(mngr), m_num(1)
0248       ,  m_find(find),  m_dothrow(dothrow)
0249    {}
0250 
0251    #define BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR(N)\
0252    \
0253    BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
0254    T *operator()( BOOST_MOVE_UREF##N ) const\
0255    {\
0256       typedef typename if_c<is_iterator \
0257          , CtorIt##N <T BOOST_MOVE_I##N BOOST_MOVE_TARG##N> \
0258          , CtorArg##N<T BOOST_MOVE_I##N BOOST_MOVE_TARG##N> \
0259          >::type ctor_obj_t;\
0260       ctor_obj_t ctor_obj = ctor_obj_t( BOOST_MOVE_FWD##N );\
0261       return mp_mngr->generic_construct(ctor_obj, mp_name, m_num, m_find, m_dothrow);\
0262    }\
0263    //
0264    BOOST_MOVE_ITERATE_0TO9(BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR)
0265    #undef BOOST_INTERPROCESS_NAMED_PROXY_CALL_OPERATOR
0266 
0267    ////////////////////////////////////////////////////////////////////////
0268    //             What the macro should generate (n == 2)
0269    ////////////////////////////////////////////////////////////////////////
0270    //
0271    // template <class P1, class P2>
0272    // T *operator()(P1 &p1, P2 &p2) const
0273    // {
0274    //    typedef CtorArg2
0275    //       <T, is_iterator, P1, P2>
0276    //       ctor_obj_t;
0277    //    ctor_obj_t ctor_obj(p1, p2);
0278    //
0279    //    return mp_mngr->(ctor_obj, mp_name, m_num, m_find, m_dothrow);
0280    // }
0281    //
0282    //////////////////////////////////////////////////////////////////////////
0283 
0284    //This operator allows --> named_new("Name")[3]; <-- syntax
0285    const named_proxy &operator[](std::size_t num) const
0286       {  m_num *= num; return *this;  }
0287 };
0288 
0289 #endif   //#ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
0290 
0291 }}}   //namespace boost { namespace interprocess { namespace ipcdetail {
0292 
0293 #include <boost/interprocess/detail/config_end.hpp>
0294 
0295 #endif //#ifndef BOOST_INTERPROCESS_NAMED_PROXY_HPP