📄 nsisupportsimpl.h
字号:
/** * * Threadsafe implementations of the ISupports convenience macros * *//** * Use this macro to implement the AddRef method for a given <i>_class</i> * @param _class The name of the class implementing the method */#define NS_IMPL_THREADSAFE_ADDREF(_class) \NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \{ \ NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \ nsrefcnt count; \ count = PR_AtomicIncrement((PRInt32*)&mRefCnt); \ NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \ return count; \}/** * Use this macro to implement the Release method for a given <i>_class</i> * @param _class The name of the class implementing the method */#define NS_IMPL_THREADSAFE_RELEASE(_class) \NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \{ \ nsrefcnt count; \ NS_PRECONDITION(0 != mRefCnt, "dup release"); \ count = PR_AtomicDecrement((PRInt32 *)&mRefCnt); \ NS_LOG_RELEASE(this, count, #_class); \ if (0 == count) { \ mRefCnt = 1; /* stabilize */ \ /* enable this to find non-threadsafe destructors: */ \ /* NS_ASSERT_OWNINGTHREAD(_class); */ \ NS_DELETEXPCOM(this); \ return 0; \ } \ return count; \}#define NS_IMPL_THREADSAFE_ISUPPORTS0(_class) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE0(_class)#define NS_IMPL_THREADSAFE_ISUPPORTS1(_class, _interface) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE1(_class, _interface)#define NS_IMPL_THREADSAFE_ISUPPORTS2(_class, _i1, _i2) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE2(_class, _i1, _i2)#define NS_IMPL_THREADSAFE_ISUPPORTS3(_class, _i1, _i2, _i3) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE3(_class, _i1, _i2, _i3)#define NS_IMPL_THREADSAFE_ISUPPORTS4(_class, _i1, _i2, _i3, _i4) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE4(_class, _i1, _i2, _i3, _i4)#define NS_IMPL_THREADSAFE_ISUPPORTS5(_class, _i1, _i2, _i3, _i4, _i5) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE5(_class, _i1, _i2, _i3, _i4, _i5)#define NS_IMPL_THREADSAFE_ISUPPORTS6(_class, _i1, _i2, _i3, _i4, _i5, _i6) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE6(_class, _i1, _i2, _i3, _i4, _i5, _i6)#define NS_IMPL_THREADSAFE_ISUPPORTS7(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE7(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7)#define NS_IMPL_THREADSAFE_ISUPPORTS8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE8(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8)#define NS_IMPL_THREADSAFE_ISUPPORTS9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE9(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9)#define NS_IMPL_THREADSAFE_ISUPPORTS10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9, _i10) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE10(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9, _i10)#define NS_IMPL_THREADSAFE_ISUPPORTS11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9, _i10, _i11) \ NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_QUERY_INTERFACE11(_class, _i1, _i2, _i3, _i4, _i5, _i6, \ _i7, _i8, _i9, _i10, _i11)///////////////////////////////////////////////////////////////////////////////// Macros for implementing nsIClassInfo-related stuff.///////////////////////////////////////////////////////////////////////////////// include here instead of at the top because it requires the nsISupport decl#include "nsIClassInfo.h"#define NS_CLASSINFO_NAME(_class) _class##_classInfoGlobal#define NS_CI_INTERFACE_GETTER_NAME(_class) _class##_GetInterfacesHelper#define NS_DECL_CI_INTERFACE_GETTER(_class) \ extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *, \ nsIID ***);#define NS_DECL_CLASSINFO(_class) \ NS_DECL_CI_INTERFACE_GETTER(_class) \ nsIClassInfo *NS_CLASSINFO_NAME(_class);#define NS_IMPL_QUERY_CLASSINFO(_class) \ if ( aIID.Equals(NS_GET_IID(nsIClassInfo)) ) { \ extern nsIClassInfo *NS_CLASSINFO_NAME(_class); \ foundInterface = NS_STATIC_CAST(nsIClassInfo*, NS_CLASSINFO_NAME(_class));\ } else#define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \NS_IMETHODIMP \NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *count, nsIID ***array) \{ \ *count = _c; \ *array = (nsIID **)nsMemory::Alloc(sizeof (nsIID *) * _c);#define NS_CLASSINFO_HELPER_ENTRY(_i, _interface) \ (*array)[_i] = (nsIID *)nsMemory::Clone(&NS_GET_IID(_interface), \ sizeof(nsIID));#define NS_CLASSINFO_HELPER_END \ return NS_OK; \}#define NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface) \ NS_CLASSINFO_HELPER_BEGIN(_class, 1) \ NS_CLASSINFO_HELPER_ENTRY(0, _interface) \ NS_CLASSINFO_HELPER_END#define NS_IMPL_QUERY_INTERFACE1_CI(_class, _i1) \ NS_INTERFACE_MAP_BEGIN(_class) \ NS_INTERFACE_MAP_ENTRY(_i1) \ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \ NS_IMPL_QUERY_CLASSINFO(_class) \ NS_INTERFACE_MAP_END#define NS_IMPL_ISUPPORTS1_CI(_class, _interface) \ NS_IMPL_ADDREF(_class) \ NS_IMPL_RELEASE(_class) \ NS_IMPL_QUERY_INTERFACE1_CI(_class, _interface) \ NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface)#define NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2) \ NS_CLASSINFO_HELPER_BEGIN(_class, 2) \ NS_CLASSINFO_HELPER_ENTRY(0, _i1) \ NS_CLASSINFO_HELPER_ENTRY(1, _i2) \ NS_CLASSINFO_HELPER_END#define NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \ NS_INTERFACE_MAP_BEGIN(_class) \ NS_INTERFACE_MAP_ENTRY(_i1) \ NS_INTERFACE_MAP_ENTRY(_i2) \ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \ NS_IMPL_QUERY_CLASSINFO(_class) \ NS_INTERFACE_MAP_END#define NS_IMPL_ISUPPORTS2_CI(_class, _i1, _i2) \ NS_IMPL_ADDREF(_class) \ NS_IMPL_RELEASE(_class) \ NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \ NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2)#define NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3) \ NS_CLASSINFO_HELPER_BEGIN(_class, 3) \ NS_CLASSINFO_HELPER_ENTRY(0, _i1) \ NS_CLASSINFO_HELPER_ENTRY(1, _i2) \ NS_CLASSINFO_HELPER_ENTRY(2, _i3) \ NS_CLASSINFO_HELPER_END#define NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \ NS_INTERFACE_MAP_BEGIN(_class) \ NS_INTERFACE_MAP_ENTRY(_i1) \ NS_INTERFACE_MAP_ENTRY(_i2) \ NS_INTERFACE_MAP_ENTRY(_i3) \ NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \ NS_IMPL_QUERY_CLASSINFO(_class) \ NS_INTERFACE_MAP_END#define NS_IMPL_ISUPPORTS3_CI(_class, _i1, _i2, _i3) \ NS_IMPL_ADDREF(_class) \ NS_IMPL_RELEASE(_class) \ NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \ NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3)#define NS_IMPL_CI_INTERFACE_GETTER4(_class, _i1, _i2, _i3, _i4) \ NS_CLASSINFO_HELPER_BEGIN(_class, 4) \ NS_CLASSINFO_HELPER_ENTRY(0, _i1) \ NS_CLASSINFO_HELPER_ENTRY(1, _i2) \ NS_CLASSINFO_HELPER_ENTRY(2, _i3) \ NS_CLASSINFO_HELPER_ENTRY(3, _i4) \ NS_CLASSINFO_HELPER_END#define NS_IMPL_QUERY_INTERFACE4_CI(_class, _i1, _i2, _i3, _i4) \ NS_INTERFACE_MAP_BEGIN(_class) \ NS_INTERFACE_MAP_ENTRY(_i1) \ NS_INTERFACE_MAP_ENTRY(_i2) \ NS_INTERFACE_MAP_ENTRY(_i3) \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -