1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/scoped_ptr.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,157 @@
1.4 +#ifndef BOOST_SCOPED_PTR_HPP_INCLUDED
1.5 +#define BOOST_SCOPED_PTR_HPP_INCLUDED
1.6 +
1.7 +// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
1.8 +// Copyright (c) 2001, 2002 Peter Dimov
1.9 +//
1.10 +// Distributed under the Boost Software License, Version 1.0. (See
1.11 +// accompanying file LICENSE_1_0.txt or copy at
1.12 +// http://www.boost.org/LICENSE_1_0.txt)
1.13 +//
1.14 +// http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
1.15 +//
1.16 +
1.17 +#include <boost/assert.hpp>
1.18 +#include <boost/checked_delete.hpp>
1.19 +#include <boost/detail/workaround.hpp>
1.20 +
1.21 +#ifndef BOOST_NO_AUTO_PTR
1.22 +# include <memory> // for std::auto_ptr
1.23 +#endif
1.24 +
1.25 +namespace boost
1.26 +{
1.27 +
1.28 +// Debug hooks
1.29 +
1.30 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.31 +
1.32 +void sp_scalar_constructor_hook(void * p);
1.33 +void sp_scalar_destructor_hook(void * p);
1.34 +
1.35 +#endif
1.36 +
1.37 +// scoped_ptr mimics a built-in pointer except that it guarantees deletion
1.38 +// of the object pointed to, either on destruction of the scoped_ptr or via
1.39 +// an explicit reset(). scoped_ptr is a simple solution for simple needs;
1.40 +// use shared_ptr or std::auto_ptr if your needs are more complex.
1.41 +
1.42 +template<class T> class scoped_ptr // noncopyable
1.43 +{
1.44 +private:
1.45 +
1.46 + T * ptr;
1.47 +
1.48 + scoped_ptr(scoped_ptr const &);
1.49 + scoped_ptr & operator=(scoped_ptr const &);
1.50 +
1.51 + typedef scoped_ptr<T> this_type;
1.52 +
1.53 +public:
1.54 +
1.55 + typedef T element_type;
1.56 +
1.57 + explicit scoped_ptr(T * p = 0): ptr(p) // never throws
1.58 + {
1.59 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.60 + boost::sp_scalar_constructor_hook(ptr);
1.61 +#endif
1.62 + }
1.63 +
1.64 +#ifndef BOOST_NO_AUTO_PTR
1.65 +
1.66 + explicit scoped_ptr(std::auto_ptr<T> p): ptr(p.release()) // never throws
1.67 + {
1.68 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.69 + boost::sp_scalar_constructor_hook(ptr);
1.70 +#endif
1.71 + }
1.72 +
1.73 +#endif
1.74 +
1.75 + ~scoped_ptr() // never throws
1.76 + {
1.77 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.78 + boost::sp_scalar_destructor_hook(ptr);
1.79 +#endif
1.80 + boost::checked_delete(ptr);
1.81 + }
1.82 +
1.83 + void reset(T * p = 0) // never throws
1.84 + {
1.85 + BOOST_ASSERT(p == 0 || p != ptr); // catch self-reset errors
1.86 + this_type(p).swap(*this);
1.87 + }
1.88 +
1.89 + T & operator*() const // never throws
1.90 + {
1.91 + BOOST_ASSERT(ptr != 0);
1.92 + return *ptr;
1.93 + }
1.94 +
1.95 + T * operator->() const // never throws
1.96 + {
1.97 + BOOST_ASSERT(ptr != 0);
1.98 + return ptr;
1.99 + }
1.100 +
1.101 + T * get() const // never throws
1.102 + {
1.103 + return ptr;
1.104 + }
1.105 +
1.106 + // implicit conversion to "bool"
1.107 +
1.108 +#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
1.109 +
1.110 + operator bool () const
1.111 + {
1.112 + return ptr != 0;
1.113 + }
1.114 +
1.115 +#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
1.116 + typedef T * (this_type::*unspecified_bool_type)() const;
1.117 +
1.118 + operator unspecified_bool_type() const // never throws
1.119 + {
1.120 + return ptr == 0? 0: &this_type::get;
1.121 + }
1.122 +
1.123 +#else
1.124 + typedef T * this_type::*unspecified_bool_type;
1.125 +
1.126 + operator unspecified_bool_type() const // never throws
1.127 + {
1.128 + return ptr == 0? 0: &this_type::ptr;
1.129 + }
1.130 +
1.131 +#endif
1.132 +
1.133 + bool operator! () const // never throws
1.134 + {
1.135 + return ptr == 0;
1.136 + }
1.137 +
1.138 + void swap(scoped_ptr & b) // never throws
1.139 + {
1.140 + T * tmp = b.ptr;
1.141 + b.ptr = ptr;
1.142 + ptr = tmp;
1.143 + }
1.144 +};
1.145 +
1.146 +template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) // never throws
1.147 +{
1.148 + a.swap(b);
1.149 +}
1.150 +
1.151 +// get_pointer(p) is a generic way to say p.get()
1.152 +
1.153 +template<class T> inline T * get_pointer(scoped_ptr<T> const & p)
1.154 +{
1.155 + return p.get();
1.156 +}
1.157 +
1.158 +} // namespace boost
1.159 +
1.160 +#endif // #ifndef BOOST_SCOPED_PTR_HPP_INCLUDED