| 1 |
#ifndef BOOST_SCOPED_PTR_HPP_INCLUDED |
| 2 |
#define BOOST_SCOPED_PTR_HPP_INCLUDED |
| 3 |
|
| 4 |
// (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. |
| 5 |
// Copyright (c) 2001, 2002 Peter Dimov |
| 6 |
// |
| 7 |
// Permission to copy, use, modify, sell and distribute this software |
| 8 |
// is granted provided this copyright notice appears in all copies. |
| 9 |
// This software is provided "as is" without express or implied |
| 10 |
// warranty, and with no claim as to its suitability for any purpose. |
| 11 |
// |
| 12 |
// http://www.boost.org/libs/smart_ptr/scoped_ptr.htm |
| 13 |
// |
| 14 |
|
| 15 |
// From Boost 1.31.0, http://www.boost.org |
| 16 |
// Modified by Ori Peleg for use in NSIS, to reduce the required Boost includes |
| 17 |
|
| 18 |
#include <cassert> |
| 19 |
#include "checked_delete.hpp" |
| 20 |
#include "detail/workaround.hpp" |
| 21 |
|
| 22 |
#include <memory> // for std::auto_ptr or std::unique_ptr |
| 23 |
|
| 24 |
// std::auto_ptr was deprecated in C++11 and removed in C++17 |
| 25 |
namespace NSIS { namespace CXX { |
| 26 |
#if __cplusplus >= 201103L |
| 27 |
template<class T> struct stdsmartptr { typedef std::unique_ptr<T> type; }; |
| 28 |
#else |
| 29 |
template<class T> struct stdsmartptr { typedef std::auto_ptr<T> type; }; |
| 30 |
#endif |
| 31 |
}} //~ NSIS::CXX |
| 32 |
|
| 33 |
namespace boost |
| 34 |
{ |
| 35 |
|
| 36 |
// scoped_ptr mimics a built-in pointer except that it guarantees deletion |
| 37 |
// of the object pointed to, either on destruction of the scoped_ptr or via |
| 38 |
// an explicit reset(). scoped_ptr is a simple solution for simple needs; |
| 39 |
// use shared_ptr or std::auto_ptr if your needs are more complex. |
| 40 |
|
| 41 |
template<class T> class scoped_ptr // noncopyable |
| 42 |
{ |
| 43 |
private: |
| 44 |
|
| 45 |
T * ptr; |
| 46 |
|
| 47 |
scoped_ptr(scoped_ptr const &); |
| 48 |
scoped_ptr & operator=(scoped_ptr const &); |
| 49 |
|
| 50 |
typedef scoped_ptr<T> this_type; |
| 51 |
|
| 52 |
public: |
| 53 |
|
| 54 |
typedef T element_type; |
| 55 |
|
| 56 |
explicit scoped_ptr(T * p = 0): ptr(p) // never throws |
| 57 |
{ |
| 58 |
} |
| 59 |
|
| 60 |
explicit scoped_ptr(typename NSIS::CXX::stdsmartptr<T>::type p): ptr(p.release()) // never throws |
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
~scoped_ptr() // never throws |
| 65 |
{ |
| 66 |
boost::checked_delete(ptr); |
| 67 |
} |
| 68 |
|
| 69 |
void reset(T * p = 0) // never throws |
| 70 |
{ |
| 71 |
assert(p == 0 || p != ptr); // catch self-reset errors |
| 72 |
this_type(p).swap(*this); |
| 73 |
} |
| 74 |
|
| 75 |
T & operator*() const // never throws |
| 76 |
{ |
| 77 |
assert(ptr != 0); |
| 78 |
return *ptr; |
| 79 |
} |
| 80 |
|
| 81 |
T * operator->() const // never throws |
| 82 |
{ |
| 83 |
assert(ptr != 0); |
| 84 |
return ptr; |
| 85 |
} |
| 86 |
|
| 87 |
T * get() const // never throws |
| 88 |
{ |
| 89 |
return ptr; |
| 90 |
} |
| 91 |
|
| 92 |
// implicit conversion to "bool" |
| 93 |
|
| 94 |
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530) |
| 95 |
|
| 96 |
operator bool () const |
| 97 |
{ |
| 98 |
return ptr != 0; |
| 99 |
} |
| 100 |
|
| 101 |
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) |
| 102 |
typedef T * (this_type::*unspecified_bool_type)() const; |
| 103 |
|
| 104 |
operator unspecified_bool_type() const // never throws |
| 105 |
{ |
| 106 |
return ptr == 0? 0: &this_type::get; |
| 107 |
} |
| 108 |
|
| 109 |
#else |
| 110 |
typedef T * this_type::*unspecified_bool_type; |
| 111 |
|
| 112 |
operator unspecified_bool_type() const // never throws |
| 113 |
{ |
| 114 |
return ptr == 0? 0: &this_type::ptr; |
| 115 |
} |
| 116 |
|
| 117 |
#endif |
| 118 |
|
| 119 |
bool operator! () const // never throws |
| 120 |
{ |
| 121 |
return ptr == 0; |
| 122 |
} |
| 123 |
|
| 124 |
void swap(scoped_ptr & b) // never throws |
| 125 |
{ |
| 126 |
T * tmp = b.ptr; |
| 127 |
b.ptr = ptr; |
| 128 |
ptr = tmp; |
| 129 |
} |
| 130 |
}; |
| 131 |
|
| 132 |
template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) // never throws |
| 133 |
{ |
| 134 |
a.swap(b); |
| 135 |
} |
| 136 |
|
| 137 |
// get_pointer(p) is a generic way to say p.get() |
| 138 |
|
| 139 |
template<class T> inline T * get_pointer(scoped_ptr<T> const & p) |
| 140 |
{ |
| 141 |
return p.get(); |
| 142 |
} |
| 143 |
|
| 144 |
} // namespace boost |
| 145 |
|
| 146 |
#endif // #ifndef BOOST_SCOPED_PTR_HPP_INCLUDED |