• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-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_IN_PLACE_INTERFACE_HPP
12 #define BOOST_INTERPROCESS_IN_PLACE_INTERFACE_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/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/interprocess/detail/type_traits.hpp>
25 #include <boost/container/detail/type_traits.hpp>  //alignment_of, aligned_storage
26 #include <typeinfo>  //typeid
27 
28 //!\file
29 //!Describes an abstract interface for placement construction and destruction.
30 
31 namespace boost {
32 namespace interprocess {
33 namespace ipcdetail {
34 
35 struct in_place_interface
36 {
in_place_interfaceboost::interprocess::ipcdetail::in_place_interface37    in_place_interface(std::size_t alignm, std::size_t sz, const char *tname)
38    :  alignment(alignm), size(sz), type_name(tname)
39    {}
40 
41    std::size_t alignment;
42    std::size_t size;
43    const char *type_name;
44 
45    virtual void construct_n(void *mem, std::size_t num, std::size_t &constructed) = 0;
46    virtual void destroy_n(void *mem, std::size_t num, std::size_t &destroyed) = 0;
~in_place_interfaceboost::interprocess::ipcdetail::in_place_interface47    virtual ~in_place_interface(){}
48 };
49 
50 template<class T>
51 struct placement_destroy :  public in_place_interface
52 {
placement_destroyboost::interprocess::ipcdetail::placement_destroy53    placement_destroy()
54       :  in_place_interface(::boost::container::dtl::alignment_of<T>::value, sizeof(T), typeid(T).name())
55    {}
56 
destroy_nboost::interprocess::ipcdetail::placement_destroy57    virtual void destroy_n(void *mem, std::size_t num, std::size_t &destroyed)
58    {
59       T* memory = static_cast<T*>(mem);
60       for(destroyed = 0; destroyed < num; ++destroyed)
61          (memory++)->~T();
62    }
63 
construct_nboost::interprocess::ipcdetail::placement_destroy64    virtual void construct_n(void *, std::size_t, std::size_t &) {}
65 
66    private:
destroyboost::interprocess::ipcdetail::placement_destroy67    void destroy(void *mem)
68    {  static_cast<T*>(mem)->~T();   }
69 };
70 
71 }
72 }
73 }   //namespace boost { namespace interprocess { namespace ipcdetail {
74 
75 #include <boost/interprocess/detail/config_end.hpp>
76 
77 #endif //#ifndef BOOST_INTERPROCESS_IN_PLACE_INTERFACE_HPP
78