1 #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
\r
2 #define BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
\r
4 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
\r
5 // Copyright (c) 2001, 2002 Peter Dimov
\r
7 // Distributed under the Boost Software License, Version 1.0. (See
\r
8 // accompanying file LICENSE_1_0.txt or copy at
\r
9 // http://www.boost.org/LICENSE_1_0.txt)
\r
11 // http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
\r
14 #include <boost/assert.hpp>
\r
15 #include <boost/checked_delete.hpp>
\r
16 #include <boost/detail/workaround.hpp>
\r
18 #ifndef BOOST_NO_AUTO_PTR
\r
19 # include <memory> // for std::auto_ptr
\r
27 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
\r
29 void sp_scalar_constructor_hook(void * p);
\r
30 void sp_scalar_destructor_hook(void * p);
\r
34 // scoped_ptr mimics a built-in pointer except that it guarantees deletion
\r
35 // of the object pointed to, either on destruction of the scoped_ptr or via
\r
36 // an explicit reset(). scoped_ptr is a simple solution for simple needs;
\r
37 // use shared_ptr or std::auto_ptr if your needs are more complex.
\r
39 template<class T> class scoped_ptr // noncopyable
\r
45 scoped_ptr(scoped_ptr const &);
\r
46 scoped_ptr & operator=(scoped_ptr const &);
\r
48 typedef scoped_ptr<T> this_type;
\r
50 void operator==( scoped_ptr const& ) const;
\r
51 void operator!=( scoped_ptr const& ) const;
\r
55 typedef T element_type;
\r
57 explicit scoped_ptr( T * p = 0 ): px( p ) // never throws
\r
59 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
\r
60 boost::sp_scalar_constructor_hook( px );
\r
64 #ifndef BOOST_NO_AUTO_PTR
\r
66 explicit scoped_ptr( std::auto_ptr<T> p ): px( p.release() ) // never throws
\r
68 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
\r
69 boost::sp_scalar_constructor_hook( px );
\r
75 ~scoped_ptr() // never throws
\r
77 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
\r
78 boost::sp_scalar_destructor_hook( px );
\r
80 boost::checked_delete( px );
\r
83 void reset(T * p = 0) // never throws
\r
85 BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
\r
86 this_type(p).swap(*this);
\r
89 T & operator*() const // never throws
\r
91 BOOST_ASSERT( px != 0 );
\r
95 T * operator->() const // never throws
\r
97 BOOST_ASSERT( px != 0 );
\r
101 T * get() const // never throws
\r
106 // implicit conversion to "bool"
\r
107 #include <boost/smart_ptr/detail/operator_bool.hpp>
\r
109 void swap(scoped_ptr & b) // never throws
\r
117 template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) // never throws
\r
122 // get_pointer(p) is a generic way to say p.get()
\r
124 template<class T> inline T * get_pointer(scoped_ptr<T> const & p)
\r
129 } // namespace boost
\r
131 #endif // #ifndef BOOST_SMART_PTR_SCOPED_PTR_HPP_INCLUDED
\r