1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
12 #define BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/interprocess/creation_tags.hpp>
25 #include <boost/interprocess/detail/managed_memory_impl.hpp>
26 #include <boost/move/utility_core.hpp>
27 #include <boost/assert.hpp>
28 //These includes needed to fulfill default template parameters of
29 //predeclarations in interprocess_fwd.hpp
30 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
31 #include <boost/interprocess/sync/mutex_family.hpp>
32 #include <boost/interprocess/indexes/iset_index.hpp>
35 //!Describes a named user memory allocation user class.
38 namespace interprocess {
40 //!A basic user memory named object creation class. Inherits all
41 //!basic functionality from
42 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>*/
46 class AllocationAlgorithm,
47 template<class IndexConfig> class IndexType
49 class basic_managed_external_buffer
50 : public ipcdetail::basic_managed_memory_impl <CharType, AllocationAlgorithm, IndexType>
52 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
53 typedef ipcdetail::basic_managed_memory_impl
54 <CharType, AllocationAlgorithm, IndexType> base_t;
55 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_external_buffer)
56 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
59 typedef typename base_t::size_type size_type;
61 //!Default constructor. Does nothing.
62 //!Useful in combination with move semantics
63 basic_managed_external_buffer()
66 //!Creates and places the segment manager. This can throw
67 basic_managed_external_buffer
68 (create_only_t, void *addr, size_type size)
70 //Check if alignment is correct
71 BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
72 if(!base_t::create_impl(addr, size)){
73 throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
77 //!Creates and places the segment manager. This can throw
78 basic_managed_external_buffer
79 (open_only_t, void *addr, size_type size)
81 //Check if alignment is correct
82 BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
83 if(!base_t::open_impl(addr, size)){
84 throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
88 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
89 basic_managed_external_buffer(BOOST_RV_REF(basic_managed_external_buffer) moved)
94 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
95 basic_managed_external_buffer &operator=(BOOST_RV_REF(basic_managed_external_buffer) moved)
97 basic_managed_external_buffer tmp(boost::move(moved));
102 void grow(size_type extra_bytes)
103 { base_t::grow(extra_bytes); }
105 //!Swaps the ownership of the managed heap memories managed by *this and other.
107 void swap(basic_managed_external_buffer &other)
108 { base_t::swap(other); }
111 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
113 //!Typedef for a default basic_managed_external_buffer
114 //!of narrow characters
115 typedef basic_managed_external_buffer
117 ,rbtree_best_fit<null_mutex_family>
119 managed_external_buffer;
121 //!Typedef for a default basic_managed_external_buffer
122 //!of wide characters
123 typedef basic_managed_external_buffer
125 ,rbtree_best_fit<null_mutex_family>
127 wmanaged_external_buffer;
129 #endif //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
131 } //namespace interprocess {
132 } //namespace boost {
134 #include <boost/interprocess/detail/config_end.hpp>
136 #endif //BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP