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/. */
7 /* Smart pointer which leaks its owning refcounted object by default. */
12 #include "mozilla/AlreadyAddRefed.h"
17 * Instance of this class behaves like a raw pointer which leaks the
18 * resource it's owning if not explicitly released.
23 explicit LeakRefPtr(already_AddRefed
<T
>&& aPtr
) : mRawPtr(aPtr
.take()) {}
25 explicit operator bool() const { return !!mRawPtr
; }
27 LeakRefPtr
<T
>& operator=(already_AddRefed
<T
>&& aPtr
) {
28 mRawPtr
= aPtr
.take();
32 T
* get() const { return mRawPtr
; }
34 already_AddRefed
<T
> take() {
37 return already_AddRefed
<T
>(rawPtr
);
40 void release() { NS_RELEASE(mRawPtr
); }
43 T
* MOZ_OWNING_REF mRawPtr
;
46 } // namespace mozilla
48 #endif // LeakRefPtr_h