Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / base / nsIInterfaceRequestorUtils.h
blobc3116ea9f297be3a6db97c2ecda282a27d73366e
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
10 #include "nsCOMPtr.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 {
24 public:
25 nsGetInterface(nsISupports* aSource, nsresult* aError)
26 : mSource(aSource), mErrorPtr(aError) {}
28 virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const override;
30 private:
31 nsISupports* MOZ_NON_OWNING_REF mSource;
32 nsresult* mErrorPtr;
35 inline const nsGetInterface do_GetInterface(nsISupports* aSource,
36 nsresult* aError = 0) {
37 return nsGetInterface(aSource, aError);
40 #endif // __nsInterfaceRequestorUtils_h