2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-09-06 02:52:43 +04:00
|
|
|
|
|
|
|
#ifndef __nsInterfaceRequestorUtils_h
|
|
|
|
#define __nsInterfaceRequestorUtils_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
// a type-safe shortcut for calling the |GetInterface()| member function
|
|
|
|
// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
|
2014-06-27 05:35:39 +04:00
|
|
|
template<class T, class DestinationType>
|
|
|
|
inline nsresult
|
|
|
|
CallGetInterface(T* aSource, DestinationType** aDestination)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSource, "null parameter");
|
|
|
|
NS_PRECONDITION(aDestination, "null parameter");
|
2001-09-06 02:52:43 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
return aSource->GetInterface(NS_GET_TEMPLATE_IID(DestinationType),
|
|
|
|
reinterpret_cast<void**>(aDestination));
|
|
|
|
}
|
2001-09-06 02:52:43 +04:00
|
|
|
|
2004-10-29 23:43:51 +04:00
|
|
|
class NS_COM_GLUE nsGetInterface : public nsCOMPtr_helper
|
2014-06-27 05:35:39 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsGetInterface(nsISupports* aSource, nsresult* aError)
|
|
|
|
: mSource(aSource)
|
|
|
|
, mErrorPtr(aError)
|
2001-09-06 02:52:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsISupports* mSource;
|
|
|
|
nsresult* mErrorPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const nsGetInterface
|
|
|
|
do_GetInterface(nsISupports* aSource, nsresult* aError = 0)
|
|
|
|
{
|
|
|
|
return nsGetInterface(aSource, aError);
|
|
|
|
}
|
|
|
|
|
2001-09-06 02:52:43 +04:00
|
|
|
#endif // __nsInterfaceRequestorUtils_h
|
|
|
|
|