1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/scoped_array.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,135 @@
1.4 +#ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED
1.5 +#define BOOST_SCOPED_ARRAY_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_array.htm
1.15 +//
1.16 +
1.17 +#include <boost/assert.hpp>
1.18 +#include <boost/checked_delete.hpp>
1.19 +#include <boost/config.hpp> // in case ptrdiff_t not in std
1.20 +
1.21 +#include <boost/detail/workaround.hpp>
1.22 +
1.23 +#include <cstddef> // for std::ptrdiff_t
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_array_constructor_hook(void * p);
1.33 +void sp_array_destructor_hook(void * p);
1.34 +
1.35 +#endif
1.36 +
1.37 +// scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to
1.38 +// is guaranteed, either on destruction of the scoped_array or via an explicit
1.39 +// reset(). Use shared_array or std::vector if your needs are more complex.
1.40 +
1.41 +template<class T> class scoped_array // noncopyable
1.42 +{
1.43 +private:
1.44 +
1.45 + T * ptr;
1.46 +
1.47 + scoped_array(scoped_array const &);
1.48 + scoped_array & operator=(scoped_array const &);
1.49 +
1.50 + typedef scoped_array<T> this_type;
1.51 +
1.52 +public:
1.53 +
1.54 + typedef T element_type;
1.55 +
1.56 + explicit scoped_array(T * p = 0) : ptr(p) // never throws
1.57 + {
1.58 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.59 + boost::sp_array_constructor_hook(ptr);
1.60 +#endif
1.61 + }
1.62 +
1.63 + ~scoped_array() // never throws
1.64 + {
1.65 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
1.66 + boost::sp_array_destructor_hook(ptr);
1.67 +#endif
1.68 + boost::checked_array_delete(ptr);
1.69 + }
1.70 +
1.71 + void reset(T * p = 0) // never throws
1.72 + {
1.73 + BOOST_ASSERT(p == 0 || p != ptr); // catch self-reset errors
1.74 + this_type(p).swap(*this);
1.75 + }
1.76 +
1.77 + T & operator[](std::ptrdiff_t i) const // never throws
1.78 + {
1.79 + BOOST_ASSERT(ptr != 0);
1.80 + BOOST_ASSERT(i >= 0);
1.81 + return ptr[i];
1.82 + }
1.83 +
1.84 + T * get() const // never throws
1.85 + {
1.86 + return ptr;
1.87 + }
1.88 +
1.89 + // implicit conversion to "bool"
1.90 +
1.91 +#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
1.92 +
1.93 + operator bool () const
1.94 + {
1.95 + return ptr != 0;
1.96 + }
1.97 +
1.98 +#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
1.99 + typedef T * (this_type::*unspecified_bool_type)() const;
1.100 +
1.101 + operator unspecified_bool_type() const // never throws
1.102 + {
1.103 + return ptr == 0? 0: &this_type::get;
1.104 + }
1.105 +
1.106 +#else
1.107 +
1.108 + typedef T * this_type::*unspecified_bool_type;
1.109 +
1.110 + operator unspecified_bool_type() const // never throws
1.111 + {
1.112 + return ptr == 0? 0: &this_type::ptr;
1.113 + }
1.114 +
1.115 +#endif
1.116 +
1.117 + bool operator! () const // never throws
1.118 + {
1.119 + return ptr == 0;
1.120 + }
1.121 +
1.122 + void swap(scoped_array & b) // never throws
1.123 + {
1.124 + T * tmp = b.ptr;
1.125 + b.ptr = ptr;
1.126 + ptr = tmp;
1.127 + }
1.128 +
1.129 +};
1.130 +
1.131 +template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws
1.132 +{
1.133 + a.swap(b);
1.134 +}
1.135 +
1.136 +} // namespace boost
1.137 +
1.138 +#endif // #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED