nsAutoPtr.h revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3261N/A/* ***** BEGIN LICENSE BLOCK *****
0N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0N/A *
0N/A * The contents of this file are subject to the Mozilla Public License Version
0N/A * 1.1 (the "License"); you may not use this file except in compliance with
2362N/A * the License. You may obtain a copy of the License at
0N/A * http://www.mozilla.org/MPL/
2362N/A *
0N/A * Software distributed under the License is distributed on an "AS IS" basis,
0N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0N/A * for the specific language governing rights and limitations under the
0N/A * License.
0N/A *
0N/A * The Original Code is mozilla.org code.
0N/A *
0N/A * The Initial Developer of the Original Code is
0N/A * Netscape Communications Corporation.
0N/A * Portions created by the Initial Developer are Copyright (C) 1998
0N/A * the Initial Developer. All Rights Reserved.
2362N/A *
2362N/A * Contributor(s):
2362N/A * Scott Collins <scc@mozilla.org> (original author of nsCOMPtr)
0N/A * L. David Baron <dbaron@dbaron.org>
0N/A *
0N/A * Alternatively, the contents of this file may be used under the terms of
0N/A * either of the GNU General Public License Version 2 or later (the "GPL"),
0N/A * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0N/A * in which case the provisions of the GPL or the LGPL are applicable instead
0N/A * of those above. If you wish to allow use of your version of this file only
0N/A * under the terms of either the GPL or the LGPL, and not to allow others to
0N/A * use your version of this file under the terms of the MPL, indicate your
0N/A * decision by deleting the provisions above and replace them with the notice
0N/A * and other provisions required by the GPL or the LGPL. If you do not delete
0N/A * the provisions above, a recipient may use your version of this file under
0N/A * the terms of any one of the MPL, the GPL or the LGPL.
0N/A *
0N/A * ***** END LICENSE BLOCK ***** */
0N/A
0N/A#ifndef nsAutoPtr_h___
0N/A#define nsAutoPtr_h___
0N/A
0N/A // Wrapping includes can speed up compiles (see "Large Scale C++ Software Design")
0N/A#ifndef nsCOMPtr_h___
0N/A // For |already_AddRefed|, |nsDerivedSafe|, |NSCAP_Zero|,
0N/A // |NSCAP_DONT_PROVIDE_NONCONST_OPEQ|,
0N/A // |NSCAP_FEATURE_INLINE_STARTASSIGNMENT|
0N/A#include "nsCOMPtr.h"
0N/A#endif
0N/A
0N/A/*****************************************************************************/
0N/A
0N/A// template <class T> class nsAutoPtrGetterTransfers;
0N/A
0N/Atemplate <class T>
0N/Aclass nsAutoPtr
0N/A {
0N/A private:
0N/A void**
0N/A begin_assignment()
0N/A {
0N/A assign(0);
0N/A return NS_REINTERPRET_CAST(void**, &mRawPtr);
0N/A }
0N/A
0N/A void
0N/A assign( T* newPtr )
0N/A {
0N/A T* oldPtr = mRawPtr;
0N/A mRawPtr = newPtr;
0N/A delete oldPtr;
0N/A }
0N/A
0N/A private:
0N/A T* mRawPtr;
0N/A
0N/A public:
0N/A typedef T element_type;
0N/A
0N/A ~nsAutoPtr()
0N/A {
0N/A delete mRawPtr;
0N/A }
0N/A
0N/A // Constructors
0N/A
0N/A nsAutoPtr()
0N/A : mRawPtr(0)
0N/A // default constructor
0N/A {
0N/A }
0N/A
0N/A nsAutoPtr( T* aRawPtr )
0N/A : mRawPtr(aRawPtr)
0N/A // construct from a raw pointer (of the right type)
1999N/A {
1999N/A }
0N/A
1999N/A nsAutoPtr( nsAutoPtr<T>& aSmartPtr )
1999N/A : mRawPtr( aSmartPtr.forget() )
0N/A // Construct by transferring ownership from another smart pointer.
1999N/A {
0N/A }
0N/A
0N/A
0N/A // Assignment operators
0N/A
0N/A nsAutoPtr<T>&
0N/A operator=( T* rhs )
0N/A // assign from a raw pointer (of the right type)
0N/A {
0N/A assign(rhs);
0N/A return *this;
0N/A }
0N/A
0N/A nsAutoPtr<T>& operator=( nsAutoPtr<T>& rhs )
0N/A // assign by transferring ownership from another smart pointer.
1173N/A {
1173N/A assign(rhs.forget());
1173N/A return *this;
1173N/A }
1173N/A
1999N/A // Other pointer operators
1173N/A
1999N/A T*
1173N/A get() const
1173N/A /*
1173N/A Prefer the implicit conversion provided automatically by
1173N/A |operator T*() const|. Use |get()| _only_ to resolve
1173N/A ambiguity.
1173N/A */
1999N/A {
1173N/A return mRawPtr;
1999N/A }
1173N/A
0N/A operator T*() const
0N/A /*
0N/A ...makes an |nsAutoPtr| act like its underlying raw pointer
0N/A type whenever it is used in a context where a raw pointer
0N/A is expected. It is this operator that makes an |nsAutoPtr|
0N/A substitutable for a raw pointer.
0N/A
0N/A Prefer the implicit use of this operator to calling |get()|,
0N/A except where necessary to resolve ambiguity.
0N/A */
0N/A {
0N/A return get();
0N/A }
0N/A
0N/A T*
0N/A forget()
0N/A {
0N/A T* temp = mRawPtr;
0N/A mRawPtr = 0;
0N/A return temp;
0N/A }
0N/A
0N/A T*
0N/A operator->() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsAutoPtr with operator->().");
0N/A return get();
0N/A }
0N/A
0N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A // broken version for IRIX
0N/A
0N/A nsAutoPtr<T>*
0N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return NS_CONST_CAST(nsAutoPtr<T>*, this);
0N/A }
0N/A
0N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A nsAutoPtr<T>*
0N/A get_address()
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A const nsAutoPtr<T>*
0N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A public:
0N/A T&
0N/A operator*() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsAutoPtr with operator*().");
0N/A return *get();
0N/A }
0N/A
0N/A T**
0N/A StartAssignment()
0N/A {
0N/A#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
0N/A return NS_REINTERPRET_CAST(T**, begin_assignment());
0N/A#else
1173N/A assign(0);
1173N/A return NS_REINTERPRET_CAST(T**, &mRawPtr);
1173N/A#endif
1173N/A }
1173N/A };
1173N/A
1173N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
1173N/A
1173N/A// This is the broken version for IRIX, which can't handle the version below.
1173N/A
1173N/Atemplate <class T>
1173N/Ainline
1173N/AnsAutoPtr<T>*
1173N/Aaddress_of( const nsAutoPtr<T>& aPtr )
1173N/A {
1173N/A return aPtr.get_address();
1173N/A }
1173N/A
1173N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
1173N/A
1173N/Atemplate <class T>
1173N/Ainline
1173N/AnsAutoPtr<T>*
1173N/Aaddress_of( nsAutoPtr<T>& aPtr )
1173N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/Aconst nsAutoPtr<T>*
0N/Aaddress_of( const nsAutoPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/Atemplate <class T>
0N/Aclass nsAutoPtrGetterTransfers
0N/A /*
0N/A ...
0N/A
0N/A This class is designed to be used for anonymous temporary objects in the
0N/A argument list of calls that return COM interface pointers, e.g.,
0N/A
0N/A nsAutoPtr<IFoo> fooP;
0N/A ...->GetTransferedPointer(getter_Transfers(fooP))
0N/A
0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead.
0N/A
0N/A When initialized with a |nsAutoPtr|, as in the example above, it returns
0N/A a |void**|, a |T**|, or an |nsISupports**| as needed, that the
0N/A outer call (|GetTransferedPointer| in this case) can fill in.
0N/A
0N/A This type should be a nested class inside |nsAutoPtr<T>|.
0N/A */
0N/A {
0N/A public:
0N/A explicit
0N/A nsAutoPtrGetterTransfers( nsAutoPtr<T>& aSmartPtr )
0N/A : mTargetSmartPtr(aSmartPtr)
0N/A {
0N/A // nothing else to do
0N/A }
0N/A
0N/A operator void**()
0N/A {
0N/A return NS_REINTERPRET_CAST(void**, mTargetSmartPtr.StartAssignment());
0N/A }
0N/A
0N/A operator T**()
0N/A {
0N/A return mTargetSmartPtr.StartAssignment();
0N/A }
0N/A
0N/A T*&
0N/A operator*()
0N/A {
0N/A return *(mTargetSmartPtr.StartAssignment());
0N/A }
0N/A
0N/A private:
0N/A nsAutoPtr<T>& mTargetSmartPtr;
0N/A };
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsAutoPtrGetterTransfers<T>
0N/Agetter_Transfers( nsAutoPtr<T>& aSmartPtr )
0N/A /*
0N/A Used around a |nsAutoPtr| when
0N/A ...makes the class |nsAutoPtrGetterTransfers<T>| invisible.
0N/A */
0N/A {
0N/A return nsAutoPtrGetterTransfers<T>(aSmartPtr);
0N/A }
0N/A
0N/A
0N/A
0N/A // Comparing two |nsAutoPtr|s
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoPtr<T>& lhs, const nsAutoPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoPtr<T>& lhs, const nsAutoPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/A // Comparing an |nsAutoPtr| to a raw pointer
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoPtr<T>& lhs, const U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const U* lhs, const nsAutoPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoPtr<T>& lhs, const U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const U* lhs, const nsAutoPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/A // To avoid ambiguities caused by the presence of builtin |operator==|s
0N/A // creating a situation where one of the |operator==| defined above
0N/A // has a better conversion for one argument and the builtin has a
0N/A // better conversion for the other argument, define additional
0N/A // |operator==| without the |const| on the raw pointer.
0N/A // See bug 65664 for details.
0N/A
0N/A#ifndef NSCAP_DONT_PROVIDE_NONCONST_OPEQ
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoPtr<T>& lhs, U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( U* lhs, const nsAutoPtr<T>& rhs )
0N/A {
0N/A return NS_CONST_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoPtr<T>& lhs, U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( U* lhs, const nsAutoPtr<T>& rhs )
0N/A {
0N/A return NS_CONST_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A#endif
0N/A
0N/A
0N/A
0N/A // Comparing an |nsAutoPtr| to |0|
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( NSCAP_Zero* lhs, const nsAutoPtr<T>& rhs )
0N/A // specifically to allow |0 == smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr != 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) != NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( NSCAP_Zero* lhs, const nsAutoPtr<T>& rhs )
0N/A // specifically to allow |0 != smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) != NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A
0N/A#ifdef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO
0N/A
0N/A // We need to explicitly define comparison operators for `int'
0N/A // because the compiler is lame.
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoPtr<T>& lhs, int rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( int lhs, const nsAutoPtr<T>& rhs )
0N/A // specifically to allow |0 == smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A#endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO)
0N/A
0N/A/*****************************************************************************/
0N/A
0N/A// template <class T> class nsAutoArrayPtrGetterTransfers;
0N/A
0N/Atemplate <class T>
0N/Aclass nsAutoArrayPtr
0N/A {
0N/A private:
0N/A void**
0N/A begin_assignment()
0N/A {
0N/A assign(0);
0N/A return NS_REINTERPRET_CAST(void**, &mRawPtr);
0N/A }
0N/A
0N/A void
0N/A assign( T* newPtr )
0N/A {
0N/A T* oldPtr = mRawPtr;
0N/A mRawPtr = newPtr;
1173N/A delete [] oldPtr;
0N/A }
1173N/A
0N/A private:
0N/A T* mRawPtr;
0N/A
1173N/A public:
1173N/A typedef T element_type;
1173N/A
1173N/A ~nsAutoArrayPtr()
0N/A {
0N/A delete [] mRawPtr;
1173N/A }
0N/A
0N/A // Constructors
0N/A
1173N/A nsAutoArrayPtr()
0N/A : mRawPtr(0)
0N/A // default constructor
0N/A {
0N/A }
0N/A
0N/A nsAutoArrayPtr( T* aRawPtr )
0N/A : mRawPtr(aRawPtr)
0N/A // construct from a raw pointer (of the right type)
0N/A {
0N/A }
0N/A
0N/A nsAutoArrayPtr( nsAutoArrayPtr<T>& aSmartPtr )
0N/A : mRawPtr( aSmartPtr.forget() )
0N/A // Construct by transferring ownership from another smart pointer.
0N/A {
1173N/A }
0N/A
0N/A
0N/A // Assignment operators
1173N/A
0N/A nsAutoArrayPtr<T>&
0N/A operator=( T* rhs )
0N/A // assign from a raw pointer (of the right type)
1173N/A {
1173N/A assign(rhs);
1173N/A return *this;
0N/A }
0N/A
0N/A nsAutoArrayPtr<T>& operator=( nsAutoArrayPtr<T>& rhs )
1173N/A // assign by transferring ownership from another smart pointer.
0N/A {
1173N/A assign(rhs.forget());
0N/A return *this;
0N/A }
0N/A
0N/A // Other pointer operators
0N/A
0N/A T*
0N/A get() const
0N/A /*
0N/A Prefer the implicit conversion provided automatically by
0N/A |operator T*() const|. Use |get()| _only_ to resolve
0N/A ambiguity.
0N/A */
0N/A {
0N/A return mRawPtr;
0N/A }
0N/A
0N/A operator T*() const
0N/A /*
0N/A ...makes an |nsAutoArrayPtr| act like its underlying raw pointer
0N/A type whenever it is used in a context where a raw pointer
0N/A is expected. It is this operator that makes an |nsAutoArrayPtr|
0N/A substitutable for a raw pointer.
0N/A
0N/A Prefer the implicit use of this operator to calling |get()|,
0N/A except where necessary to resolve ambiguity.
0N/A */
0N/A {
0N/A return get();
0N/A }
0N/A
0N/A T*
0N/A forget()
0N/A {
0N/A T* temp = mRawPtr;
0N/A mRawPtr = 0;
0N/A return temp;
0N/A }
0N/A
0N/A T*
0N/A operator->() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsAutoArrayPtr with operator->().");
0N/A return get();
0N/A }
0N/A
0N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A // broken version for IRIX
0N/A
0N/A nsAutoArrayPtr<T>*
0N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
1999N/A {
0N/A return NS_CONST_CAST(nsAutoArrayPtr<T>*, this);
0N/A }
0N/A
0N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A nsAutoArrayPtr<T>*
0N/A get_address()
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A const nsAutoArrayPtr<T>*
1999N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A public:
0N/A T&
0N/A operator*() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsAutoArrayPtr with operator*().");
0N/A return *get();
0N/A }
0N/A
0N/A T**
0N/A StartAssignment()
0N/A {
0N/A#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
0N/A return NS_REINTERPRET_CAST(T**, begin_assignment());
0N/A#else
0N/A assign(0);
0N/A return NS_REINTERPRET_CAST(T**, &mRawPtr);
0N/A#endif
0N/A }
0N/A };
0N/A
0N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A// This is the broken version for IRIX, which can't handle the version below.
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsAutoArrayPtr<T>*
0N/Aaddress_of( const nsAutoArrayPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsAutoArrayPtr<T>*
0N/Aaddress_of( nsAutoArrayPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/Aconst nsAutoArrayPtr<T>*
0N/Aaddress_of( const nsAutoArrayPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
1173N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
1173N/A
0N/Atemplate <class T>
0N/Aclass nsAutoArrayPtrGetterTransfers
0N/A /*
1173N/A ...
1173N/A
0N/A This class is designed to be used for anonymous temporary objects in the
0N/A argument list of calls that return COM interface pointers, e.g.,
0N/A
0N/A nsAutoArrayPtr<IFoo> fooP;
0N/A ...->GetTransferedPointer(getter_Transfers(fooP))
0N/A
0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead.
0N/A
0N/A When initialized with a |nsAutoArrayPtr|, as in the example above, it returns
0N/A a |void**|, a |T**|, or an |nsISupports**| as needed, that the
0N/A outer call (|GetTransferedPointer| in this case) can fill in.
0N/A
0N/A This type should be a nested class inside |nsAutoArrayPtr<T>|.
0N/A */
0N/A {
0N/A public:
0N/A explicit
1173N/A nsAutoArrayPtrGetterTransfers( nsAutoArrayPtr<T>& aSmartPtr )
0N/A : mTargetSmartPtr(aSmartPtr)
0N/A {
0N/A // nothing else to do
1173N/A }
0N/A
0N/A operator void**()
0N/A {
0N/A return NS_REINTERPRET_CAST(void**, mTargetSmartPtr.StartAssignment());
0N/A }
0N/A
0N/A operator T**()
0N/A {
0N/A return mTargetSmartPtr.StartAssignment();
0N/A }
0N/A
0N/A T*&
0N/A operator*()
0N/A {
0N/A return *(mTargetSmartPtr.StartAssignment());
1173N/A }
1173N/A
0N/A private:
0N/A nsAutoArrayPtr<T>& mTargetSmartPtr;
0N/A };
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsAutoArrayPtrGetterTransfers<T>
0N/Agetter_Transfers( nsAutoArrayPtr<T>& aSmartPtr )
0N/A /*
0N/A Used around a |nsAutoArrayPtr| when
0N/A ...makes the class |nsAutoArrayPtrGetterTransfers<T>| invisible.
0N/A */
0N/A {
0N/A return nsAutoArrayPtrGetterTransfers<T>(aSmartPtr);
0N/A }
0N/A
0N/A
1173N/A
1173N/A // Comparing two |nsAutoArrayPtr|s
0N/A
1173N/Atemplate <class T, class U>
1173N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoArrayPtr<T>& lhs, const nsAutoArrayPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoArrayPtr<T>& lhs, const nsAutoArrayPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/A // Comparing an |nsAutoArrayPtr| to a raw pointer
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoArrayPtr<T>& lhs, const U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const U* lhs, const nsAutoArrayPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
1173N/Atemplate <class T, class U>
1173N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoArrayPtr<T>& lhs, const U* rhs )
1173N/A {
1173N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
1173N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const U* lhs, const nsAutoArrayPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/A // To avoid ambiguities caused by the presence of builtin |operator==|s
0N/A // creating a situation where one of the |operator==| defined above
0N/A // has a better conversion for one argument and the builtin has a
0N/A // better conversion for the other argument, define additional
0N/A // |operator==| without the |const| on the raw pointer.
0N/A // See bug 65664 for details.
0N/A
0N/A#ifndef NSCAP_DONT_PROVIDE_NONCONST_OPEQ
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoArrayPtr<T>& lhs, U* rhs )
1173N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( U* lhs, const nsAutoArrayPtr<T>& rhs )
1173N/A {
0N/A return NS_CONST_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoArrayPtr<T>& lhs, U* rhs )
0N/A {
1173N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( U* lhs, const nsAutoArrayPtr<T>& rhs )
0N/A {
1173N/A return NS_CONST_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
1173N/A }
0N/A#endif
0N/A
0N/A
0N/A
0N/A // Comparing an |nsAutoArrayPtr| to |0|
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoArrayPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
1173N/Ainline
1173N/ANSCAP_BOOL
0N/Aoperator==( NSCAP_Zero* lhs, const nsAutoArrayPtr<T>& rhs )
1173N/A // specifically to allow |0 == smartPtr|
1173N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsAutoArrayPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr != 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) != NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( NSCAP_Zero* lhs, const nsAutoArrayPtr<T>& rhs )
0N/A // specifically to allow |0 != smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) != NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A
0N/A#ifdef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO
0N/A
0N/A // We need to explicitly define comparison operators for `int'
0N/A // because the compiler is lame.
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsAutoArrayPtr<T>& lhs, int rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( int lhs, const nsAutoArrayPtr<T>& rhs )
0N/A // specifically to allow |0 == smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A#endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO)
0N/A
0N/A
0N/A/*****************************************************************************/
0N/A
0N/A// template <class T> class nsRefPtrGetterAddRefs;
0N/A
0N/Atemplate <class T>
0N/Aclass nsRefPtr
0N/A {
0N/A private:
0N/A
0N/A void
0N/A assign_with_AddRef( T* rawPtr )
0N/A {
0N/A if ( rawPtr )
0N/A rawPtr->AddRef();
0N/A assign_assuming_AddRef(rawPtr);
0N/A }
0N/A
0N/A void**
0N/A begin_assignment()
0N/A {
0N/A assign_assuming_AddRef(0);
0N/A return NS_REINTERPRET_CAST(void**, &mRawPtr);
0N/A }
0N/A
0N/A void
0N/A assign_assuming_AddRef( T* newPtr )
0N/A {
0N/A T* oldPtr = mRawPtr;
0N/A mRawPtr = newPtr;
0N/A if ( oldPtr )
0N/A oldPtr->Release();
0N/A }
0N/A
0N/A private:
0N/A T* mRawPtr;
0N/A
0N/A public:
0N/A typedef T element_type;
0N/A
0N/A ~nsRefPtr()
0N/A {
0N/A if ( mRawPtr )
0N/A mRawPtr->Release();
0N/A }
0N/A
0N/A // Constructors
0N/A
0N/A nsRefPtr()
0N/A : mRawPtr(0)
0N/A // default constructor
0N/A {
0N/A }
0N/A
0N/A nsRefPtr( const nsRefPtr<T>& aSmartPtr )
0N/A : mRawPtr(aSmartPtr.mRawPtr)
0N/A // copy-constructor
0N/A {
0N/A if ( mRawPtr )
0N/A mRawPtr->AddRef();
0N/A }
0N/A
0N/A nsRefPtr( T* aRawPtr )
0N/A : mRawPtr(aRawPtr)
0N/A // construct from a raw pointer (of the right type)
0N/A {
0N/A if ( mRawPtr )
0N/A mRawPtr->AddRef();
0N/A }
0N/A
0N/A nsRefPtr( const already_AddRefed<T>& aSmartPtr )
0N/A : mRawPtr(aSmartPtr.mRawPtr)
0N/A // construct from |dont_AddRef(expr)|
0N/A {
0N/A }
0N/A
0N/A // Assignment operators
0N/A
0N/A nsRefPtr<T>&
0N/A operator=( const nsRefPtr<T>& rhs )
0N/A // copy assignment operator
0N/A {
0N/A assign_with_AddRef(rhs.mRawPtr);
0N/A return *this;
0N/A }
0N/A
0N/A nsRefPtr<T>&
0N/A operator=( T* rhs )
0N/A // assign from a raw pointer (of the right type)
0N/A {
0N/A assign_with_AddRef(rhs);
0N/A return *this;
0N/A }
0N/A
0N/A nsRefPtr<T>&
0N/A operator=( const already_AddRefed<T>& rhs )
0N/A // assign from |dont_AddRef(expr)|
0N/A {
0N/A assign_assuming_AddRef(rhs.mRawPtr);
0N/A return *this;
0N/A }
0N/A
0N/A // Other pointer operators
0N/A
0N/A void
0N/A swap( nsRefPtr<T>& rhs )
0N/A // ...exchange ownership with |rhs|; can save a pair of refcount operations
0N/A {
0N/A T* temp = rhs.mRawPtr;
0N/A rhs.mRawPtr = mRawPtr;
0N/A mRawPtr = temp;
0N/A }
0N/A
0N/A void
0N/A swap( T*& rhs )
0N/A // ...exchange ownership with |rhs|; can save a pair of refcount operations
0N/A {
0N/A T* temp = rhs;
0N/A rhs = mRawPtr;
0N/A mRawPtr = temp;
0N/A }
0N/A
0N/A nsDerivedSafe<T>*
0N/A get() const
0N/A /*
0N/A Prefer the implicit conversion provided automatically by |operator nsDerivedSafe<T>*() const|.
0N/A Use |get()| _only_ to resolve ambiguity.
0N/A
0N/A Returns a |nsDerivedSafe<T>*| to deny clients the use of |AddRef| and |Release|.
0N/A */
0N/A {
0N/A return NS_CONST_CAST(nsDerivedSafe<T>*,
0N/A NS_REINTERPRET_CAST(const nsDerivedSafe<T>*, mRawPtr));
0N/A }
0N/A
0N/A operator nsDerivedSafe<T>*() const
0N/A /*
0N/A ...makes an |nsRefPtr| act like its underlying raw pointer type (except against |AddRef()|, |Release()|,
0N/A and |delete|) whenever it is used in a context where a raw pointer is expected. It is this operator
0N/A that makes an |nsRefPtr| substitutable for a raw pointer.
0N/A
0N/A Prefer the implicit use of this operator to calling |get()|, except where necessary to resolve ambiguity.
0N/A */
0N/A {
0N/A return get();
0N/A }
0N/A
0N/A nsDerivedSafe<T>*
0N/A operator->() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsRefPtr with operator->().");
0N/A return get();
0N/A }
0N/A
0N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A // broken version for IRIX
0N/A
0N/A nsRefPtr<T>*
0N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return NS_CONST_CAST(nsRefPtr<T>*, this);
0N/A }
0N/A
0N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A nsRefPtr<T>*
0N/A get_address()
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A const nsRefPtr<T>*
0N/A get_address() const
0N/A // This is not intended to be used by clients. See |address_of|
0N/A // below.
0N/A {
0N/A return this;
0N/A }
0N/A
0N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A public:
0N/A nsDerivedSafe<T>&
0N/A operator*() const
0N/A {
0N/A NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsRefPtr with operator*().");
0N/A return *get();
0N/A }
0N/A
0N/A T**
0N/A StartAssignment()
0N/A {
0N/A#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
0N/A return NS_REINTERPRET_CAST(T**, begin_assignment());
0N/A#else
0N/A assign_assuming_AddRef(0);
0N/A return NS_REINTERPRET_CAST(T**, &mRawPtr);
0N/A#endif
0N/A }
0N/A };
0N/A
0N/A#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/A// This is the broken version for IRIX, which can't handle the version below.
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsRefPtr<T>*
0N/Aaddress_of( const nsRefPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/A#else // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsRefPtr<T>*
0N/Aaddress_of( nsRefPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/Aconst nsRefPtr<T>*
0N/Aaddress_of( const nsRefPtr<T>& aPtr )
0N/A {
0N/A return aPtr.get_address();
0N/A }
0N/A
0N/A#endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY
0N/A
0N/Atemplate <class T>
0N/Aclass nsRefPtrGetterAddRefs
0N/A /*
0N/A ...
0N/A
0N/A This class is designed to be used for anonymous temporary objects in the
0N/A argument list of calls that return COM interface pointers, e.g.,
0N/A
0N/A nsRefPtr<IFoo> fooP;
0N/A ...->GetAddRefedPointer(getter_AddRefs(fooP))
0N/A
0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_AddRefs()| instead.
0N/A
0N/A When initialized with a |nsRefPtr|, as in the example above, it returns
0N/A a |void**|, a |T**|, or an |nsISupports**| as needed, that the
0N/A outer call (|GetAddRefedPointer| in this case) can fill in.
0N/A
0N/A This type should be a nested class inside |nsRefPtr<T>|.
0N/A */
0N/A {
0N/A public:
0N/A explicit
0N/A nsRefPtrGetterAddRefs( nsRefPtr<T>& aSmartPtr )
0N/A : mTargetSmartPtr(aSmartPtr)
0N/A {
0N/A // nothing else to do
0N/A }
0N/A
0N/A operator void**()
0N/A {
0N/A return NS_REINTERPRET_CAST(void**, mTargetSmartPtr.StartAssignment());
0N/A }
0N/A
0N/A operator T**()
0N/A {
0N/A return mTargetSmartPtr.StartAssignment();
0N/A }
0N/A
0N/A T*&
0N/A operator*()
0N/A {
0N/A return *(mTargetSmartPtr.StartAssignment());
0N/A }
0N/A
0N/A private:
0N/A nsRefPtr<T>& mTargetSmartPtr;
0N/A };
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/AnsRefPtrGetterAddRefs<T>
0N/Agetter_AddRefs( nsRefPtr<T>& aSmartPtr )
0N/A /*
0N/A Used around a |nsRefPtr| when
0N/A ...makes the class |nsRefPtrGetterAddRefs<T>| invisible.
0N/A */
0N/A {
0N/A return nsRefPtrGetterAddRefs<T>(aSmartPtr);
0N/A }
0N/A
0N/A
0N/A
0N/A // Comparing two |nsRefPtr|s
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsRefPtr<T>& lhs, const nsRefPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsRefPtr<T>& lhs, const nsRefPtr<U>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs.get());
0N/A }
0N/A
0N/A
0N/A // Comparing an |nsRefPtr| to a raw pointer
0N/A
1173N/Atemplate <class T, class U>
1173N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsRefPtr<T>& lhs, const U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_STATIC_CAST(const U*, rhs);
0N/A }
1173N/A
1173N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const U* lhs, const nsRefPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsRefPtr<T>& lhs, const U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_STATIC_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const U* lhs, const nsRefPtr<T>& rhs )
0N/A {
0N/A return NS_STATIC_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/A // To avoid ambiguities caused by the presence of builtin |operator==|s
0N/A // creating a situation where one of the |operator==| defined above
0N/A // has a better conversion for one argument and the builtin has a
0N/A // better conversion for the other argument, define additional
0N/A // |operator==| without the |const| on the raw pointer.
0N/A // See bug 65664 for details.
0N/A
0N/A#ifndef NSCAP_DONT_PROVIDE_NONCONST_OPEQ
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsRefPtr<T>& lhs, U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) == NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( U* lhs, const nsRefPtr<T>& rhs )
0N/A {
0N/A return NS_CONST_CAST(const U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsRefPtr<T>& lhs, U* rhs )
0N/A {
0N/A return NS_STATIC_CAST(const T*, lhs.get()) != NS_CONST_CAST(const U*, rhs);
0N/A }
0N/A
0N/Atemplate <class T, class U>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( U* lhs, const nsRefPtr<T>& rhs )
0N/A {
0N/A return NS_CONST_CAST(const U*, lhs) != NS_STATIC_CAST(const T*, rhs.get());
0N/A }
0N/A#endif
0N/A
0N/A
0N/A
0N/A // Comparing an |nsRefPtr| to |0|
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsRefPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( NSCAP_Zero* lhs, const nsRefPtr<T>& rhs )
0N/A // specifically to allow |0 == smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( const nsRefPtr<T>& lhs, NSCAP_Zero* rhs )
0N/A // specifically to allow |smartPtr != 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) != NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator!=( NSCAP_Zero* lhs, const nsRefPtr<T>& rhs )
0N/A // specifically to allow |0 != smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) != NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A
0N/A#ifdef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO
0N/A
0N/A // We need to explicitly define comparison operators for `int'
0N/A // because the compiler is lame.
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( const nsRefPtr<T>& lhs, int rhs )
0N/A // specifically to allow |smartPtr == 0|
0N/A {
0N/A return NS_STATIC_CAST(const void*, lhs.get()) == NS_REINTERPRET_CAST(const void*, rhs);
0N/A }
0N/A
0N/Atemplate <class T>
0N/Ainline
0N/ANSCAP_BOOL
0N/Aoperator==( int lhs, const nsRefPtr<T>& rhs )
0N/A // specifically to allow |0 == smartPtr|
0N/A {
0N/A return NS_REINTERPRET_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
0N/A }
0N/A
0N/A#endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO)
0N/A
0N/A/*****************************************************************************/
0N/A
0N/A#endif // !defined(nsAutoPtr_h___)
0N/A