123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- #ifndef BOOST_INTERPROCESS_INTRUSIVE_PTR_HPP_INCLUDED
- #define BOOST_INTERPROCESS_INTRUSIVE_PTR_HPP_INCLUDED
- #ifndef BOOST_CONFIG_HPP
- # include <boost/config.hpp>
- #endif
- #
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- #include <boost/interprocess/detail/config_begin.hpp>
- #include <boost/interprocess/detail/workaround.hpp>
- #include <boost/assert.hpp>
- #include <boost/interprocess/detail/utilities.hpp>
- #include <boost/intrusive/pointer_traits.hpp>
- #include <boost/move/adl_move_swap.hpp>
- #include <boost/move/core.hpp>
- #include <iosfwd> // for std::basic_ostream
- #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
- namespace boost {
- namespace interprocess {
- template<class T, class VoidPointer>
- class intrusive_ptr
- {
- public:
-
- typedef typename boost::intrusive::
- pointer_traits<VoidPointer>::template
- rebind_pointer<T>::type pointer;
-
- typedef T element_type;
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- private:
- typedef VoidPointer VP;
- typedef intrusive_ptr this_type;
- typedef pointer this_type::*unspecified_bool_type;
- #endif
- BOOST_COPYABLE_AND_MOVABLE(intrusive_ptr)
- public:
-
-
- intrusive_ptr() BOOST_NOEXCEPT
- : m_ptr(0)
- {}
-
-
-
- intrusive_ptr(const pointer &p, bool add_ref = true) BOOST_NOEXCEPT
- : m_ptr(p)
- {
- if(m_ptr != 0 && add_ref) intrusive_ptr_add_ref(ipcdetail::to_raw_pointer(m_ptr));
- }
-
-
- intrusive_ptr(intrusive_ptr const & rhs) BOOST_NOEXCEPT
- : m_ptr(rhs.m_ptr)
- {
- if(m_ptr != 0) intrusive_ptr_add_ref(ipcdetail::to_raw_pointer(m_ptr));
- }
-
- intrusive_ptr(BOOST_RV_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
- : m_ptr(rhs.m_ptr)
- {
- rhs.m_ptr = 0;
- }
-
-
- template<class U> intrusive_ptr(intrusive_ptr<U, VP> const & rhs) BOOST_NOEXCEPT
- : m_ptr(rhs.get())
- {
- if(m_ptr != 0) intrusive_ptr_add_ref(ipcdetail::to_raw_pointer(m_ptr));
- }
-
- ~intrusive_ptr()
- {
- reset();
- }
-
-
- intrusive_ptr & operator=(BOOST_COPY_ASSIGN_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
- {
- this_type(rhs).swap(*this);
- return *this;
- }
-
-
- intrusive_ptr & operator=(BOOST_RV_REF(intrusive_ptr) rhs) BOOST_NOEXCEPT
- {
- rhs.swap(*this);
- rhs.reset();
- return *this;
- }
-
-
- template<class U> intrusive_ptr & operator=(intrusive_ptr<U, VP> const & rhs) BOOST_NOEXCEPT
- {
- this_type(rhs).swap(*this);
- return *this;
- }
-
-
- intrusive_ptr & operator=(pointer rhs) BOOST_NOEXCEPT
- {
- this_type(rhs).swap(*this);
- return *this;
- }
-
-
- void reset() BOOST_NOEXCEPT {
- if(m_ptr != 0) {
- pointer ptr = m_ptr;
- m_ptr = 0;
- intrusive_ptr_release(ipcdetail::to_raw_pointer(ptr));
- }
- }
-
-
- pointer &get() BOOST_NOEXCEPT
- { return m_ptr; }
-
-
- const pointer &get() const BOOST_NOEXCEPT
- { return m_ptr; }
-
-
- T & operator*() const BOOST_NOEXCEPT
- { return *m_ptr; }
-
-
- const pointer &operator->() const BOOST_NOEXCEPT
- { return m_ptr; }
-
-
- pointer &operator->() BOOST_NOEXCEPT
- { return m_ptr; }
-
-
- operator unspecified_bool_type () const BOOST_NOEXCEPT
- { return m_ptr == 0? 0: &this_type::m_ptr; }
-
-
- bool operator! () const BOOST_NOEXCEPT
- { return m_ptr == 0; }
-
-
- void swap(intrusive_ptr & rhs) BOOST_NOEXCEPT
- { ::boost::adl_move_swap(m_ptr, rhs.m_ptr); }
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- private:
- pointer m_ptr;
- #endif
- };
- template<class T, class U, class VP> inline
- bool operator==(intrusive_ptr<T, VP> const & a,
- intrusive_ptr<U, VP> const & b) BOOST_NOEXCEPT
- { return a.get() == b.get(); }
- template<class T, class U, class VP> inline
- bool operator!=(intrusive_ptr<T, VP> const & a,
- intrusive_ptr<U, VP> const & b) BOOST_NOEXCEPT
- { return a.get() != b.get(); }
- template<class T, class VP> inline
- bool operator==(intrusive_ptr<T, VP> const & a,
- const typename intrusive_ptr<T, VP>::pointer &b) BOOST_NOEXCEPT
- { return a.get() == b; }
- template<class T, class VP> inline
- bool operator!=(intrusive_ptr<T, VP> const & a,
- const typename intrusive_ptr<T, VP>::pointer &b) BOOST_NOEXCEPT
- { return a.get() != b; }
- template<class T, class VP> inline
- bool operator==(const typename intrusive_ptr<T, VP>::pointer &a,
- intrusive_ptr<T, VP> const & b) BOOST_NOEXCEPT
- { return a == b.get(); }
- template<class T, class VP> inline
- bool operator!=(const typename intrusive_ptr<T, VP>::pointer &a,
- intrusive_ptr<T, VP> const & b) BOOST_NOEXCEPT
- { return a != b.get(); }
- template<class T, class VP> inline
- bool operator<(intrusive_ptr<T, VP> const & a,
- intrusive_ptr<T, VP> const & b) BOOST_NOEXCEPT
- {
- return std::less<typename intrusive_ptr<T, VP>::pointer>()
- (a.get(), b.get());
- }
- template<class T, class VP> inline
- void swap(intrusive_ptr<T, VP> & lhs,
- intrusive_ptr<T, VP> & rhs) BOOST_NOEXCEPT
- { lhs.swap(rhs); }
- template<class E, class T, class Y, class VP>
- inline std::basic_ostream<E, T> & operator<<
- (std::basic_ostream<E, T> & os, intrusive_ptr<Y, VP> const & p) BOOST_NOEXCEPT
- { os << p.get(); return os; }
- template<class T, class VP>
- inline typename boost::interprocess::intrusive_ptr<T, VP>::pointer
- to_raw_pointer(intrusive_ptr<T, VP> p) BOOST_NOEXCEPT
- { return p.get(); }
- }
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- #if defined(_MSC_VER) && (_MSC_VER < 1400)
- template<class T, class VP>
- inline T *to_raw_pointer(boost::interprocess::intrusive_ptr<T, VP> p) BOOST_NOEXCEPT
- { return p.get(); }
- #endif
- #endif
- }
- #include <boost/interprocess/detail/config_end.hpp>
- #endif
|