2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-10-25 08:09:38 +04:00
|
|
|
|
2014-09-26 21:53:47 +04:00
|
|
|
#ifndef nsAutoPtr_h
|
|
|
|
#define nsAutoPtr_h
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2016-01-30 02:33:41 +03:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2003-01-18 19:20:26 +03:00
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
#include "nsCycleCollectionNoteChild.h"
|
2014-01-04 22:15:41 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-11-15 11:32:39 +04:00
|
|
|
|
2003-01-18 19:20:26 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
// template <class T> class nsAutoPtrGetterTransfers;
|
2001-10-25 08:09:38 +04:00
|
|
|
|
|
|
|
template <class T>
|
2003-01-18 19:20:26 +03:00
|
|
|
class nsAutoPtr
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
|
|
|
private:
|
2016-01-30 02:33:41 +03:00
|
|
|
static_assert(!mozilla::IsScalar<T>::value, "If you are using "
|
|
|
|
"nsAutoPtr to hold an array, use UniquePtr<T[]> instead");
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
void**
|
|
|
|
begin_assignment()
|
|
|
|
{
|
|
|
|
assign(0);
|
|
|
|
return reinterpret_cast<void**>(&mRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-13 21:41:38 +04:00
|
|
|
assign(T* aNewPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
|
|
|
T* oldPtr = mRawPtr;
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
if (aNewPtr && aNewPtr == oldPtr) {
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("Logic flaw in the caller");
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
mRawPtr = aNewPtr;
|
2014-05-05 21:30:39 +04:00
|
|
|
delete oldPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// |class Ptr| helps us prevent implicit "copy construction"
|
|
|
|
// through |operator T*() const| from a |const nsAutoPtr<T>|
|
|
|
|
// because two implicit conversions in a row aren't allowed.
|
|
|
|
// It still allows assignment from T* through implicit conversion
|
|
|
|
// from |T*| to |nsAutoPtr<T>::Ptr|
|
|
|
|
class Ptr
|
|
|
|
{
|
|
|
|
public:
|
2014-07-28 21:19:06 +04:00
|
|
|
MOZ_IMPLICIT Ptr(T* aPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
: mPtr(aPtr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T*() const
|
|
|
|
{
|
|
|
|
return mPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-12-24 05:17:50 +03:00
|
|
|
T* MOZ_NON_OWNING_REF mPtr;
|
2014-05-05 21:30:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2014-12-24 05:17:50 +03:00
|
|
|
T* MOZ_OWNING_REF mRawPtr;
|
2014-05-05 21:30:39 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef T element_type;
|
|
|
|
|
|
|
|
~nsAutoPtr()
|
|
|
|
{
|
|
|
|
delete mRawPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
|
|
|
|
nsAutoPtr()
|
|
|
|
: mRawPtr(0)
|
|
|
|
// default constructor
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-28 21:19:06 +04:00
|
|
|
MOZ_IMPLICIT nsAutoPtr(Ptr aRawPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
: mRawPtr(aRawPtr)
|
|
|
|
// construct from a raw pointer (of the right type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// This constructor shouldn't exist; we should just use the &&
|
|
|
|
// constructor.
|
2014-05-13 21:41:38 +04:00
|
|
|
nsAutoPtr(nsAutoPtr<T>& aSmartPtr)
|
|
|
|
: mRawPtr(aSmartPtr.forget())
|
2014-05-05 21:30:39 +04:00
|
|
|
// Construct by transferring ownership from another smart pointer.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:55:05 +03:00
|
|
|
template <typename I>
|
2015-07-28 04:11:51 +03:00
|
|
|
MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>& aSmartPtr)
|
2015-05-01 07:55:05 +03:00
|
|
|
: mRawPtr(aSmartPtr.forget())
|
|
|
|
// Construct by transferring ownership from another smart pointer.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
nsAutoPtr(nsAutoPtr<T>&& aSmartPtr)
|
|
|
|
: mRawPtr(aSmartPtr.forget())
|
2014-05-05 21:30:39 +04:00
|
|
|
// Construct by transferring ownership from another smart pointer.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:55:05 +03:00
|
|
|
template <typename I>
|
2015-07-28 04:11:51 +03:00
|
|
|
MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>&& aSmartPtr)
|
2015-05-01 07:55:05 +03:00
|
|
|
: mRawPtr(aSmartPtr.forget())
|
|
|
|
// Construct by transferring ownership from another smart pointer.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Assignment operators
|
|
|
|
|
|
|
|
nsAutoPtr<T>&
|
2014-05-13 21:41:38 +04:00
|
|
|
operator=(T* aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
// assign from a raw pointer (of the right type)
|
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
assign(aRhs);
|
2014-05-05 21:30:39 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
nsAutoPtr<T>& operator=(nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
// assign by transferring ownership from another smart pointer.
|
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
assign(aRhs.forget());
|
2014-05-05 21:30:39 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:55:05 +03:00
|
|
|
template <typename I>
|
|
|
|
nsAutoPtr<T>& operator=(nsAutoPtr<I>& aRhs)
|
|
|
|
// assign by transferring ownership from another smart pointer.
|
|
|
|
{
|
|
|
|
assign(aRhs.forget());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-08 02:05:37 +04:00
|
|
|
nsAutoPtr<T>& operator=(nsAutoPtr<T>&& aRhs)
|
|
|
|
{
|
|
|
|
assign(aRhs.forget());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-01 07:55:05 +03:00
|
|
|
template <typename I>
|
|
|
|
nsAutoPtr<T>& operator=(nsAutoPtr<I>&& aRhs)
|
|
|
|
{
|
|
|
|
assign(aRhs.forget());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Other pointer operators
|
|
|
|
|
|
|
|
T*
|
|
|
|
get() const
|
|
|
|
/*
|
|
|
|
Prefer the implicit conversion provided automatically by
|
|
|
|
|operator T*() const|. Use |get()| _only_ to resolve
|
|
|
|
ambiguity.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return mRawPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T*() const
|
|
|
|
/*
|
|
|
|
...makes an |nsAutoPtr| act like its underlying raw pointer
|
|
|
|
type whenever it is used in a context where a raw pointer
|
|
|
|
is expected. It is this operator that makes an |nsAutoPtr|
|
|
|
|
substitutable for a raw pointer.
|
|
|
|
|
|
|
|
Prefer the implicit use of this operator to calling |get()|,
|
|
|
|
except where necessary to resolve ambiguity.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T*
|
|
|
|
forget()
|
|
|
|
{
|
|
|
|
T* temp = mRawPtr;
|
|
|
|
mRawPtr = 0;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
T*
|
|
|
|
operator->() const
|
2003-01-18 19:20:26 +03:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_PRECONDITION(mRawPtr != 0,
|
|
|
|
"You can't dereference a NULL nsAutoPtr with operator->().");
|
2014-05-05 21:30:39 +04:00
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
2015-07-31 04:02:00 +03:00
|
|
|
template <typename R, typename... Args>
|
|
|
|
class Proxy
|
|
|
|
{
|
|
|
|
typedef R (T::*member_function)(Args...);
|
|
|
|
T* mRawPtr;
|
|
|
|
member_function mFunction;
|
|
|
|
public:
|
|
|
|
Proxy(T* aRawPtr, member_function aFunction)
|
|
|
|
: mRawPtr(aRawPtr),
|
|
|
|
mFunction(aFunction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
template<typename... ActualArgs>
|
|
|
|
R operator()(ActualArgs&&... aArgs)
|
|
|
|
{
|
|
|
|
return ((*mRawPtr).*mFunction)(mozilla::Forward<ActualArgs>(aArgs)...);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename R, typename C, typename... Args>
|
|
|
|
Proxy<R, Args...> operator->*(R (C::*aFptr)(Args...)) const
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_PRECONDITION(mRawPtr != 0,
|
|
|
|
"You can't dereference a NULL nsAutoPtr with operator->*().");
|
2015-07-31 04:02:00 +03:00
|
|
|
return Proxy<R, Args...>(get(), aFptr);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2009-10-30 07:04:32 +03:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
nsAutoPtr<T>*
|
|
|
|
get_address()
|
|
|
|
// This is not intended to be used by clients. See |address_of|
|
|
|
|
// below.
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAutoPtr<T>*
|
|
|
|
get_address() const
|
|
|
|
// This is not intended to be used by clients. See |address_of|
|
|
|
|
// below.
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
T&
|
|
|
|
operator*() const
|
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
NS_PRECONDITION(mRawPtr != 0,
|
|
|
|
"You can't dereference a NULL nsAutoPtr with operator*().");
|
2014-05-05 21:30:39 +04:00
|
|
|
return *get();
|
|
|
|
}
|
|
|
|
|
|
|
|
T**
|
|
|
|
StartAssignment()
|
|
|
|
{
|
2003-01-18 19:20:26 +03:00
|
|
|
#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
|
2014-05-05 21:30:39 +04:00
|
|
|
return reinterpret_cast<T**>(begin_assignment());
|
2003-01-18 19:20:26 +03:00
|
|
|
#else
|
2014-05-05 21:30:39 +04:00
|
|
|
assign(0);
|
|
|
|
return reinterpret_cast<T**>(&mRawPtr);
|
2003-01-18 19:20:26 +03:00
|
|
|
#endif
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
|
|
|
};
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline nsAutoPtr<T>*
|
2014-05-13 21:41:38 +04:00
|
|
|
address_of(nsAutoPtr<T>& aPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
|
|
|
return aPtr.get_address();
|
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline const nsAutoPtr<T>*
|
2014-05-13 21:41:38 +04:00
|
|
|
address_of(const nsAutoPtr<T>& aPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
|
|
|
return aPtr.get_address();
|
|
|
|
}
|
2001-10-25 08:09:38 +04:00
|
|
|
|
2003-01-18 19:20:26 +03:00
|
|
|
template <class T>
|
|
|
|
class nsAutoPtrGetterTransfers
|
2014-05-05 21:30:39 +04:00
|
|
|
/*
|
|
|
|
...
|
|
|
|
|
|
|
|
This class is designed to be used for anonymous temporary objects in the
|
|
|
|
argument list of calls that return COM interface pointers, e.g.,
|
|
|
|
|
|
|
|
nsAutoPtr<IFoo> fooP;
|
|
|
|
...->GetTransferedPointer(getter_Transfers(fooP))
|
|
|
|
|
|
|
|
DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead.
|
|
|
|
|
|
|
|
When initialized with a |nsAutoPtr|, as in the example above, it returns
|
|
|
|
a |void**|, a |T**|, or an |nsISupports**| as needed, that the
|
|
|
|
outer call (|GetTransferedPointer| in this case) can fill in.
|
|
|
|
|
|
|
|
This type should be a nested class inside |nsAutoPtr<T>|.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit
|
2014-05-13 21:41:38 +04:00
|
|
|
nsAutoPtrGetterTransfers(nsAutoPtr<T>& aSmartPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
: mTargetSmartPtr(aSmartPtr)
|
|
|
|
{
|
|
|
|
// nothing else to do
|
|
|
|
}
|
|
|
|
|
|
|
|
operator void**()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<void**>(mTargetSmartPtr.StartAssignment());
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T**()
|
|
|
|
{
|
|
|
|
return mTargetSmartPtr.StartAssignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
T*&
|
|
|
|
operator*()
|
|
|
|
{
|
|
|
|
return *(mTargetSmartPtr.StartAssignment());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoPtr<T>& mTargetSmartPtr;
|
|
|
|
};
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline nsAutoPtrGetterTransfers<T>
|
2014-05-13 21:41:38 +04:00
|
|
|
getter_Transfers(nsAutoPtr<T>& aSmartPtr)
|
2014-05-05 21:30:39 +04:00
|
|
|
/*
|
|
|
|
Used around a |nsAutoPtr| when
|
|
|
|
...makes the class |nsAutoPtrGetterTransfers<T>| invisible.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return nsAutoPtrGetterTransfers<T>(aSmartPtr);
|
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Comparing two |nsAutoPtr|s
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator==(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator!=(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
// Comparing an |nsAutoPtr| to a raw pointer
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator==(const nsAutoPtr<T>& aLhs, const U* aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator==(const U* aLhs, const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator!=(const nsAutoPtr<T>& aLhs, const U* aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator!=(const U* aLhs, const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator==(const nsAutoPtr<T>& aLhs, U* aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) == const_cast<const U*>(aRhs);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator==(U* aLhs, const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return const_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator!=(const nsAutoPtr<T>& aLhs, U* aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return static_cast<const T*>(aLhs.get()) != const_cast<const U*>(aRhs);
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T, class U>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2014-05-13 21:41:38 +04:00
|
|
|
operator!=(U* aLhs, const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2014-05-13 21:41:38 +04:00
|
|
|
return const_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-20 03:30:10 +03:00
|
|
|
// Comparing an |nsAutoPtr| to |nullptr|
|
2001-10-25 08:09:38 +04:00
|
|
|
|
2003-01-18 19:20:26 +03:00
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2015-08-20 03:30:10 +03:00
|
|
|
operator==(const nsAutoPtr<T>& aLhs, decltype(nullptr))
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2015-08-20 03:30:10 +03:00
|
|
|
return aLhs.get() == nullptr;
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2015-08-20 03:30:10 +03:00
|
|
|
operator==(decltype(nullptr), const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2015-08-20 03:30:10 +03:00
|
|
|
return nullptr == aRhs.get();
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
2003-01-18 19:20:26 +03:00
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2015-08-20 03:30:10 +03:00
|
|
|
operator!=(const nsAutoPtr<T>& aLhs, decltype(nullptr))
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2015-08-20 03:30:10 +03:00
|
|
|
return aLhs.get() != nullptr;
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2014-05-15 00:14:58 +04:00
|
|
|
inline bool
|
2015-08-20 03:30:10 +03:00
|
|
|
operator!=(decltype(nullptr), const nsAutoPtr<T>& aRhs)
|
2014-05-05 21:30:39 +04:00
|
|
|
{
|
2015-08-20 03:30:10 +03:00
|
|
|
return nullptr != aRhs.get();
|
2014-05-05 21:30:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-09 03:27:12 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2014-09-26 21:53:47 +04:00
|
|
|
#endif // !defined(nsAutoPtr_h)
|