зеркало из https://github.com/mozilla/gecko-dev.git
macros and defs to removed conditional definition of |GetIID()| within |nsISupports|. r=beard, (waterson?), bug=10477
This commit is contained in:
Родитель
ce4293d0ec
Коммит
a2dea03069
|
@ -600,7 +600,7 @@ class nsCOMPtr
|
|||
Specializing |nsCOMPtr| for |nsISupports| allows us to
|
||||
*/
|
||||
|
||||
// template <>
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
class nsCOMPtr<nsISupports>
|
||||
: private nsCOMPtr_base
|
||||
{
|
||||
|
@ -843,7 +843,7 @@ class nsGetterAddRefs
|
|||
};
|
||||
|
||||
|
||||
// template <>
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
class nsGetterAddRefs<nsISupports>
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Scott Collins <scc@ScottCollins.net>
|
||||
*/
|
||||
|
||||
#ifndef __nsISupportsUtils_h
|
||||
|
@ -27,6 +28,9 @@
|
|||
/***************************************************************************/
|
||||
/* this section copied from the hand written nsISupports.h */
|
||||
|
||||
#include "nscore.h"
|
||||
// for |NS_SPECIALIZE_TEMPLATE|, and the casts, et al
|
||||
|
||||
#include "nsDebug.h"
|
||||
#include "nsID.h"
|
||||
#include "nsIID.h"
|
||||
|
@ -37,21 +41,6 @@
|
|||
#include "prcmon.h"
|
||||
#endif /* NS_MT_SUPPORTED */
|
||||
|
||||
// under Metrowerks (Mac), we don't have autoconf yet
|
||||
#ifdef __MWERKS__
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#endif
|
||||
|
||||
// under VC++ (Windows), we don't have autoconf yet
|
||||
#if defined(_MSC_VER) && (_MSC_VER>=1100)
|
||||
// VC++ 5.0 and greater implement template specialization, 4.2 is unknown
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CPP_SPECIALIZATION
|
||||
#define NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
#endif
|
||||
|
||||
/*@{*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -92,10 +81,6 @@ typedef PRUint32 nsrefcnt;
|
|||
class nsISupports {
|
||||
public:
|
||||
|
||||
#ifndef NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ISUPPORTS_IID; return iid; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Methods
|
||||
*/
|
||||
|
@ -293,16 +278,16 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
|||
}
|
||||
|
||||
#define NS_IMPL_QUERY_TAIL(_supports_interface) \
|
||||
NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface) \
|
||||
NS_IMPL_QUERY_TAIL_GUTS
|
||||
NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface) \
|
||||
NS_IMPL_QUERY_TAIL_GUTS
|
||||
|
||||
|
||||
/*
|
||||
This is the new scheme. Using this notation now will allow us to switch to
|
||||
a table driven mechanism when it's ready. Note the difference between this
|
||||
and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism. You must
|
||||
explicitly mention |nsISupports| when using the interface maps.
|
||||
*/
|
||||
/*
|
||||
This is the new scheme. Using this notation now will allow us to switch to
|
||||
a table driven mechanism when it's ready. Note the difference between this
|
||||
and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism. You must
|
||||
explicitly mention |nsISupports| when using the interface maps.
|
||||
*/
|
||||
#define NS_INTERFACE_MAP_BEGIN(_implClass) NS_IMPL_QUERY_HEAD(_implClass)
|
||||
#define NS_INTERFACE_MAP_ENTRY(_interface) NS_IMPL_QUERY_BODY(_interface)
|
||||
#define NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(_interface, _implClass) NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass)
|
||||
|
@ -862,19 +847,17 @@ class nsISupports;
|
|||
|
||||
template <class T>
|
||||
struct nsCOMTypeInfo
|
||||
{
|
||||
static const nsIID& GetIID() { return T::GetIID(); }
|
||||
};
|
||||
|
||||
#ifdef NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
template <>
|
||||
struct nsCOMTypeInfo<nsISupports>
|
||||
{
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_ISUPPORTS_IID; return iid;
|
||||
}
|
||||
static const nsIID& GetIID() { return T::GetIID(); }
|
||||
};
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
struct nsCOMTypeInfo<nsISupports>
|
||||
{
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_ISUPPORTS_IID; return iid;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define NS_GET_IID(T) nsCOMTypeInfo<T>::GetIID()
|
||||
|
||||
|
@ -883,12 +866,12 @@ template <class DestinationType>
|
|||
inline
|
||||
nsresult
|
||||
CallQueryInterface( nsISupports* aSource, DestinationType** aDestination )
|
||||
{
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->QueryInterface(NS_GET_IID(DestinationType), (void**)aDestination);
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C++"
|
||||
|
||||
|
|
|
@ -146,6 +146,34 @@ typedef PRUint16 PRUnichar;
|
|||
/* ------------------------------------------------------------------------ */
|
||||
/* Casting macros for hiding C++ features from older compilers */
|
||||
|
||||
/*
|
||||
All our compiler support template specialization, but not all support the
|
||||
|template <>| notation. The compiler that don't understand this notation
|
||||
just omit it for specialization.
|
||||
|
||||
Need to add an autoconf test for this.
|
||||
*/
|
||||
|
||||
// under Metrowerks (Mac), we don't have autoconf yet
|
||||
#ifdef __MWERKS__
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
||||
#endif
|
||||
|
||||
// under VC++ (Windows), we don't have autoconf yet
|
||||
#if defined(_MSC_VER) && (_MSC_VER>=1100)
|
||||
// VC++ 5.0 and greater implement template specialization, 4.2 is unknown
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
||||
#define NS_SPECIALIZE_TEMPLATE template <>
|
||||
#else
|
||||
#define NS_SPECIALIZE_TEMPLATE
|
||||
#endif
|
||||
|
||||
/* unix and beos now determine this automatically */
|
||||
#if ! defined XP_UNIX && ! defined XP_BEOS
|
||||
#define HAVE_CPP_NEW_CASTS /* we'll be optimistic. */
|
||||
|
@ -154,30 +182,37 @@ typedef PRUint16 PRUnichar;
|
|||
#if defined(HAVE_CPP_NEW_CASTS)
|
||||
#define NS_STATIC_CAST(__type, __ptr) static_cast<__type>(__ptr)
|
||||
#define NS_CONST_CAST(__type, __ptr) const_cast<__type>(__ptr)
|
||||
#define NS_REINTERPRET_CAST(__type, __ptr) reinterpret_cast<__type>(__ptr)
|
||||
|
||||
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) reinterpret_cast<__type>(__ptr)
|
||||
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast<__type>(__obj)
|
||||
#define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast<__type>(__expr)
|
||||
|
||||
#else
|
||||
#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
|
||||
#define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
|
||||
|
||||
/* Note: the following is only appropriate for pointers. */
|
||||
#define NS_REINTERPRET_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
|
||||
/*
|
||||
Why cast to a |void*| first? Well, when old-style casting from
|
||||
a pointer to a base to a pointer to a derived class, the cast will be
|
||||
ambiguous if the source pointer type appears multiple times in the
|
||||
destination, e.g.,
|
||||
|
||||
class Base {};
|
||||
class Derived : public Base, public Base {};
|
||||
|
||||
void foo( Base* b )
|
||||
{
|
||||
((Derived*)b)->some_deried_member ... // Error: Ambiguous, expand from which |Base|?
|
||||
}
|
||||
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
|
||||
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
|
||||
|
||||
an old-style cast (like |static_cast|) will change the pointer, but
|
||||
here, doesn't know how. The cast to |void*| prevents it from thinking
|
||||
it needs to expand the original pointer.
|
||||
/* Note: the following is only appropriate for pointers. */
|
||||
#define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CAST(__type, __expr)
|
||||
/*
|
||||
Why cast to a |void*| first? Well, when old-style casting from
|
||||
a pointer to a base to a pointer to a derived class, the cast will be
|
||||
ambiguous if the source pointer type appears multiple times in the
|
||||
destination, e.g.,
|
||||
|
||||
class Base {};
|
||||
class Derived : public Base, public Base {};
|
||||
|
||||
void foo( Base* b )
|
||||
{
|
||||
((Derived*)b)->some_deried_member ... // Error: Ambiguous, expand from which |Base|?
|
||||
}
|
||||
|
||||
an old-style cast (like |static_cast|) will change the pointer, but
|
||||
here, doesn't know how. The cast to |void*| prevents it from thinking
|
||||
it needs to expand the original pointer.
|
||||
|
||||
The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
|
||||
conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to something
|
||||
|
|
|
@ -600,7 +600,7 @@ class nsCOMPtr
|
|||
Specializing |nsCOMPtr| for |nsISupports| allows us to
|
||||
*/
|
||||
|
||||
// template <>
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
class nsCOMPtr<nsISupports>
|
||||
: private nsCOMPtr_base
|
||||
{
|
||||
|
@ -843,7 +843,7 @@ class nsGetterAddRefs
|
|||
};
|
||||
|
||||
|
||||
// template <>
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
class nsGetterAddRefs<nsISupports>
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Scott Collins <scc@ScottCollins.net>
|
||||
*/
|
||||
|
||||
#ifndef __nsISupportsUtils_h
|
||||
|
@ -27,6 +28,9 @@
|
|||
/***************************************************************************/
|
||||
/* this section copied from the hand written nsISupports.h */
|
||||
|
||||
#include "nscore.h"
|
||||
// for |NS_SPECIALIZE_TEMPLATE|, and the casts, et al
|
||||
|
||||
#include "nsDebug.h"
|
||||
#include "nsID.h"
|
||||
#include "nsIID.h"
|
||||
|
@ -37,21 +41,6 @@
|
|||
#include "prcmon.h"
|
||||
#endif /* NS_MT_SUPPORTED */
|
||||
|
||||
// under Metrowerks (Mac), we don't have autoconf yet
|
||||
#ifdef __MWERKS__
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#endif
|
||||
|
||||
// under VC++ (Windows), we don't have autoconf yet
|
||||
#if defined(_MSC_VER) && (_MSC_VER>=1100)
|
||||
// VC++ 5.0 and greater implement template specialization, 4.2 is unknown
|
||||
#define HAVE_CPP_SPECIALIZATION
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CPP_SPECIALIZATION
|
||||
#define NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
#endif
|
||||
|
||||
/*@{*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -92,10 +81,6 @@ typedef PRUint32 nsrefcnt;
|
|||
class nsISupports {
|
||||
public:
|
||||
|
||||
#ifndef NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ISUPPORTS_IID; return iid; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name Methods
|
||||
*/
|
||||
|
@ -293,16 +278,16 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
|||
}
|
||||
|
||||
#define NS_IMPL_QUERY_TAIL(_supports_interface) \
|
||||
NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface) \
|
||||
NS_IMPL_QUERY_TAIL_GUTS
|
||||
NS_IMPL_QUERY_BODY_AMBIGUOUS(nsISupports, _supports_interface) \
|
||||
NS_IMPL_QUERY_TAIL_GUTS
|
||||
|
||||
|
||||
/*
|
||||
This is the new scheme. Using this notation now will allow us to switch to
|
||||
a table driven mechanism when it's ready. Note the difference between this
|
||||
and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism. You must
|
||||
explicitly mention |nsISupports| when using the interface maps.
|
||||
*/
|
||||
/*
|
||||
This is the new scheme. Using this notation now will allow us to switch to
|
||||
a table driven mechanism when it's ready. Note the difference between this
|
||||
and the (currently) underlying NS_IMPL_QUERY_INTERFACE mechanism. You must
|
||||
explicitly mention |nsISupports| when using the interface maps.
|
||||
*/
|
||||
#define NS_INTERFACE_MAP_BEGIN(_implClass) NS_IMPL_QUERY_HEAD(_implClass)
|
||||
#define NS_INTERFACE_MAP_ENTRY(_interface) NS_IMPL_QUERY_BODY(_interface)
|
||||
#define NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(_interface, _implClass) NS_IMPL_QUERY_BODY_AMBIGUOUS(_interface, _implClass)
|
||||
|
@ -862,19 +847,17 @@ class nsISupports;
|
|||
|
||||
template <class T>
|
||||
struct nsCOMTypeInfo
|
||||
{
|
||||
static const nsIID& GetIID() { return T::GetIID(); }
|
||||
};
|
||||
|
||||
#ifdef NSCAP_FEATURE_HIDE_NSISUPPORTS_GETIID
|
||||
template <>
|
||||
struct nsCOMTypeInfo<nsISupports>
|
||||
{
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_ISUPPORTS_IID; return iid;
|
||||
}
|
||||
static const nsIID& GetIID() { return T::GetIID(); }
|
||||
};
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
struct nsCOMTypeInfo<nsISupports>
|
||||
{
|
||||
static const nsIID& GetIID() {
|
||||
static nsIID iid = NS_ISUPPORTS_IID; return iid;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#define NS_GET_IID(T) nsCOMTypeInfo<T>::GetIID()
|
||||
|
||||
|
@ -883,12 +866,12 @@ template <class DestinationType>
|
|||
inline
|
||||
nsresult
|
||||
CallQueryInterface( nsISupports* aSource, DestinationType** aDestination )
|
||||
{
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->QueryInterface(NS_GET_IID(DestinationType), (void**)aDestination);
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C++"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче