Source code

Revision control

Other Tools

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/. */
6
7
#include "nsCOMPtr.h"
8
9
nsresult nsQueryInterfaceISupports::operator()(const nsIID& aIID,
10
void** aAnswer) const {
11
nsresult status;
12
if (mRawPtr) {
13
status = mRawPtr->QueryInterface(aIID, aAnswer);
14
} else {
15
status = NS_ERROR_NULL_POINTER;
16
}
17
18
return status;
19
}
20
21
nsresult nsQueryInterfaceISupportsWithError::operator()(const nsIID& aIID,
22
void** aAnswer) const {
23
nsresult status;
24
if (mRawPtr) {
25
status = mRawPtr->QueryInterface(aIID, aAnswer);
26
} else {
27
status = NS_ERROR_NULL_POINTER;
28
}
29
30
if (mErrorPtr) {
31
*mErrorPtr = status;
32
}
33
return status;
34
}
35
36
void nsCOMPtr_base::assign_with_AddRef(nsISupports* aRawPtr) {
37
if (aRawPtr) {
38
NSCAP_ADDREF(this, aRawPtr);
39
}
40
assign_assuming_AddRef(aRawPtr);
41
}
42
43
void nsCOMPtr_base::assign_from_qi(const nsQueryInterfaceISupports aQI,
44
const nsIID& aIID) {
45
void* newRawPtr;
46
if (NS_FAILED(aQI(aIID, &newRawPtr))) {
47
newRawPtr = nullptr;
48
}
49
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
50
}
51
52
void nsCOMPtr_base::assign_from_qi_with_error(
53
const nsQueryInterfaceISupportsWithError& aQI, const nsIID& aIID) {
54
void* newRawPtr;
55
if (NS_FAILED(aQI(aIID, &newRawPtr))) {
56
newRawPtr = nullptr;
57
}
58
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
59
}
60
61
void nsCOMPtr_base::assign_from_gs_cid(const nsGetServiceByCID aGS,
62
const nsIID& aIID) {
63
void* newRawPtr;
64
if (NS_FAILED(aGS(aIID, &newRawPtr))) {
65
newRawPtr = nullptr;
66
}
67
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
68
}
69
70
void nsCOMPtr_base::assign_from_gs_cid_with_error(
71
const nsGetServiceByCIDWithError& aGS, const nsIID& aIID) {
72
void* newRawPtr;
73
if (NS_FAILED(aGS(aIID, &newRawPtr))) {
74
newRawPtr = nullptr;
75
}
76
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
77
}
78
79
void nsCOMPtr_base::assign_from_gs_contractid(
80
const nsGetServiceByContractID aGS, const nsIID& aIID) {
81
void* newRawPtr;
82
if (NS_FAILED(aGS(aIID, &newRawPtr))) {
83
newRawPtr = nullptr;
84
}
85
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
86
}
87
88
void nsCOMPtr_base::assign_from_gs_contractid_with_error(
89
const nsGetServiceByContractIDWithError& aGS, const nsIID& aIID) {
90
void* newRawPtr;
91
if (NS_FAILED(aGS(aIID, &newRawPtr))) {
92
newRawPtr = nullptr;
93
}
94
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
95
}
96
97
void nsCOMPtr_base::assign_from_query_referent(
98
const nsQueryReferent& aQueryReferent, const nsIID& aIID) {
99
void* newRawPtr;
100
if (NS_FAILED(aQueryReferent(aIID, &newRawPtr))) {
101
newRawPtr = nullptr;
102
}
103
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
104
}
105
106
void nsCOMPtr_base::assign_from_helper(const nsCOMPtr_helper& aHelper,
107
const nsIID& aIID) {
108
void* newRawPtr;
109
if (NS_FAILED(aHelper(aIID, &newRawPtr))) {
110
newRawPtr = nullptr;
111
}
112
assign_assuming_AddRef(static_cast<nsISupports*>(newRawPtr));
113
}
114
115
void** nsCOMPtr_base::begin_assignment() {
116
assign_assuming_AddRef(nullptr);
117
return reinterpret_cast<void**>(&mRawPtr);
118
}