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 #ifndef nsQueryObject_h
8 #define nsQueryObject_h
10 #include "mozilla/Attributes.h"
13 #include "mozilla/RefPtr.h"
15 /*****************************************************************************/
18 class MOZ_STACK_CLASS nsQueryObject final
: public nsCOMPtr_helper
{
20 explicit nsQueryObject(T
* aRawPtr
) : mRawPtr(aRawPtr
) {}
22 virtual nsresult NS_FASTCALL
operator()(const nsIID
& aIID
,
23 void** aResult
) const override
{
24 nsresult status
= mRawPtr
? mRawPtr
->QueryInterface(aIID
, aResult
)
25 : NS_ERROR_NULL_POINTER
;
30 T
* MOZ_NON_OWNING_REF mRawPtr
;
34 class MOZ_STACK_CLASS nsQueryObjectWithError final
: public nsCOMPtr_helper
{
36 nsQueryObjectWithError(T
* aRawPtr
, nsresult
* aErrorPtr
)
37 : mRawPtr(aRawPtr
), mErrorPtr(aErrorPtr
) {}
39 virtual nsresult NS_FASTCALL
operator()(const nsIID
& aIID
,
40 void** aResult
) const override
{
41 nsresult status
= mRawPtr
? mRawPtr
->QueryInterface(aIID
, aResult
)
42 : NS_ERROR_NULL_POINTER
;
50 T
* MOZ_NON_OWNING_REF mRawPtr
;
54 /*****************************************************************************/
56 /*****************************************************************************/
59 inline nsQueryObject
<T
> do_QueryObject(T
* aRawPtr
) {
60 return nsQueryObject
<T
>(aRawPtr
);
64 inline nsQueryObject
<T
> do_QueryObject(const nsCOMPtr
<T
>& aRawPtr
) {
65 return nsQueryObject
<T
>(aRawPtr
);
69 inline nsQueryObject
<T
> do_QueryObject(const RefPtr
<T
>& aRawPtr
) {
70 return nsQueryObject
<T
>(aRawPtr
);
74 inline nsQueryObjectWithError
<T
> do_QueryObject(T
* aRawPtr
,
75 nsresult
* aErrorPtr
) {
76 return nsQueryObjectWithError
<T
>(aRawPtr
, aErrorPtr
);
80 inline nsQueryObjectWithError
<T
> do_QueryObject(const nsCOMPtr
<T
>& aRawPtr
,
81 nsresult
* aErrorPtr
) {
82 return nsQueryObjectWithError
<T
>(aRawPtr
, aErrorPtr
);
86 inline nsQueryObjectWithError
<T
> do_QueryObject(const RefPtr
<T
>& aRawPtr
,
87 nsresult
* aErrorPtr
) {
88 return nsQueryObjectWithError
<T
>(aRawPtr
, aErrorPtr
);
91 /*****************************************************************************/
93 #endif // !defined(nsQueryObject_h)