Bumping manifests a=b2g-bump
[gecko.git] / xpcom / glue / nsCOMPtr.cpp
blobec92068db1642f29f178e3969f6633af7074200f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsCOMPtr.h"
9 nsresult
10 nsQueryInterface::operator()(const nsIID& aIID, void** aAnswer) const
12 nsresult status;
13 if (mRawPtr) {
14 status = mRawPtr->QueryInterface(aIID, aAnswer);
15 #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
16 NS_ASSERTION(NS_SUCCEEDED(status),
17 "interface not found---were you expecting that?");
18 #endif
19 } else {
20 status = NS_ERROR_NULL_POINTER;
23 return status;
26 nsresult
27 nsQueryInterfaceWithError::operator()(const nsIID& aIID, void** aAnswer) const
29 nsresult status;
30 if (mRawPtr) {
31 status = mRawPtr->QueryInterface(aIID, aAnswer);
32 #ifdef NSCAP_FEATURE_TEST_NONNULL_QUERY_SUCCEEDS
33 NS_ASSERTION(NS_SUCCEEDED(status),
34 "interface not found---were you expecting that?");
35 #endif
36 } else {
37 status = NS_ERROR_NULL_POINTER;
40 if (mErrorPtr) {
41 *mErrorPtr = status;
43 return status;
46 void
47 nsCOMPtr_base::assign_with_AddRef(nsISupports* aRawPtr)
49 if (aRawPtr) {
50 NSCAP_ADDREF(this, aRawPtr);
52 assign_assuming_AddRef(aRawPtr);
55 void
56 nsCOMPtr_base::assign_from_qi(const nsQueryInterface aQI, const nsIID& aIID)
58 void* newRawPtr;
59 if (NS_FAILED(aQI(aIID, &newRawPtr))) {
60 newRawPtr = 0;
62 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
65 void
66 nsCOMPtr_base::assign_from_qi_with_error(const nsQueryInterfaceWithError& aQI,
67 const nsIID& aIID)
69 void* newRawPtr;
70 if (NS_FAILED(aQI(aIID, &newRawPtr))) {
71 newRawPtr = 0;
73 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
76 void
77 nsCOMPtr_base::assign_from_gs_cid(const nsGetServiceByCID aGS,
78 const nsIID& aIID)
80 void* newRawPtr;
81 if (NS_FAILED(aGS(aIID, &newRawPtr))) {
82 newRawPtr = 0;
84 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
87 void
88 nsCOMPtr_base::assign_from_gs_cid_with_error(
89 const nsGetServiceByCIDWithError& aGS, const nsIID& aIID)
91 void* newRawPtr;
92 if (NS_FAILED(aGS(aIID, &newRawPtr))) {
93 newRawPtr = 0;
95 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
98 void
99 nsCOMPtr_base::assign_from_gs_contractid(const nsGetServiceByContractID aGS,
100 const nsIID& aIID)
102 void* newRawPtr;
103 if (NS_FAILED(aGS(aIID, &newRawPtr))) {
104 newRawPtr = 0;
106 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
109 void
110 nsCOMPtr_base::assign_from_gs_contractid_with_error(
111 const nsGetServiceByContractIDWithError& aGS, const nsIID& aIID)
113 void* newRawPtr;
114 if (NS_FAILED(aGS(aIID, &newRawPtr))) {
115 newRawPtr = 0;
117 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
120 void
121 nsCOMPtr_base::assign_from_helper(const nsCOMPtr_helper& aHelper,
122 const nsIID& aIID)
124 void* newRawPtr;
125 if (NS_FAILED(aHelper(aIID, &newRawPtr))) {
126 newRawPtr = 0;
128 assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
131 void**
132 nsCOMPtr_base::begin_assignment()
134 assign_assuming_AddRef(0);
135 return reinterpret_cast<void**>(&mRawPtr);