123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
- #define BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
- #include <boost/assert.hpp>
- #include <boost/checked_delete.hpp>
- #include <boost/detail/workaround.hpp>
- #ifndef BOOST_NO_AUTO_PTR
- # include <memory>
- #endif
- namespace boost
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- void sp_scalar_constructor_hook(void * p);
- void sp_scalar_destructor_hook(void * p);
- #endif
- template<class T> class scoped_ptr
- {
- private:
- T * px;
- scoped_ptr(scoped_ptr const &);
- scoped_ptr & operator=(scoped_ptr const &);
- typedef scoped_ptr<T> this_type;
- void operator==( scoped_ptr const& ) const;
- void operator!=( scoped_ptr const& ) const;
- public:
- typedef T element_type;
- explicit scoped_ptr( T * p = 0 ): px( p )
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::sp_scalar_constructor_hook( px );
- #endif
- }
- #ifndef BOOST_NO_AUTO_PTR
- explicit scoped_ptr( std::auto_ptr<T> p ): px( p.release() )
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::sp_scalar_constructor_hook( px );
- #endif
- }
- #endif
- ~scoped_ptr()
- {
- #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
- boost::sp_scalar_destructor_hook( px );
- #endif
- boost::checked_delete( px );
- }
- void reset(T * p = 0)
- {
- BOOST_ASSERT( p == 0 || p != px );
- this_type(p).swap(*this);
- }
- T & operator*() const
- {
- BOOST_ASSERT( px != 0 );
- return *px;
- }
- T * operator->() const
- {
- BOOST_ASSERT( px != 0 );
- return px;
- }
- T * get() const
- {
- return px;
- }
- #include <boost/smart_ptr/detail/operator_bool.hpp>
- void swap(scoped_ptr & b)
- {
- T * tmp = b.px;
- b.px = px;
- px = tmp;
- }
- };
- template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b)
- {
- a.swap(b);
- }
- template<class T> inline T * get_pointer(scoped_ptr<T> const & p)
- {
- return p.get();
- }
- }
- #endif
|