OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 OwnPtr& operator=(OwnPtr&&); | 82 OwnPtr& operator=(OwnPtr&&); |
83 template<typename U> OwnPtr& operator=(OwnPtr<U>&&); | 83 template<typename U> OwnPtr& operator=(OwnPtr<U>&&); |
84 | 84 |
85 void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); } | 85 void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); } |
86 | 86 |
87 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } | 87 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } |
88 | 88 |
89 private: | 89 private: |
90 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get | 90 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get |
91 // double-destruction), so these equality operators should never be need
ed. | 91 // double-destruction), so these equality operators should never be need
ed. |
92 template<typename U> bool operator==(const OwnPtr<U>&) const { COMPILE_A
SSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 92 template<typename U> bool operator==(const OwnPtr<U>&) const { static_as
sert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
93 template<typename U> bool operator!=(const OwnPtr<U>&) const { COMPILE_A
SSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 93 template<typename U> bool operator!=(const OwnPtr<U>&) const { static_as
sert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
94 template<typename U> bool operator==(const PassOwnPtr<U>&) const { COMPI
LE_ASSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 94 template<typename U> bool operator==(const PassOwnPtr<U>&) const { stati
c_assert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
95 template<typename U> bool operator!=(const PassOwnPtr<U>&) const { COMPI
LE_ASSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 95 template<typename U> bool operator!=(const PassOwnPtr<U>&) const { stati
c_assert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
96 | 96 |
97 PtrType m_ptr; | 97 PtrType m_ptr; |
98 }; | 98 }; |
99 | 99 |
100 template<typename T> inline OwnPtr<T>::OwnPtr(const PassOwnPtr<T>& o) | 100 template<typename T> inline OwnPtr<T>::OwnPtr(const PassOwnPtr<T>& o) |
101 : m_ptr(o.leakPtr()) | 101 : m_ptr(o.leakPtr()) |
102 { | 102 { |
103 } | 103 } |
104 | 104 |
105 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas
sOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) | 105 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(const Pas
sOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) |
106 : m_ptr(o.leakPtr()) | 106 : m_ptr(o.leakPtr()) |
107 { | 107 { |
108 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 108 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
109 } | 109 } |
110 | 110 |
111 template<typename T> inline void OwnPtr<T>::clear() | 111 template<typename T> inline void OwnPtr<T>::clear() |
112 { | 112 { |
113 PtrType ptr = m_ptr; | 113 PtrType ptr = m_ptr; |
114 m_ptr = 0; | 114 m_ptr = 0; |
115 OwnedPtrDeleter<T>::deletePtr(ptr); | 115 OwnedPtrDeleter<T>::deletePtr(ptr); |
116 } | 116 } |
117 | 117 |
118 template<typename T> inline PassOwnPtr<T> OwnPtr<T>::release() | 118 template<typename T> inline PassOwnPtr<T> OwnPtr<T>::release() |
119 { | 119 { |
120 PtrType ptr = m_ptr; | 120 PtrType ptr = m_ptr; |
121 m_ptr = 0; | 121 m_ptr = 0; |
122 return PassOwnPtr<T>(ptr); | 122 return PassOwnPtr<T>(ptr); |
123 } | 123 } |
124 | 124 |
125 template<typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() | 125 template<typename T> inline typename OwnPtr<T>::PtrType OwnPtr<T>::leakPtr() |
126 { | 126 { |
127 PtrType ptr = m_ptr; | 127 PtrType ptr = m_ptr; |
128 m_ptr = 0; | 128 m_ptr = 0; |
129 return ptr; | 129 return ptr; |
130 } | 130 } |
131 | 131 |
132 template<typename T> inline typename OwnPtr<T>::ValueType& OwnPtr<T>::operat
or[](std::ptrdiff_t i) const | 132 template<typename T> inline typename OwnPtr<T>::ValueType& OwnPtr<T>::operat
or[](std::ptrdiff_t i) const |
133 { | 133 { |
134 COMPILE_ASSERT(IsArray<T>::value, Elements_access_is_possible_for_arrays
_only); | 134 static_assert(IsArray<T>::value, "elements access is possible for arrays
only"); |
135 ASSERT(m_ptr); | 135 ASSERT(m_ptr); |
136 ASSERT(i >= 0); | 136 ASSERT(i >= 0); |
137 return m_ptr[i]; | 137 return m_ptr[i]; |
138 } | 138 } |
139 | 139 |
140 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr
<T>& o) | 140 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(const PassOwnPtr
<T>& o) |
141 { | 141 { |
142 PtrType ptr = m_ptr; | 142 PtrType ptr = m_ptr; |
143 m_ptr = o.leakPtr(); | 143 m_ptr = o.leakPtr(); |
144 ASSERT(!ptr || m_ptr != ptr); | 144 ASSERT(!ptr || m_ptr != ptr); |
145 OwnedPtrDeleter<T>::deletePtr(ptr); | 145 OwnedPtrDeleter<T>::deletePtr(ptr); |
146 return *this; | 146 return *this; |
147 } | 147 } |
148 | 148 |
149 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera
tor=(const PassOwnPtr<U>& o) | 149 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera
tor=(const PassOwnPtr<U>& o) |
150 { | 150 { |
151 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 151 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
152 PtrType ptr = m_ptr; | 152 PtrType ptr = m_ptr; |
153 m_ptr = o.leakPtr(); | 153 m_ptr = o.leakPtr(); |
154 ASSERT(!ptr || m_ptr != ptr); | 154 ASSERT(!ptr || m_ptr != ptr); |
155 OwnedPtrDeleter<T>::deletePtr(ptr); | 155 OwnedPtrDeleter<T>::deletePtr(ptr); |
156 return *this; | 156 return *this; |
157 } | 157 } |
158 | 158 |
159 template<typename T> inline OwnPtr<T>::OwnPtr(OwnPtr<T>&& o) | 159 template<typename T> inline OwnPtr<T>::OwnPtr(OwnPtr<T>&& o) |
160 : m_ptr(o.leakPtr()) | 160 : m_ptr(o.leakPtr()) |
161 { | 161 { |
162 } | 162 } |
163 | 163 |
164 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(OwnPtr<U>
&& o) | 164 template<typename T> template<typename U> inline OwnPtr<T>::OwnPtr(OwnPtr<U>
&& o) |
165 : m_ptr(o.leakPtr()) | 165 : m_ptr(o.leakPtr()) |
166 { | 166 { |
167 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 167 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
168 } | 168 } |
169 | 169 |
170 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(OwnPtr<T>&& o) | 170 template<typename T> inline OwnPtr<T>& OwnPtr<T>::operator=(OwnPtr<T>&& o) |
171 { | 171 { |
172 PtrType ptr = m_ptr; | 172 PtrType ptr = m_ptr; |
173 m_ptr = o.leakPtr(); | 173 m_ptr = o.leakPtr(); |
174 ASSERT(!ptr || m_ptr != ptr); | 174 ASSERT(!ptr || m_ptr != ptr); |
175 OwnedPtrDeleter<T>::deletePtr(ptr); | 175 OwnedPtrDeleter<T>::deletePtr(ptr); |
176 | 176 |
177 return *this; | 177 return *this; |
178 } | 178 } |
179 | 179 |
180 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera
tor=(OwnPtr<U>&& o) | 180 template<typename T> template<typename U> inline OwnPtr<T>& OwnPtr<T>::opera
tor=(OwnPtr<U>&& o) |
181 { | 181 { |
182 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 182 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
183 PtrType ptr = m_ptr; | 183 PtrType ptr = m_ptr; |
184 m_ptr = o.leakPtr(); | 184 m_ptr = o.leakPtr(); |
185 ASSERT(!ptr || m_ptr != ptr); | 185 ASSERT(!ptr || m_ptr != ptr); |
186 OwnedPtrDeleter<T>::deletePtr(ptr); | 186 OwnedPtrDeleter<T>::deletePtr(ptr); |
187 | 187 |
188 return *this; | 188 return *this; |
189 } | 189 } |
190 | 190 |
191 template<typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) | 191 template<typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) |
192 { | 192 { |
(...skipping 23 matching lines...) Expand all Loading... |
216 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<
T>& p) | 216 template<typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<
T>& p) |
217 { | 217 { |
218 return p.get(); | 218 return p.get(); |
219 } | 219 } |
220 | 220 |
221 } // namespace WTF | 221 } // namespace WTF |
222 | 222 |
223 using WTF::OwnPtr; | 223 using WTF::OwnPtr; |
224 | 224 |
225 #endif // WTF_OwnPtr_h | 225 #endif // WTF_OwnPtr_h |
OLD | NEW |