Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:53:29

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // This file is the adaptation for Interprocess of boost/scoped_ptr.hpp
0004 //
0005 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
0006 // (C) Copyright Peter Dimov 2001, 2002
0007 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
0008 // Software License, Version 1.0. (See accompanying file
0009 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // See http://www.boost.org/libs/interprocess for documentation.
0012 //
0013 //////////////////////////////////////////////////////////////////////////////
0014 
0015 #ifndef BOOST_INTERPROCESS_SCOPED_PTR_HPP_INCLUDED
0016 #define BOOST_INTERPROCESS_SCOPED_PTR_HPP_INCLUDED
0017 
0018 #ifndef BOOST_CONFIG_HPP
0019 #  include <boost/config.hpp>
0020 #endif
0021 #
0022 #if defined(BOOST_HAS_PRAGMA_ONCE)
0023 #  pragma once
0024 #endif
0025 
0026 #include <boost/interprocess/detail/config_begin.hpp>
0027 #include <boost/interprocess/detail/workaround.hpp>
0028 #include <boost/interprocess/detail/pointer_type.hpp>
0029 #include <boost/interprocess/detail/utilities.hpp>
0030 #include <boost/assert.hpp>
0031 #include <boost/move/adl_move_swap.hpp>
0032 
0033 //!\file
0034 //!Describes the smart pointer scoped_ptr
0035 
0036 namespace boost {
0037 namespace interprocess {
0038 
0039 //!scoped_ptr stores a pointer to a dynamically allocated object.
0040 //!The object pointed to is guaranteed to be deleted, either on destruction
0041 //!of the scoped_ptr, or via an explicit reset. The user can avoid this
0042 //!deletion using release().
0043 //!scoped_ptr is parameterized on T (the type of the object pointed to) and
0044 //!Deleter (the functor to be executed to delete the internal pointer).
0045 //!The internal pointer will be of the same pointer type as typename
0046 //!Deleter::pointer type (that is, if typename Deleter::pointer is
0047 //!offset_ptr<void>, the internal pointer will be offset_ptr<T>).
0048 template<class T, class Deleter>
0049 class scoped_ptr
0050    : private Deleter
0051 {
0052    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0053    scoped_ptr(scoped_ptr const &);
0054    scoped_ptr & operator=(scoped_ptr const &);
0055 
0056    typedef scoped_ptr<T, Deleter> this_type;
0057    typedef typename ipcdetail::add_reference<T>::type reference;
0058    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0059 
0060    public:
0061 
0062    typedef T element_type;
0063    typedef Deleter deleter_type;
0064    typedef typename ipcdetail::pointer_type<T, Deleter>::type pointer;
0065 
0066    //!Constructs a scoped_ptr, storing a copy of p(which can be 0) and d.
0067    //!Does not throw.
0068    explicit scoped_ptr(const pointer &p = 0, const Deleter &d = Deleter())
0069       : Deleter(d), m_ptr(p) // throws if pointer/Deleter copy ctor throws
0070    {}
0071 
0072    //!If the stored pointer is not 0, destroys the object pointed to by the stored pointer.
0073    //!calling the operator() of the stored deleter. Never throws
0074    ~scoped_ptr()
0075    {
0076       if(m_ptr){
0077          Deleter &del = static_cast<Deleter&>(*this);
0078          del(m_ptr);
0079       }
0080    }
0081 
0082    //!Deletes the object pointed to by the stored pointer and then
0083    //!stores a copy of p. Never throws
0084    void reset(const pointer &p = 0) // never throws
0085    {  BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p).swap(*this);  }
0086 
0087    //!Deletes the object pointed to by the stored pointer and then
0088    //!stores a copy of p and a copy of d.
0089    void reset(const pointer &p, const Deleter &d) // never throws
0090    {  BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p, d).swap(*this);  }
0091 
0092    //!Assigns internal pointer as 0 and returns previous pointer. This will
0093    //!avoid deletion on destructor
0094    pointer release() BOOST_NOEXCEPT
0095    {  pointer tmp(m_ptr);  m_ptr = 0;  return tmp; }
0096 
0097    //!Returns a reference to the object pointed to by the stored pointer.
0098    //!Never throws.
0099    reference operator*() const BOOST_NOEXCEPT
0100    {  BOOST_ASSERT(m_ptr != 0);  return *m_ptr; }
0101 
0102    //!Returns the internal stored pointer.
0103    //!Never throws.
0104    pointer &operator->() BOOST_NOEXCEPT
0105    {  BOOST_ASSERT(m_ptr != 0);  return m_ptr;  }
0106 
0107    //!Returns the internal stored pointer.
0108    //!Never throws.
0109    const pointer &operator->() const BOOST_NOEXCEPT
0110    {  BOOST_ASSERT(m_ptr != 0);  return m_ptr;  }
0111 
0112    //!Returns the stored pointer.
0113    //!Never throws.
0114    pointer & get() BOOST_NOEXCEPT
0115    {  return m_ptr;  }
0116 
0117    //!Returns the stored pointer.
0118    //!Never throws.
0119    const pointer & get() const BOOST_NOEXCEPT
0120    {  return m_ptr;  }
0121 
0122    typedef pointer this_type::*unspecified_bool_type;
0123 
0124    //!Conversion to bool
0125    //!Never throws
0126    operator unspecified_bool_type() const BOOST_NOEXCEPT
0127    {  return m_ptr == 0? 0: &this_type::m_ptr;  }
0128 
0129    //!Returns true if the stored pointer is 0.
0130    //!Never throws.
0131    bool operator! () const BOOST_NOEXCEPT // never throws
0132    {  return m_ptr == 0;   }
0133 
0134    //!Exchanges the internal pointer and deleter with other scoped_ptr
0135    //!Never throws.
0136    void swap(scoped_ptr & b) BOOST_NOEXCEPT // never throws
0137    {
0138       ::boost::adl_move_swap(static_cast<Deleter&>(*this), static_cast<Deleter&>(b));
0139       ::boost::adl_move_swap(m_ptr, b.m_ptr);
0140    }
0141 
0142    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0143    private:
0144    pointer m_ptr;
0145    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0146 };
0147 
0148 //!Exchanges the internal pointer and deleter with other scoped_ptr
0149 //!Never throws.
0150 template<class T, class D> inline
0151 void swap(scoped_ptr<T, D> & a, scoped_ptr<T, D> & b) BOOST_NOEXCEPT
0152 {  a.swap(b); }
0153 
0154 //!Returns a copy of the stored pointer
0155 //!Never throws
0156 template<class T, class D> inline
0157 typename scoped_ptr<T, D>::pointer to_raw_pointer(scoped_ptr<T, D> const & p)
0158 {  return p.get();   }
0159 
0160 } // namespace interprocess
0161 
0162 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0163 
0164 #if defined(_MSC_VER) && (_MSC_VER < 1400)
0165 template<class T, class D> inline
0166 T *to_raw_pointer(boost::interprocess::scoped_ptr<T, D> const & p)
0167 {  return p.get();   }
0168 #endif
0169 
0170 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0171 
0172 } // namespace boost
0173 
0174 #include <boost/interprocess/detail/config_end.hpp>
0175 
0176 #endif // #ifndef BOOST_INTERPROCESS_SCOPED_PTR_HPP_INCLUDED