michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: nsresult michael@0: nsQueryInterface::operator()( const nsIID& aIID, void** answer ) const michael@0: { michael@0: nsresult status; michael@0: if ( mRawPtr ) michael@0: { michael@0: status = mRawPtr->QueryInterface(aIID, answer); michael@0: #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS michael@0: NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?"); michael@0: #endif michael@0: } michael@0: else michael@0: status = NS_ERROR_NULL_POINTER; michael@0: michael@0: return status; michael@0: } michael@0: michael@0: nsresult michael@0: nsQueryInterfaceWithError::operator()( const nsIID& aIID, void** answer ) const michael@0: { michael@0: nsresult status; michael@0: if ( mRawPtr ) michael@0: { michael@0: status = mRawPtr->QueryInterface(aIID, answer); michael@0: #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS michael@0: NS_ASSERTION(NS_SUCCEEDED(status), "interface not found---were you expecting that?"); michael@0: #endif michael@0: } michael@0: else michael@0: status = NS_ERROR_NULL_POINTER; michael@0: michael@0: if ( mErrorPtr ) michael@0: *mErrorPtr = status; michael@0: return status; michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_with_AddRef( nsISupports* rawPtr ) michael@0: { michael@0: if ( rawPtr ) michael@0: NSCAP_ADDREF(this, rawPtr); michael@0: assign_assuming_AddRef(rawPtr); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_qi( const nsQueryInterface qi, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( qi(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_qi_with_error( const nsQueryInterfaceWithError& qi, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( qi(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_gs_cid( const nsGetServiceByCID gs, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( gs(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_gs_cid_with_error( const nsGetServiceByCIDWithError& gs, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( gs(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_gs_contractid( const nsGetServiceByContractID gs, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( gs(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_gs_contractid_with_error( const nsGetServiceByContractIDWithError& gs, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( gs(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void michael@0: nsCOMPtr_base::assign_from_helper( const nsCOMPtr_helper& helper, const nsIID& iid ) michael@0: { michael@0: void* newRawPtr; michael@0: if ( NS_FAILED( helper(iid, &newRawPtr) ) ) michael@0: newRawPtr = 0; michael@0: assign_assuming_AddRef(static_cast(newRawPtr)); michael@0: } michael@0: michael@0: void** michael@0: nsCOMPtr_base::begin_assignment() michael@0: { michael@0: assign_assuming_AddRef(0); michael@0: return reinterpret_cast(&mRawPtr); michael@0: }