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 * 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 * 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 * The Original Code is mozilla.org code. 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 * Scott Collins <scc@mozilla.org> (original author of nsCOMPtr) 0N/A * L. David Baron <dbaron@dbaron.org> 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 * ***** END LICENSE BLOCK ***** */ 0N/A // Wrapping includes can speed up compiles (see "Large Scale C++ Software Design") 0N/A // For |already_AddRefed|, |nsDerivedSafe|, |NSCAP_Zero|, 0N/A // |NSCAP_DONT_PROVIDE_NONCONST_OPEQ|, 0N/A // |NSCAP_FEATURE_INLINE_STARTASSIGNMENT| 0N/A/*****************************************************************************/ 0N/A// template <class T> class nsAutoPtrGetterTransfers; 0N/A // default constructor 0N/A // construct from a raw pointer (of the right type) 0N/A // Construct by transferring ownership from another smart pointer. 0N/A // Assignment operators 0N/A // assign from a raw pointer (of the right type) 0N/A // assign by transferring ownership from another smart pointer. 1173N/A Prefer the implicit conversion provided automatically by 1173N/A |operator T*() const|. Use |get()| _only_ to resolve 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 Prefer the implicit use of this operator to calling |get()|, 0N/A except where necessary to resolve ambiguity. 0N/A // broken version for IRIX 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A // This is not intended to be used by clients. See |address_of| 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 1173N/A// This is the broken version for IRIX, which can't handle the version below. 1173N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 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 nsAutoPtr<IFoo> fooP; 0N/A ...->GetTransferedPointer(getter_Transfers(fooP)) 0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead. 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 This type should be a nested class inside |nsAutoPtr<T>|. 0N/A // nothing else to do 0N/A Used around a |nsAutoPtr| when 0N/A ...makes the class |nsAutoPtrGetterTransfers<T>| invisible. 0N/A // Comparing two |nsAutoPtr|s 0N/A // Comparing an |nsAutoPtr| to a raw pointer 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 // Comparing an |nsAutoPtr| to |0| 0N/A // specifically to allow |smartPtr == 0| 0N/A // specifically to allow |0 == smartPtr| 0N/A // specifically to allow |smartPtr != 0| 0N/A // specifically to allow |0 != smartPtr| 0N/A // We need to explicitly define comparison operators for `int' 0N/A // because the compiler is lame. 0N/A // specifically to allow |smartPtr == 0| 0N/A // specifically to allow |0 == smartPtr| 0N/A#
endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO) 0N/A/*****************************************************************************/ 0N/A// template <class T> class nsAutoArrayPtrGetterTransfers; 0N/A // default constructor 0N/A // construct from a raw pointer (of the right type) 0N/A // Construct by transferring ownership from another smart pointer. 0N/A // Assignment operators 0N/A // assign from a raw pointer (of the right type) 1173N/A // assign by transferring ownership from another smart pointer. 0N/A // Other pointer operators 0N/A Prefer the implicit conversion provided automatically by 0N/A |operator T*() const|. Use |get()| _only_ to resolve 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 Prefer the implicit use of this operator to calling |get()|, 0N/A except where necessary to resolve ambiguity. 0N/A // broken version for IRIX 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A // This is not intended to be used by clients. See |address_of| 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A// This is the broken version for IRIX, which can't handle the version below. 0N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 1173N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 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 nsAutoArrayPtr<IFoo> fooP; 0N/A ...->GetTransferedPointer(getter_Transfers(fooP)) 0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead. 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 This type should be a nested class inside |nsAutoArrayPtr<T>|. 0N/A // nothing else to do 0N/A Used around a |nsAutoArrayPtr| when 0N/A ...makes the class |nsAutoArrayPtrGetterTransfers<T>| invisible. 1173N/A // Comparing two |nsAutoArrayPtr|s 0N/A // Comparing an |nsAutoArrayPtr| to a raw pointer 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 // Comparing an |nsAutoArrayPtr| to |0| 0N/A // specifically to allow |smartPtr == 0| 1173N/A // specifically to allow |0 == smartPtr| 0N/A // specifically to allow |smartPtr != 0| 0N/A // specifically to allow |0 != smartPtr| 0N/A // We need to explicitly define comparison operators for `int' 0N/A // because the compiler is lame. 0N/A // specifically to allow |smartPtr == 0| 0N/A // specifically to allow |0 == smartPtr| 0N/A#
endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO) 0N/A/*****************************************************************************/ 0N/A// template <class T> class nsRefPtrGetterAddRefs; 0N/A // default constructor 0N/A // construct from a raw pointer (of the right type) 0N/A // construct from |dont_AddRef(expr)| 0N/A // Assignment operators 0N/A // copy assignment operator 0N/A // assign from a raw pointer (of the right type) 0N/A // assign from |dont_AddRef(expr)| 0N/A // Other pointer operators 0N/A // ...exchange ownership with |rhs|; can save a pair of refcount operations 0N/A // ...exchange ownership with |rhs|; can save a pair of refcount operations 0N/A Prefer the implicit conversion provided automatically by |operator nsDerivedSafe<T>*() const|. 0N/A Use |get()| _only_ to resolve ambiguity. 0N/A Returns a |nsDerivedSafe<T>*| to deny clients the use of |AddRef| and |Release|. 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 Prefer the implicit use of this operator to calling |get()|, except where necessary to resolve ambiguity. 0N/A // broken version for IRIX 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A // This is not intended to be used by clients. See |address_of| 0N/A // This is not intended to be used by clients. See |address_of| 0N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A// This is the broken version for IRIX, which can't handle the version below. 0N/A#
else // CANT_RESOLVE_CPP_CONST_AMBIGUITY 0N/A#
endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY 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 nsRefPtr<IFoo> fooP; 0N/A ...->GetAddRefedPointer(getter_AddRefs(fooP)) 0N/A DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_AddRefs()| instead. 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 This type should be a nested class inside |nsRefPtr<T>|. 0N/A // nothing else to do 0N/A Used around a |nsRefPtr| when 0N/A ...makes the class |nsRefPtrGetterAddRefs<T>| invisible. 0N/A // Comparing two |nsRefPtr|s 0N/A // Comparing an |nsRefPtr| to a raw pointer 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 // Comparing an |nsRefPtr| to |0| 0N/A // specifically to allow |smartPtr == 0| 0N/A // specifically to allow |0 == smartPtr| 0N/A // specifically to allow |smartPtr != 0| 0N/A // specifically to allow |0 != smartPtr| 0N/A // We need to explicitly define comparison operators for `int' 0N/A // because the compiler is lame. 0N/A // specifically to allow |smartPtr == 0| 0N/A // specifically to allow |0 == smartPtr| 0N/A#
endif // !defined(HAVE_CPP_TROUBLE_COMPARING_TO_ZERO) 0N/A/*****************************************************************************/ 0N/A#
endif // !defined(nsAutoPtr_h___)