michael@0: /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __nsInterfaceRequestorUtils_h michael@0: #define __nsInterfaceRequestorUtils_h michael@0: michael@0: #include "nsCOMPtr.h" michael@0: michael@0: // a type-safe shortcut for calling the |GetInterface()| member function michael@0: // T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous. michael@0: template michael@0: inline michael@0: nsresult michael@0: CallGetInterface( T* aSource, DestinationType** aDestination ) michael@0: { michael@0: NS_PRECONDITION(aSource, "null parameter"); michael@0: NS_PRECONDITION(aDestination, "null parameter"); michael@0: michael@0: return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType), michael@0: reinterpret_cast(aDestination)); michael@0: } michael@0: michael@0: class NS_COM_GLUE nsGetInterface : public nsCOMPtr_helper michael@0: { michael@0: public: michael@0: nsGetInterface( nsISupports* aSource, nsresult* error ) michael@0: : mSource(aSource), michael@0: mErrorPtr(error) michael@0: { michael@0: // nothing else to do here michael@0: } michael@0: michael@0: virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const; michael@0: michael@0: private: michael@0: nsISupports* mSource; michael@0: nsresult* mErrorPtr; michael@0: }; michael@0: michael@0: inline michael@0: const nsGetInterface michael@0: do_GetInterface( nsISupports* aSource, nsresult* error = 0 ) michael@0: { michael@0: return nsGetInterface(aSource, error); michael@0: } michael@0: michael@0: #endif // __nsInterfaceRequestorUtils_h michael@0: