File indexing completed on 2025-12-16 09:53:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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
0034
0035
0036 namespace boost {
0037 namespace interprocess {
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
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
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
0067
0068 explicit scoped_ptr(const pointer &p = 0, const Deleter &d = Deleter())
0069 : Deleter(d), m_ptr(p)
0070 {}
0071
0072
0073
0074 ~scoped_ptr()
0075 {
0076 if(m_ptr){
0077 Deleter &del = static_cast<Deleter&>(*this);
0078 del(m_ptr);
0079 }
0080 }
0081
0082
0083
0084 void reset(const pointer &p = 0)
0085 { BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p).swap(*this); }
0086
0087
0088
0089 void reset(const pointer &p, const Deleter &d)
0090 { BOOST_ASSERT(p == 0 || p != m_ptr); this_type(p, d).swap(*this); }
0091
0092
0093
0094 pointer release() BOOST_NOEXCEPT
0095 { pointer tmp(m_ptr); m_ptr = 0; return tmp; }
0096
0097
0098
0099 reference operator*() const BOOST_NOEXCEPT
0100 { BOOST_ASSERT(m_ptr != 0); return *m_ptr; }
0101
0102
0103
0104 pointer &operator->() BOOST_NOEXCEPT
0105 { BOOST_ASSERT(m_ptr != 0); return m_ptr; }
0106
0107
0108
0109 const pointer &operator->() const BOOST_NOEXCEPT
0110 { BOOST_ASSERT(m_ptr != 0); return m_ptr; }
0111
0112
0113
0114 pointer & get() BOOST_NOEXCEPT
0115 { return m_ptr; }
0116
0117
0118
0119 const pointer & get() const BOOST_NOEXCEPT
0120 { return m_ptr; }
0121
0122 typedef pointer this_type::*unspecified_bool_type;
0123
0124
0125
0126 operator unspecified_bool_type() const BOOST_NOEXCEPT
0127 { return m_ptr == 0? 0: &this_type::m_ptr; }
0128
0129
0130
0131 bool operator! () const BOOST_NOEXCEPT
0132 { return m_ptr == 0; }
0133
0134
0135
0136 void swap(scoped_ptr & b) BOOST_NOEXCEPT
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
0146 };
0147
0148
0149
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
0155
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 }
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
0171
0172 }
0173
0174 #include <boost/interprocess/detail/config_end.hpp>
0175
0176 #endif