123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #ifndef BOOST_INTERPROCESS_SCOPED_PTR_HPP_INCLUDED
- #define BOOST_INTERPROCESS_SCOPED_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/interprocess/detail/pointer_type.hpp>
- #include <boost/interprocess/detail/utilities.hpp>
- #include <boost/assert.hpp>
- #include <boost/move/adl_move_swap.hpp>
- namespace boost {
- namespace interprocess {
- template<class T, class Deleter>
- class scoped_ptr
- : private Deleter
- {
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- scoped_ptr(scoped_ptr const &);
- scoped_ptr & operator=(scoped_ptr const &);
- typedef scoped_ptr<T, Deleter> this_type;
- typedef typename ipcdetail::add_reference<T>::type reference;
- #endif
- public:
- typedef T element_type;
- typedef Deleter deleter_type;
- typedef typename ipcdetail::pointer_type<T, Deleter>::type pointer;
-
-
- explicit scoped_ptr(const pointer &p = 0, const Deleter &d = Deleter())
- : Deleter(d), m_ptr(p)
- {}
-
-
- ~scoped_ptr()
- {
- if(m_ptr){
- Deleter &del = static_cast<Deleter&>(*this);
- del(m_ptr);
- }
- }
-
-
- void reset(const pointer &p = 0)
- { BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p).swap(*this); }
-
-
- void reset(const pointer &p, const Deleter &d)
- { BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p, d).swap(*this); }
-
-
- pointer release() BOOST_NOEXCEPT
- { pointer tmp(m_ptr); m_ptr = 0; return tmp; }
-
-
- reference operator*() const BOOST_NOEXCEPT
- { BOOST_ASSERT(m_ptr != 0); return *m_ptr; }
-
-
- pointer &operator->() BOOST_NOEXCEPT
- { BOOST_ASSERT(m_ptr != 0); return m_ptr; }
-
-
- const pointer &operator->() const BOOST_NOEXCEPT
- { BOOST_ASSERT(m_ptr != 0); return m_ptr; }
-
-
- pointer & get() BOOST_NOEXCEPT
- { return m_ptr; }
-
-
- const pointer & get() const BOOST_NOEXCEPT
- { return m_ptr; }
- typedef pointer this_type::*unspecified_bool_type;
-
-
- 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(scoped_ptr & b) BOOST_NOEXCEPT
- {
- ::boost::adl_move_swap(static_cast<Deleter&>(*this), static_cast<Deleter&>(b));
- ::boost::adl_move_swap(m_ptr, b.m_ptr);
- }
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- private:
- pointer m_ptr;
- #endif
- };
- template<class T, class D> inline
- void swap(scoped_ptr<T, D> & a, scoped_ptr<T, D> & b) BOOST_NOEXCEPT
- { a.swap(b); }
- template<class T, class D> inline
- typename scoped_ptr<T, D>::pointer to_raw_pointer(scoped_ptr<T, D> const & p)
- { return p.get(); }
- }
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- #if defined(_MSC_VER) && (_MSC_VER < 1400)
- template<class T, class D> inline
- T *to_raw_pointer(boost::interprocess::scoped_ptr<T, D> const & p)
- { return p.get(); }
- #endif
- #endif
- }
- #include <boost/interprocess/detail/config_end.hpp>
- #endif
|