Debian Codegraph @

Source/boost/scoped_array.hpp

raw
1 #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED
2 #define BOOST_SCOPED_ARRAY_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_array.htm
13 //
14
15
16 // From Boost 1.31.0, http://www.boost.org
17 // Modified by Ori Peleg for use in NSIS, to reduce the required Boost includes
18
19 #include "checked_delete.hpp"
20 #include "detail/workaround.hpp"
21
22 #include <cstddef> // for std::ptrdiff_t
23
24 namespace boost
25 {
26
27 // scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to
28 // is guaranteed, either on destruction of the scoped_array or via an explicit
29 // reset(). Use shared_array or std::vector if your needs are more complex.
30
31 template<class T> class scoped_array // noncopyable
32 {
33 private:
34
35 T * ptr;
36
37 scoped_array(scoped_array const &);
38 scoped_array & operator=(scoped_array const &);
39
40 typedef scoped_array<T> this_type;
41
42 public:
43
44 typedef T element_type;
45
46 explicit scoped_array(T * p = 0) : ptr(p) // never throws
47 {
48 }
49
50 ~scoped_array() // never throws
51 {
52 boost::checked_array_delete(ptr);
53 }
54
55 void reset(T * p = 0) // never throws
56 {
57 assert(p == 0 || p != ptr); // catch self-reset errors
58 this_type(p).swap(*this);
59 }
60
61 T & operator[](std::ptrdiff_t i) const // never throws
62 {
63 assert(ptr != 0);
64 assert(i >= 0);
65 return ptr[i];
66 }
67
68 T * get() const // never throws
69 {
70 return ptr;
71 }
72
73 // implicit conversion to "bool"
74
75 #if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
76
77 operator bool () const
78 {
79 return ptr != 0;
80 }
81
82 #elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
83 typedef T * (this_type::*unspecified_bool_type)() const;
84
85 operator unspecified_bool_type() const // never throws
86 {
87 return ptr == 0? 0: &this_type::get;
88 }
89
90 #else
91
92 typedef T * this_type::*unspecified_bool_type;
93
94 operator unspecified_bool_type() const // never throws
95 {
96 return ptr == 0? 0: &this_type::ptr;
97 }
98
99 #endif
100
101 bool operator! () const // never throws
102 {
103 return ptr == 0;
104 }
105
106 void swap(scoped_array & b) // never throws
107 {
108 T * tmp = b.ptr;
109 b.ptr = ptr;
110 ptr = tmp;
111 }
112
113 };
114
115 template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws
116 {
117 a.swap(b);
118 }
119
120 } // namespace boost
121
122 #endif // #ifndef BOOST_SCOPED_ARRAY_HPP_INCLUDED