2015-04-15 19:47:03 +03: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
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsQueryObject_h
|
|
|
|
#define nsQueryObject_h
|
|
|
|
|
2015-04-20 23:17:00 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
template<class T>
|
2015-04-20 23:58:15 +03:00
|
|
|
class MOZ_STACK_CLASS nsQueryObject final : public nsCOMPtr_helper
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit nsQueryObject(T* aRawPtr)
|
|
|
|
: mRawPtr(aRawPtr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID& aIID,
|
2017-11-06 06:37:28 +03:00
|
|
|
void** aResult) const override
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult)
|
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
private:
|
2015-04-20 23:17:00 +03:00
|
|
|
T* MOZ_NON_OWNING_REF mRawPtr;
|
2015-04-15 19:47:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
2015-04-20 23:58:15 +03:00
|
|
|
class MOZ_STACK_CLASS nsQueryObjectWithError final : public nsCOMPtr_helper
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsQueryObjectWithError(T* aRawPtr, nsresult* aErrorPtr)
|
|
|
|
: mRawPtr(aRawPtr), mErrorPtr(aErrorPtr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult NS_FASTCALL operator()(const nsIID& aIID,
|
2017-11-06 06:37:28 +03:00
|
|
|
void** aResult) const override
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult)
|
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
if (mErrorPtr) {
|
|
|
|
*mErrorPtr = status;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
private:
|
2015-04-20 23:17:00 +03:00
|
|
|
T* MOZ_NON_OWNING_REF mRawPtr;
|
2015-04-15 19:47:03 +03:00
|
|
|
nsresult* mErrorPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObject<T>
|
|
|
|
do_QueryObject(T* aRawPtr)
|
|
|
|
{
|
|
|
|
return nsQueryObject<T>(aRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObject<T>
|
|
|
|
do_QueryObject(nsCOMPtr<T>& aRawPtr)
|
|
|
|
{
|
|
|
|
return nsQueryObject<T>(aRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObject<T>
|
2015-10-18 08:24:48 +03:00
|
|
|
do_QueryObject(RefPtr<T>& aRawPtr)
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
return nsQueryObject<T>(aRawPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObjectWithError<T>
|
|
|
|
do_QueryObject(T* aRawPtr, nsresult* aErrorPtr)
|
|
|
|
{
|
|
|
|
return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObjectWithError<T>
|
|
|
|
do_QueryObject(nsCOMPtr<T>& aRawPtr, nsresult* aErrorPtr)
|
|
|
|
{
|
|
|
|
return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline nsQueryObjectWithError<T>
|
2015-10-18 08:24:48 +03:00
|
|
|
do_QueryObject(RefPtr<T>& aRawPtr, nsresult* aErrorPtr)
|
2015-04-15 19:47:03 +03:00
|
|
|
{
|
|
|
|
return nsQueryObjectWithError<T>(aRawPtr, aErrorPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
#endif // !defined(nsQueryObject_h)
|