xpcom/glue/nsCOMPtr.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/nsCOMPtr.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsCOMPtr.h"
    1.10 +
    1.11 +nsresult
    1.12 +nsQueryInterface::operator()( const nsIID& aIID, void** answer ) const
    1.13 +	{
    1.14 +		nsresult status;
    1.15 +		if ( mRawPtr )
    1.16 +			{
    1.17 +				status = mRawPtr->QueryInterface(aIID, answer);
    1.18 +#ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
    1.19 +				NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?");
    1.20 +#endif
    1.21 +			}
    1.22 +		else
    1.23 +			status = NS_ERROR_NULL_POINTER;
    1.24 +		
    1.25 +		return status;
    1.26 +	}
    1.27 +
    1.28 +nsresult
    1.29 +nsQueryInterfaceWithError::operator()( const nsIID& aIID, void** answer ) const
    1.30 +	{
    1.31 +		nsresult status;
    1.32 +		if ( mRawPtr )
    1.33 +			{
    1.34 +				status = mRawPtr->QueryInterface(aIID, answer);
    1.35 +#ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
    1.36 +				NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?");
    1.37 +#endif
    1.38 +			}
    1.39 +		else
    1.40 +			status = NS_ERROR_NULL_POINTER;
    1.41 +		
    1.42 +		if ( mErrorPtr )
    1.43 +			*mErrorPtr = status;
    1.44 +		return status;
    1.45 +	}
    1.46 +
    1.47 +void
    1.48 +nsCOMPtr_base::assign_with_AddRef( nsISupports* rawPtr )
    1.49 +	{
    1.50 +    if ( rawPtr )
    1.51 +    	NSCAP_ADDREF(this, rawPtr);
    1.52 +    assign_assuming_AddRef(rawPtr);
    1.53 +	}
    1.54 +
    1.55 +void
    1.56 +nsCOMPtr_base::assign_from_qi( const nsQueryInterface qi, const nsIID& iid )
    1.57 +  {
    1.58 +    void* newRawPtr;
    1.59 +    if ( NS_FAILED( qi(iid, &newRawPtr) ) )
    1.60 +      newRawPtr = 0;
    1.61 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
    1.62 +  }
    1.63 +
    1.64 +void
    1.65 +nsCOMPtr_base::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& iid )
    1.66 +  {
    1.67 +    void* newRawPtr;
    1.68 +    if ( NS_FAILED( qi(iid, &newRawPtr) ) )
    1.69 +      newRawPtr = 0;
    1.70 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
    1.71 +  }
    1.72 +
    1.73 +void
    1.74 +nsCOMPtr_base::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& iid )
    1.75 +  {
    1.76 +    void* newRawPtr;
    1.77 +    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
    1.78 +      newRawPtr = 0;
    1.79 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
    1.80 +  }
    1.81 +
    1.82 +void
    1.83 +nsCOMPtr_base::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& iid )
    1.84 +  {
    1.85 +    void* newRawPtr;
    1.86 +    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
    1.87 +      newRawPtr = 0;
    1.88 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
    1.89 +  }
    1.90 +
    1.91 +void
    1.92 +nsCOMPtr_base::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& iid )
    1.93 +  {
    1.94 +    void* newRawPtr;
    1.95 +    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
    1.96 +      newRawPtr = 0;
    1.97 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
    1.98 +  }
    1.99 +
   1.100 +void
   1.101 +nsCOMPtr_base::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& iid )
   1.102 +  {
   1.103 +    void* newRawPtr;
   1.104 +    if ( NS_FAILED( gs(iid, &newRawPtr) ) )
   1.105 +      newRawPtr = 0;
   1.106 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
   1.107 +  }
   1.108 +
   1.109 +void
   1.110 +nsCOMPtr_base::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& iid )
   1.111 +  {
   1.112 +    void* newRawPtr;
   1.113 +    if ( NS_FAILED( helper(iid, &newRawPtr) ) )
   1.114 +      newRawPtr = 0;
   1.115 +    assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
   1.116 +  }
   1.117 +
   1.118 +void**
   1.119 +nsCOMPtr_base::begin_assignment()
   1.120 +  {
   1.121 +    assign_assuming_AddRef(0);
   1.122 +    return reinterpret_cast<void**>(&mRawPtr);
   1.123 +  }

mercurial