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 __nsInterfaceRequestorUtils_h
8 #define __nsInterfaceRequestorUtils_h
12 // a type-safe shortcut for calling the |GetInterface()| member function
13 // T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
14 template <class T
, class DestinationType
>
15 inline nsresult
CallGetInterface(T
* aSource
, DestinationType
** aDestination
) {
16 MOZ_ASSERT(aSource
, "null parameter");
17 MOZ_ASSERT(aDestination
, "null parameter");
19 return aSource
->GetInterface(NS_GET_TEMPLATE_IID(DestinationType
),
20 reinterpret_cast<void**>(aDestination
));
23 class MOZ_STACK_CLASS nsGetInterface final
: public nsCOMPtr_helper
{
25 nsGetInterface(nsISupports
* aSource
, nsresult
* aError
)
26 : mSource(aSource
), mErrorPtr(aError
) {}
28 virtual nsresult NS_FASTCALL
operator()(const nsIID
&, void**) const override
;
31 nsISupports
* MOZ_NON_OWNING_REF mSource
;
35 inline const nsGetInterface
do_GetInterface(nsISupports
* aSource
,
36 nsresult
* aError
= 0) {
37 return nsGetInterface(aSource
, aError
);
40 #endif // __nsInterfaceRequestorUtils_h