/src/mozilla-central/xpcom/base/nsAutoPtr.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsAutoPtr_h |
8 | | #define nsAutoPtr_h |
9 | | |
10 | | #include "nsCOMPtr.h" |
11 | | #include "mozilla/RefPtr.h" |
12 | | #include "mozilla/TypeTraits.h" |
13 | | |
14 | | #include "nsCycleCollectionNoteChild.h" |
15 | | #include "mozilla/MemoryReporting.h" |
16 | | |
17 | | /*****************************************************************************/ |
18 | | |
19 | | // template <class T> class nsAutoPtrGetterTransfers; |
20 | | |
21 | | template <class T> |
22 | | class nsAutoPtr |
23 | | { |
24 | | private: |
25 | | static_assert(!mozilla::IsScalar<T>::value, "If you are using " |
26 | | "nsAutoPtr to hold an array, use UniquePtr<T[]> instead"); |
27 | | |
28 | | void** |
29 | | begin_assignment() |
30 | 0 | { |
31 | 0 | assign(0); |
32 | 0 | return reinterpret_cast<void**>(&mRawPtr); |
33 | 0 | } |
34 | | |
35 | | void |
36 | | assign(T* aNewPtr) |
37 | 85 | { |
38 | 85 | T* oldPtr = mRawPtr; |
39 | 85 | |
40 | 85 | if (aNewPtr && aNewPtr == oldPtr) { |
41 | 0 | MOZ_CRASH("Logic flaw in the caller"); |
42 | 0 | } |
43 | 85 | |
44 | 85 | mRawPtr = aNewPtr; |
45 | 85 | delete oldPtr; |
46 | 85 | } nsAutoPtr<mozilla::LogModule>::assign(mozilla::LogModule*) Line | Count | Source | 37 | 75 | { | 38 | 75 | T* oldPtr = mRawPtr; | 39 | 75 | | 40 | 75 | if (aNewPtr && aNewPtr == oldPtr) { | 41 | 0 | MOZ_CRASH("Logic flaw in the caller"); | 42 | 0 | } | 43 | 75 | | 44 | 75 | mRawPtr = aNewPtr; | 45 | 75 | delete oldPtr; | 46 | 75 | } |
Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::assign(NodePool::Enumerator*) Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::assign(CCGraphBuilder*) nsAutoPtr<nsTString<char> >::assign(nsTString<char>*) Line | Count | Source | 37 | 10 | { | 38 | 10 | T* oldPtr = mRawPtr; | 39 | 10 | | 40 | 10 | if (aNewPtr && aNewPtr == oldPtr) { | 41 | 0 | MOZ_CRASH("Logic flaw in the caller"); | 42 | 0 | } | 43 | 10 | | 44 | 10 | mRawPtr = aNewPtr; | 45 | 10 | delete oldPtr; | 46 | 10 | } |
Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::assign(nsINIParser_internal::INIValue*) Unexecuted instantiation: nsAutoPtr<BloatEntry>::assign(BloatEntry*) Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::assign(SerialNumberRecord*) Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::assign(mozilla::gmp::GMPDiskStorage::Record*) Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::assign(mozilla::gmp::GMPMemoryStorage::Record*) Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::assign(mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> >*) Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::assign(mozilla::dom::CoalescedMouseData*) Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::assign(nsTArray<JITFrameInfoForBufferRange::JITFrameKey>*) Unexecuted instantiation: nsAutoPtr<TestObject>::assign(TestObject*) |
47 | | |
48 | | // |class Ptr| helps us prevent implicit "copy construction" |
49 | | // through |operator T*() const| from a |const nsAutoPtr<T>| |
50 | | // because two implicit conversions in a row aren't allowed. |
51 | | // It still allows assignment from T* through implicit conversion |
52 | | // from |T*| to |nsAutoPtr<T>::Ptr| |
53 | | class Ptr |
54 | | { |
55 | | public: |
56 | | MOZ_IMPLICIT Ptr(T* aPtr) |
57 | | : mPtr(aPtr) |
58 | 0 | { |
59 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::Ptr::Ptr(mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> >*) Unexecuted instantiation: nsAutoPtr<TestObject>::Ptr::Ptr(TestObject*) Unexecuted instantiation: nsAutoPtr<TestObjectBaseB>::Ptr::Ptr(TestObjectBaseB*) Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::Ptr::Ptr(TestObjectBaseA*) |
60 | | |
61 | | operator T*() const |
62 | 0 | { |
63 | 0 | return mPtr; |
64 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::Ptr::operator mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> >*() const Unexecuted instantiation: nsAutoPtr<TestObject>::Ptr::operator TestObject*() const Unexecuted instantiation: nsAutoPtr<TestObjectBaseB>::Ptr::operator TestObjectBaseB*() const Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::Ptr::operator TestObjectBaseA*() const |
65 | | |
66 | | private: |
67 | | T* MOZ_NON_OWNING_REF mPtr; |
68 | | }; |
69 | | |
70 | | private: |
71 | | T* MOZ_OWNING_REF mRawPtr; |
72 | | |
73 | | public: |
74 | | typedef T element_type; |
75 | | |
76 | | ~nsAutoPtr() |
77 | 0 | { |
78 | 0 | delete mRawPtr; |
79 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::LogModule>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<nsTString<char> >::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<BloatEntry>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<TestObject>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<TestObjectBaseB>::~nsAutoPtr() Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::~nsAutoPtr() |
80 | | |
81 | | // Constructors |
82 | | |
83 | | nsAutoPtr() |
84 | | : mRawPtr(0) |
85 | | // default constructor |
86 | 88 | { |
87 | 88 | } nsAutoPtr<mozilla::LogModule>::nsAutoPtr() Line | Count | Source | 86 | 75 | { | 87 | 75 | } |
nsAutoPtr<nsTString<char> >::nsAutoPtr() Line | Count | Source | 86 | 10 | { | 87 | 10 | } |
Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::nsAutoPtr() nsAutoPtr<CCGraphBuilder>::nsAutoPtr() Line | Count | Source | 86 | 3 | { | 87 | 3 | } |
Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<BloatEntry>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::nsAutoPtr() Unexecuted instantiation: nsAutoPtr<TestObject>::nsAutoPtr() |
88 | | |
89 | | MOZ_IMPLICIT nsAutoPtr(Ptr aRawPtr) |
90 | | : mRawPtr(aRawPtr) |
91 | | // construct from a raw pointer (of the right type) |
92 | 0 | { |
93 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::nsAutoPtr(nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::Ptr) Unexecuted instantiation: nsAutoPtr<TestObject>::nsAutoPtr(nsAutoPtr<TestObject>::Ptr) Unexecuted instantiation: nsAutoPtr<TestObjectBaseB>::nsAutoPtr(nsAutoPtr<TestObjectBaseB>::Ptr) Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::nsAutoPtr(nsAutoPtr<TestObjectBaseA>::Ptr) |
94 | | |
95 | | // This constructor shouldn't exist; we should just use the && |
96 | | // constructor. |
97 | | nsAutoPtr(nsAutoPtr<T>& aSmartPtr) |
98 | | : mRawPtr(aSmartPtr.forget()) |
99 | | // Construct by transferring ownership from another smart pointer. |
100 | | { |
101 | | } |
102 | | |
103 | | template <typename I> |
104 | | MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>& aSmartPtr) |
105 | | : mRawPtr(aSmartPtr.forget()) |
106 | | // Construct by transferring ownership from another smart pointer. |
107 | | { |
108 | | } |
109 | | |
110 | | nsAutoPtr(nsAutoPtr<T>&& aSmartPtr) |
111 | | : mRawPtr(aSmartPtr.forget()) |
112 | | // Construct by transferring ownership from another smart pointer. |
113 | | { |
114 | | } |
115 | | |
116 | | template <typename I> |
117 | | MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>&& aSmartPtr) |
118 | | : mRawPtr(aSmartPtr.forget()) |
119 | | // Construct by transferring ownership from another smart pointer. |
120 | | { |
121 | | } |
122 | | |
123 | | // Assignment operators |
124 | | |
125 | | nsAutoPtr<T>& |
126 | | operator=(T* aRhs) |
127 | | // assign from a raw pointer (of the right type) |
128 | 85 | { |
129 | 85 | assign(aRhs); |
130 | 85 | return *this; |
131 | 85 | } nsAutoPtr<mozilla::LogModule>::operator=(mozilla::LogModule*) Line | Count | Source | 128 | 75 | { | 129 | 75 | assign(aRhs); | 130 | 75 | return *this; | 131 | 75 | } |
Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::operator=(NodePool::Enumerator*) Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::operator=(CCGraphBuilder*) nsAutoPtr<nsTString<char> >::operator=(nsTString<char>*) Line | Count | Source | 128 | 10 | { | 129 | 10 | assign(aRhs); | 130 | 10 | return *this; | 131 | 10 | } |
Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::operator=(nsINIParser_internal::INIValue*) Unexecuted instantiation: nsAutoPtr<BloatEntry>::operator=(BloatEntry*) Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::operator=(SerialNumberRecord*) Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::operator=(mozilla::gmp::GMPDiskStorage::Record*) Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::operator=(mozilla::gmp::GMPMemoryStorage::Record*) Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::operator=(mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> >*) Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::operator=(mozilla::dom::CoalescedMouseData*) Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::operator=(nsTArray<JITFrameInfoForBufferRange::JITFrameKey>*) Unexecuted instantiation: nsAutoPtr<TestObject>::operator=(TestObject*) |
132 | | |
133 | | nsAutoPtr<T>& operator=(nsAutoPtr<T>& aRhs) |
134 | | // assign by transferring ownership from another smart pointer. |
135 | | { |
136 | | assign(aRhs.forget()); |
137 | | return *this; |
138 | | } |
139 | | |
140 | | template <typename I> |
141 | | nsAutoPtr<T>& operator=(nsAutoPtr<I>& aRhs) |
142 | | // assign by transferring ownership from another smart pointer. |
143 | | { |
144 | | assign(aRhs.forget()); |
145 | | return *this; |
146 | | } |
147 | | |
148 | | nsAutoPtr<T>& operator=(nsAutoPtr<T>&& aRhs) |
149 | 0 | { |
150 | 0 | assign(aRhs.forget()); |
151 | 0 | return *this; |
152 | 0 | } Unexecuted instantiation: nsAutoPtr<nsTString<char> >::operator=(nsAutoPtr<nsTString<char> >&&) Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::operator=(nsAutoPtr<nsINIParser_internal::INIValue>&&) Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::operator=(nsAutoPtr<SerialNumberRecord>&&) Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::operator=(nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>&&) |
153 | | |
154 | | template <typename I> |
155 | | nsAutoPtr<T>& operator=(nsAutoPtr<I>&& aRhs) |
156 | | { |
157 | | assign(aRhs.forget()); |
158 | | return *this; |
159 | | } |
160 | | |
161 | | // Other pointer operators |
162 | | |
163 | | T* |
164 | | get() const |
165 | | /* |
166 | | Prefer the implicit conversion provided automatically by |
167 | | |operator T*() const|. Use |get()| _only_ to resolve |
168 | | ambiguity. |
169 | | */ |
170 | 0 | { |
171 | 0 | return mRawPtr; |
172 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::LogModule>::get() const Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::get() const Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::get() const Unexecuted instantiation: nsAutoPtr<nsTString<char> >::get() const Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::get() const Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::get() const Unexecuted instantiation: nsAutoPtr<BloatEntry>::get() const Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::get() const Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::get() const Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::get() const Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::get() const Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::get() const Unexecuted instantiation: nsAutoPtr<TestObject>::get() const Unexecuted instantiation: nsAutoPtr<TestObjectBaseB>::get() const Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::get() const |
173 | | |
174 | | operator T*() const |
175 | | /* |
176 | | ...makes an |nsAutoPtr| act like its underlying raw pointer |
177 | | type whenever it is used in a context where a raw pointer |
178 | | is expected. It is this operator that makes an |nsAutoPtr| |
179 | | substitutable for a raw pointer. |
180 | | |
181 | | Prefer the implicit use of this operator to calling |get()|, |
182 | | except where necessary to resolve ambiguity. |
183 | | */ |
184 | 0 | { |
185 | 0 | return get(); |
186 | 0 | } Unexecuted instantiation: nsAutoPtr<mozilla::LogModule>::operator mozilla::LogModule*() const Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::operator CCGraphBuilder*() const Unexecuted instantiation: nsAutoPtr<nsTString<char> >::operator nsTString<char>*() const Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::operator nsINIParser_internal::INIValue*() const Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::operator SerialNumberRecord*() const Unexecuted instantiation: nsAutoPtr<BloatEntry>::operator BloatEntry*() const Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::operator mozilla::gmp::GMPDiskStorage::Record*() const Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::operator mozilla::gmp::GMPMemoryStorage::Record*() const Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::operator mozilla::dom::CoalescedMouseData*() const Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::operator nsTArray<JITFrameInfoForBufferRange::JITFrameKey>*() const Unexecuted instantiation: nsAutoPtr<TestObject>::operator TestObject*() const Unexecuted instantiation: nsAutoPtr<TestObjectBaseA>::operator TestObjectBaseA*() const |
187 | | |
188 | | T* |
189 | | forget() |
190 | 0 | { |
191 | 0 | T* temp = mRawPtr; |
192 | 0 | mRawPtr = 0; |
193 | 0 | return temp; |
194 | 0 | } Unexecuted instantiation: nsAutoPtr<nsCOMArray<nsMutationReceiver> >::forget() Unexecuted instantiation: nsAutoPtr<nsTArray<nsAutoAnimationMutationBatch::Entry> >::forget() Unexecuted instantiation: nsAutoPtr<mozilla::LogModule>::forget() Unexecuted instantiation: nsAutoPtr<nsTString<char> >::forget() Unexecuted instantiation: nsAutoPtr<nsINIParser_internal::INIValue>::forget() Unexecuted instantiation: nsAutoPtr<SerialNumberRecord>::forget() Unexecuted instantiation: nsAutoPtr<BloatEntry>::forget() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPMemoryStorage::Record>::forget() Unexecuted instantiation: nsAutoPtr<mozilla::gmp::GMPDiskStorage::Record>::forget() Unexecuted instantiation: nsAutoPtr<mozilla::dom::CoalescedMouseData>::forget() Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::forget() Unexecuted instantiation: nsAutoPtr<TestObject>::forget() |
195 | | |
196 | | T* |
197 | | operator->() const |
198 | 0 | { |
199 | 0 | MOZ_ASSERT(mRawPtr != 0, |
200 | 0 | "You can't dereference a NULL nsAutoPtr with operator->()."); |
201 | 0 | return get(); |
202 | 0 | } Unexecuted instantiation: nsAutoPtr<NodePool::Enumerator>::operator->() const Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::operator->() const Unexecuted instantiation: nsAutoPtr<mozilla::detail::MethodCall<mozilla::MozPromise<bool, nsresult, false>, RefPtr<mozilla::MozPromise<bool, nsresult, false> > (mozilla::gmp::GMPParent::*)(nsTSubstring<char16_t> const&), mozilla::gmp::GMPParent, StoreCopyPassByRRef<NS_ConvertUTF8toUTF16> > >::operator->() const |
203 | | |
204 | | template <typename R, typename... Args> |
205 | | class Proxy |
206 | | { |
207 | | typedef R (T::*member_function)(Args...); |
208 | | T* mRawPtr; |
209 | | member_function mFunction; |
210 | | public: |
211 | | Proxy(T* aRawPtr, member_function aFunction) |
212 | | : mRawPtr(aRawPtr), |
213 | | mFunction(aFunction) |
214 | 0 | { |
215 | 0 | } |
216 | | template<typename... ActualArgs> |
217 | | R operator()(ActualArgs&&... aArgs) |
218 | 0 | { |
219 | 0 | return ((*mRawPtr).*mFunction)(std::forward<ActualArgs>(aArgs)...); |
220 | 0 | } |
221 | | }; |
222 | | |
223 | | template <typename R, typename C, typename... Args> |
224 | | Proxy<R, Args...> operator->*(R (C::*aFptr)(Args...)) const |
225 | 0 | { |
226 | 0 | MOZ_ASSERT(mRawPtr != 0, |
227 | 0 | "You can't dereference a NULL nsAutoPtr with operator->*()."); |
228 | 0 | return Proxy<R, Args...>(get(), aFptr); |
229 | 0 | } |
230 | | |
231 | | nsAutoPtr<T>* |
232 | | get_address() |
233 | | // This is not intended to be used by clients. See |address_of| |
234 | | // below. |
235 | | { |
236 | | return this; |
237 | | } |
238 | | |
239 | | const nsAutoPtr<T>* |
240 | | get_address() const |
241 | | // This is not intended to be used by clients. See |address_of| |
242 | | // below. |
243 | | { |
244 | | return this; |
245 | | } |
246 | | |
247 | | public: |
248 | | T& |
249 | | operator*() const |
250 | 0 | { |
251 | 0 | MOZ_ASSERT(mRawPtr != 0, |
252 | 0 | "You can't dereference a NULL nsAutoPtr with operator*()."); |
253 | 0 | return *get(); |
254 | 0 | } Unexecuted instantiation: nsAutoPtr<CCGraphBuilder>::operator*() const Unexecuted instantiation: nsAutoPtr<nsTArray<JITFrameInfoForBufferRange::JITFrameKey> >::operator*() const |
255 | | |
256 | | T** |
257 | | StartAssignment() |
258 | 0 | { |
259 | 0 | #ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT |
260 | 0 | return reinterpret_cast<T**>(begin_assignment()); |
261 | | #else |
262 | | assign(0); |
263 | | return reinterpret_cast<T**>(&mRawPtr); |
264 | | #endif |
265 | | } |
266 | | }; |
267 | | |
268 | | template <class T> |
269 | | inline nsAutoPtr<T>* |
270 | | address_of(nsAutoPtr<T>& aPtr) |
271 | | { |
272 | | return aPtr.get_address(); |
273 | | } |
274 | | |
275 | | template <class T> |
276 | | inline const nsAutoPtr<T>* |
277 | | address_of(const nsAutoPtr<T>& aPtr) |
278 | | { |
279 | | return aPtr.get_address(); |
280 | | } |
281 | | |
282 | | template <class T> |
283 | | class nsAutoPtrGetterTransfers |
284 | | /* |
285 | | ... |
286 | | |
287 | | This class is designed to be used for anonymous temporary objects in the |
288 | | argument list of calls that return COM interface pointers, e.g., |
289 | | |
290 | | nsAutoPtr<IFoo> fooP; |
291 | | ...->GetTransferedPointer(getter_Transfers(fooP)) |
292 | | |
293 | | DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead. |
294 | | |
295 | | When initialized with a |nsAutoPtr|, as in the example above, it returns |
296 | | a |void**|, a |T**|, or an |nsISupports**| as needed, that the |
297 | | outer call (|GetTransferedPointer| in this case) can fill in. |
298 | | |
299 | | This type should be a nested class inside |nsAutoPtr<T>|. |
300 | | */ |
301 | | { |
302 | | public: |
303 | | explicit |
304 | | nsAutoPtrGetterTransfers(nsAutoPtr<T>& aSmartPtr) |
305 | | : mTargetSmartPtr(aSmartPtr) |
306 | 0 | { |
307 | 0 | // nothing else to do |
308 | 0 | } |
309 | | |
310 | | operator void**() |
311 | | { |
312 | | return reinterpret_cast<void**>(mTargetSmartPtr.StartAssignment()); |
313 | | } |
314 | | |
315 | | operator T**() |
316 | 0 | { |
317 | 0 | return mTargetSmartPtr.StartAssignment(); |
318 | 0 | } |
319 | | |
320 | | T*& |
321 | | operator*() |
322 | | { |
323 | | return *(mTargetSmartPtr.StartAssignment()); |
324 | | } |
325 | | |
326 | | private: |
327 | | nsAutoPtr<T>& mTargetSmartPtr; |
328 | | }; |
329 | | |
330 | | template <class T> |
331 | | inline nsAutoPtrGetterTransfers<T> |
332 | | getter_Transfers(nsAutoPtr<T>& aSmartPtr) |
333 | | /* |
334 | | Used around a |nsAutoPtr| when |
335 | | ...makes the class |nsAutoPtrGetterTransfers<T>| invisible. |
336 | | */ |
337 | 0 | { |
338 | 0 | return nsAutoPtrGetterTransfers<T>(aSmartPtr); |
339 | 0 | } |
340 | | |
341 | | |
342 | | |
343 | | // Comparing two |nsAutoPtr|s |
344 | | |
345 | | template <class T, class U> |
346 | | inline bool |
347 | | operator==(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs) |
348 | | { |
349 | | return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs.get()); |
350 | | } |
351 | | |
352 | | |
353 | | template <class T, class U> |
354 | | inline bool |
355 | | operator!=(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs) |
356 | | { |
357 | | return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs.get()); |
358 | | } |
359 | | |
360 | | |
361 | | // Comparing an |nsAutoPtr| to a raw pointer |
362 | | |
363 | | template <class T, class U> |
364 | | inline bool |
365 | | operator==(const nsAutoPtr<T>& aLhs, const U* aRhs) |
366 | | { |
367 | | return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs); |
368 | | } |
369 | | |
370 | | template <class T, class U> |
371 | | inline bool |
372 | | operator==(const U* aLhs, const nsAutoPtr<T>& aRhs) |
373 | | { |
374 | | return static_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get()); |
375 | | } |
376 | | |
377 | | template <class T, class U> |
378 | | inline bool |
379 | | operator!=(const nsAutoPtr<T>& aLhs, const U* aRhs) |
380 | | { |
381 | | return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs); |
382 | | } |
383 | | |
384 | | template <class T, class U> |
385 | | inline bool |
386 | | operator!=(const U* aLhs, const nsAutoPtr<T>& aRhs) |
387 | | { |
388 | | return static_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get()); |
389 | | } |
390 | | |
391 | | template <class T, class U> |
392 | | inline bool |
393 | | operator==(const nsAutoPtr<T>& aLhs, U* aRhs) |
394 | 0 | { |
395 | 0 | return static_cast<const T*>(aLhs.get()) == const_cast<const U*>(aRhs); |
396 | 0 | } Unexecuted instantiation: bool operator==<TestObject, TestObjectBaseB>(nsAutoPtr<TestObject> const&, TestObjectBaseB*) Unexecuted instantiation: bool operator==<TestObjectBaseB, TestObject>(nsAutoPtr<TestObjectBaseB> const&, TestObject*) |
397 | | |
398 | | template <class T, class U> |
399 | | inline bool |
400 | | operator==(U* aLhs, const nsAutoPtr<T>& aRhs) |
401 | 0 | { |
402 | 0 | return const_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get()); |
403 | 0 | } Unexecuted instantiation: bool operator==<TestObject, TestObjectBaseB>(TestObjectBaseB*, nsAutoPtr<TestObject> const&) Unexecuted instantiation: bool operator==<TestObjectBaseB, TestObject>(TestObject*, nsAutoPtr<TestObjectBaseB> const&) |
404 | | |
405 | | template <class T, class U> |
406 | | inline bool |
407 | | operator!=(const nsAutoPtr<T>& aLhs, U* aRhs) |
408 | 0 | { |
409 | 0 | return static_cast<const T*>(aLhs.get()) != const_cast<const U*>(aRhs); |
410 | 0 | } Unexecuted instantiation: bool operator!=<TestObject, TestObjectBaseB>(nsAutoPtr<TestObject> const&, TestObjectBaseB*) Unexecuted instantiation: bool operator!=<TestObjectBaseB, TestObject>(nsAutoPtr<TestObjectBaseB> const&, TestObject*) |
411 | | |
412 | | template <class T, class U> |
413 | | inline bool |
414 | | operator!=(U* aLhs, const nsAutoPtr<T>& aRhs) |
415 | 0 | { |
416 | 0 | return const_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get()); |
417 | 0 | } Unexecuted instantiation: bool operator!=<TestObject, TestObjectBaseB>(TestObjectBaseB*, nsAutoPtr<TestObject> const&) Unexecuted instantiation: bool operator!=<TestObjectBaseB, TestObject>(TestObject*, nsAutoPtr<TestObjectBaseB> const&) |
418 | | |
419 | | |
420 | | |
421 | | // Comparing an |nsAutoPtr| to |nullptr| |
422 | | |
423 | | template <class T> |
424 | | inline bool |
425 | | operator==(const nsAutoPtr<T>& aLhs, decltype(nullptr)) |
426 | | { |
427 | | return aLhs.get() == nullptr; |
428 | | } |
429 | | |
430 | | template <class T> |
431 | | inline bool |
432 | | operator==(decltype(nullptr), const nsAutoPtr<T>& aRhs) |
433 | | { |
434 | | return nullptr == aRhs.get(); |
435 | | } |
436 | | |
437 | | template <class T> |
438 | | inline bool |
439 | | operator!=(const nsAutoPtr<T>& aLhs, decltype(nullptr)) |
440 | | { |
441 | | return aLhs.get() != nullptr; |
442 | | } |
443 | | |
444 | | template <class T> |
445 | | inline bool |
446 | | operator!=(decltype(nullptr), const nsAutoPtr<T>& aRhs) |
447 | | { |
448 | | return nullptr != aRhs.get(); |
449 | | } |
450 | | |
451 | | |
452 | | /*****************************************************************************/ |
453 | | |
454 | | #endif // !defined(nsAutoPtr_h) |