From f0e906aeaece03333ebb352dd986d2d331ab9a34 Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Sat, 24 Apr 1999 02:38:54 +0000 Subject: [PATCH] Added nsISimpleEnumerator as Phase I of the great enumerator unification. Added misc files for XPConnect. Details in RDF_19990422_BRANCH. git-svn-id: svn://10.0.0.236/trunk@29015 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/base/nsISupports.idl | 25 +-- mozilla/xpcom/base/nsrootidl.idl | 56 +++++++ mozilla/xpcom/ds/nsEmptyEnumerator.cpp | 77 +++++++++ mozilla/xpcom/ds/nsEnumeratorUtils.cpp | 186 ++++++++++++++++++++++ mozilla/xpcom/ds/nsEnumeratorUtils.h | 85 ++++++++++ mozilla/xpcom/ds/nsIEnumerator.h | 33 ++-- mozilla/xpcom/idl/nsISimpleEnumerator.idl | 27 ++++ mozilla/xpcom/idl/nsISupports.idl | 25 +-- mozilla/xpcom/idl/nsrootidl.idl | 56 +++++++ mozilla/xpcom/macbuild/xpcom.exp | 30 ++++ mozilla/xpcom/macbuild/xpcomPPC.mcp | Bin 85274 -> 85274 bytes mozilla/xpcom/public/MANIFEST | 2 + mozilla/xpcom/public/Makefile.in | 2 + mozilla/xpcom/public/makefile.win | 2 + mozilla/xpcom/public/nsEnumeratorUtils.h | 85 ++++++++++ mozilla/xpcom/public/nsIEnumerator.h | 33 ++-- mozilla/xpcom/public/nsrootidl.h | 30 ++++ mozilla/xpcom/src/Makefile.in | 2 + mozilla/xpcom/src/makefile.win | 5 + mozilla/xpcom/src/nsEmptyEnumerator.cpp | 77 +++++++++ mozilla/xpcom/src/nsEnumeratorUtils.cpp | 186 ++++++++++++++++++++++ 21 files changed, 954 insertions(+), 70 deletions(-) create mode 100644 mozilla/xpcom/base/nsrootidl.idl create mode 100644 mozilla/xpcom/ds/nsEmptyEnumerator.cpp create mode 100644 mozilla/xpcom/ds/nsEnumeratorUtils.cpp create mode 100644 mozilla/xpcom/ds/nsEnumeratorUtils.h create mode 100644 mozilla/xpcom/idl/nsISimpleEnumerator.idl create mode 100644 mozilla/xpcom/idl/nsrootidl.idl create mode 100644 mozilla/xpcom/public/nsEnumeratorUtils.h create mode 100644 mozilla/xpcom/public/nsrootidl.h create mode 100644 mozilla/xpcom/src/nsEmptyEnumerator.cpp create mode 100644 mozilla/xpcom/src/nsEnumeratorUtils.cpp diff --git a/mozilla/xpcom/base/nsISupports.idl b/mozilla/xpcom/base/nsISupports.idl index b8a51f8cc50..1c614c1a022 100644 --- a/mozilla/xpcom/base/nsISupports.idl +++ b/mozilla/xpcom/base/nsISupports.idl @@ -16,31 +16,20 @@ * Reserved. */ +#include "nsrootidl.idl" + %{C++ #include "nsDebug.h" #include "nsTraceRefcnt.h" #include "nsIID.h" -%} -#include "nsID.idl" -%{C++ #include "nsError.h" - #include "nsISupportsUtils.h" %} -native nsQIResult(void *); -native voidStar(void*); -native voidStarRef(void**); -native nsIIDRef(REFNSIID); - -typedef unsigned long nsrefcnt; - -[ - object, - uuid(00000000-0000-0000-c000-000000000046) -] +[scriptable, uuid(00000000-0000-0000-c000-000000000046)] interface nsISupports { - void QueryInterface(in nsIIDRef uuid, out nsQIResult result); - [notxpcom] nsrefcnt AddRef(); - [notxpcom] nsrefcnt Release(); + void QueryInterface(in nsIIDRef uuid, + [iid_is(uuid),retval] out nsQIResult result); + [noscript, notxpcom] nsrefcnt AddRef(); + [noscript, notxpcom] nsrefcnt Release(); }; diff --git a/mozilla/xpcom/base/nsrootidl.idl b/mozilla/xpcom/base/nsrootidl.idl new file mode 100644 index 00000000000..5aeeb484de5 --- /dev/null +++ b/mozilla/xpcom/base/nsrootidl.idl @@ -0,0 +1,56 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* Root idl declarations to be used by all. */ + +%{C++ +/* + * Start commenting out the C++ versions of the below in the output header + */ +#if 0 +%} + +typedef octet PRUint8 ; +typedef unsigned short PRUint16 ; +typedef unsigned long PRUint32 ; +typedef unsigned long long PRUint64 ; +typedef short PRInt16 ; +typedef long PRInt32 ; +typedef long long PRInt64 ; + +typedef unsigned long nsrefcnt ; + +[ptr] native voidStar(void); +[ref] native voidRef(void); + +[ref, nsid] native nsIDRef(nsID); +[ref, nsid] native nsIIDRef(nsIID); +[ref, nsid] native nsCIDRef(nsCID); + +[ptr, nsid] native nsIDPtr(nsID); +[ptr, nsid] native nsIIDPtr(nsIID); +[ptr, nsid] native nsCIDPtr(nsCID); + +[ptr] native nsQIResult(void); + +%{C++ +/* + * End commenting out the C++ versions of the above in the output header + */ +#endif +%} diff --git a/mozilla/xpcom/ds/nsEmptyEnumerator.cpp b/mozilla/xpcom/ds/nsEmptyEnumerator.cpp new file mode 100644 index 00000000000..e6fc17e51a6 --- /dev/null +++ b/mozilla/xpcom/ds/nsEmptyEnumerator.cpp @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + + An empty enumerator. + + */ + +#include "nsIEnumerator.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +//////////////////////////////////////////////////////////////////////// + +class EmptyEnumeratorImpl : public nsISimpleEnumerator +{ +public: + EmptyEnumeratorImpl(void) {}; + virtual ~EmptyEnumeratorImpl(void) {}; + + // nsISupports interface + NS_IMETHOD_(nsrefcnt) AddRef(void) { + return 2; + } + + NS_IMETHOD_(nsrefcnt) Release(void) { + return 1; + } + + NS_IMETHOD QueryInterface(REFNSIID iid, void** result) { + if (! result) + return NS_ERROR_NULL_POINTER; + + if (iid.Equals(nsISimpleEnumerator::GetIID()) || + iid.Equals(kISupportsIID)) { + *result = (nsISimpleEnumerator*) this; + NS_ADDREF(this); + return NS_OK; + } + return NS_NOINTERFACE; + } + + // nsISimpleEnumerator + NS_IMETHOD HasMoreElements(PRBool* aResult) { + *aResult = PR_FALSE; + return NS_OK; + } + + NS_IMETHOD GetNext(nsISupports** aResult) { + return NS_ERROR_UNEXPECTED; + } +}; + +extern "C" NS_COM nsresult +NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult) +{ + static EmptyEnumeratorImpl gEmptyEnumerator; + *aResult = &gEmptyEnumerator; + return NS_OK; +} + diff --git a/mozilla/xpcom/ds/nsEnumeratorUtils.cpp b/mozilla/xpcom/ds/nsEnumeratorUtils.cpp new file mode 100644 index 00000000000..75a1b3ab26f --- /dev/null +++ b/mozilla/xpcom/ds/nsEnumeratorUtils.cpp @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsEnumeratorUtils.h" + + +nsArrayEnumerator::nsArrayEnumerator(nsISupportsArray* aValueArray) + : mValueArray(aValueArray), + mIndex(0) +{ + NS_INIT_REFCNT(); + NS_IF_ADDREF(mValueArray); +} + +nsArrayEnumerator::~nsArrayEnumerator(void) +{ + NS_IF_RELEASE(mValueArray); +} + +NS_IMPL_ISUPPORTS(nsArrayEnumerator, nsISimpleEnumerator::GetIID()); + +NS_IMETHODIMP +nsArrayEnumerator::HasMoreElements(PRBool* aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + *aResult = (mIndex < (PRInt32) mValueArray->Count()); + return NS_OK; +} + +NS_IMETHODIMP +nsArrayEnumerator::GetNext(nsISupports** aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (mIndex >= (PRInt32) mValueArray->Count()) + return NS_ERROR_UNEXPECTED; + + *aResult = mValueArray->ElementAt(mIndex++); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// + +nsSingletonEnumerator::nsSingletonEnumerator(nsISupports* aValue) + : mValue(aValue) +{ + NS_INIT_REFCNT(); + NS_IF_ADDREF(mValue); + mConsumed = (mValue ? PR_FALSE : PR_TRUE); +} + +nsSingletonEnumerator::~nsSingletonEnumerator() +{ + NS_IF_RELEASE(mValue); +} + +NS_IMPL_ISUPPORTS(nsSingletonEnumerator, nsISimpleEnumerator::GetIID()); + +NS_IMETHODIMP +nsSingletonEnumerator::HasMoreElements(PRBool* aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + *aResult = !mConsumed; + return NS_OK; +} + + +NS_IMETHODIMP +nsSingletonEnumerator::GetNext(nsISupports** aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (mConsumed) + return NS_ERROR_UNEXPECTED; + + mConsumed = PR_TRUE; + + NS_ADDREF(mValue); + *aResult = mValue; + return NS_OK; +} + + +//////////////////////////////////////////////////////////////////////// + + +nsAdapterEnumerator::nsAdapterEnumerator(nsIEnumerator* aEnum) + : mEnum(aEnum), mCurrent(0), mStarted(PR_FALSE) +{ + NS_INIT_REFCNT(); + NS_ADDREF(mEnum); +} + + +nsAdapterEnumerator::~nsAdapterEnumerator() +{ + NS_RELEASE(mEnum); + NS_IF_RELEASE(mCurrent); +} + + +NS_IMPL_ISUPPORTS(nsAdapterEnumerator, nsISimpleEnumerator::GetIID()); + + +NS_IMETHODIMP +nsAdapterEnumerator::HasMoreElements(PRBool* aResult) +{ + nsresult rv; + + if (mCurrent) { + *aResult = PR_TRUE; + return NS_OK; + } + + if (! mStarted) { + mStarted = PR_TRUE; + rv = mEnum->First(); + if (rv == NS_OK) { + mEnum->CurrentItem(&mCurrent); + *aResult = PR_TRUE; + } + else { + *aResult = PR_FALSE; + } + } + else { + *aResult = PR_FALSE; + + rv = mEnum->IsDone(); + if (rv != NS_OK) { + // We're not done. Advance to the next one. + rv = mEnum->Next(); + if (rv == NS_OK) { + mEnum->CurrentItem(&mCurrent); + *aResult = PR_TRUE; + } + } + } + return NS_OK; +} + + +NS_IMETHODIMP +nsAdapterEnumerator::GetNext(nsISupports** aResult) +{ + nsresult rv; + + PRBool hasMore; + rv = HasMoreElements(&hasMore); + if (NS_FAILED(rv)) return rv; + + if (! hasMore) + return NS_ERROR_UNEXPECTED; + + // No need to addref, we "transfer" the ownership to the caller. + *aResult = mCurrent; + mCurrent = 0; + return NS_OK; +} + + diff --git a/mozilla/xpcom/ds/nsEnumeratorUtils.h b/mozilla/xpcom/ds/nsEnumeratorUtils.h new file mode 100644 index 00000000000..2b5c053aa9a --- /dev/null +++ b/mozilla/xpcom/ds/nsEnumeratorUtils.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsRDFCursorUtils_h__ +#define nsRDFCursorUtils_h__ + +#include "nsIEnumerator.h" +#include "nsISupportsArray.h" + +class NS_COM nsArrayEnumerator : public nsISimpleEnumerator +{ +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator interface + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + // nsRDFArrayEnumerator methods + nsArrayEnumerator(nsISupportsArray* aValueArray); + virtual ~nsArrayEnumerator(void); + +protected: + nsISupportsArray* mValueArray; + PRInt32 mIndex; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NS_COM nsSingletonEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator methods + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + nsSingletonEnumerator(nsISupports* aValue); + virtual ~nsSingletonEnumerator(); + +protected: + nsISupports* mValue; + PRBool mConsumed; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NS_COM nsAdapterEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator methods + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + nsAdapterEnumerator(nsIEnumerator* aEnum); + virtual ~nsAdapterEnumerator(); + +protected: + nsIEnumerator* mEnum; + nsISupports* mCurrent; + PRBool mStarted; +}; + +//////////////////////////////////////////////////////////////////////// + +#endif /* nsRDFCursorUtils_h__ */ diff --git a/mozilla/xpcom/ds/nsIEnumerator.h b/mozilla/xpcom/ds/nsIEnumerator.h index 79a2f2d99d9..b011c2762df 100644 --- a/mozilla/xpcom/ds/nsIEnumerator.h +++ b/mozilla/xpcom/ds/nsIEnumerator.h @@ -21,10 +21,21 @@ #include "nsISupports.h" -#if defined(XPIDL_JS_STUBS) -struct JSObject; -struct JSContext; -#endif +// {D1899240-F9D2-11d2-BDD6-000064657374} +#define NS_ISIMPLEENUMERATOR_IID \ +{ 0xd1899240, 0xf9d2, 0x11d2, { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } + +class nsISimpleEnumerator : public nsISupports { +public: + static const nsIID& GetIID(void) { static nsIID iid = NS_ISIMPLEENUMERATOR_IID; return iid; } + NS_IMETHOD HasMoreElements(PRBool* aResult) = 0; + NS_IMETHOD GetNext(nsISupports** aResult) = 0; +}; + + +extern "C" NS_COM nsresult +NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult); + #define NS_IENUMERATOR_IID \ { /* ad385286-cbc4-11d2-8cca-0060b0fc14a3 */ \ @@ -34,6 +45,7 @@ struct JSContext; {0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ } + class nsIEnumerator : public nsISupports { public: @@ -57,19 +69,6 @@ public: * @param aItem return value */ NS_IMETHOD IsDone(void) = 0; - -#if defined(XPIDL_JS_STUBS) - // XXX Scriptability hack... - static NS_EXPORT_(JSObject*) InitJSClass(JSContext* cx) { - NS_NOTYETIMPLEMENTED("nsIEnumerator isn't XPIDL scriptable yet"); - return 0; - } - - static NS_EXPORT_(JSObject*) GetJSObject(JSContext* cx, nsIEnumerator* priv) { - NS_NOTYETIMPLEMENTED("nsIEnumerator isn't XPIDL scriptable yet"); - return 0; - } -#endif }; #define NS_IBIDIRECTIONALENUMERATOR_IID \ diff --git a/mozilla/xpcom/idl/nsISimpleEnumerator.idl b/mozilla/xpcom/idl/nsISimpleEnumerator.idl new file mode 100644 index 00000000000..54986810acc --- /dev/null +++ b/mozilla/xpcom/idl/nsISimpleEnumerator.idl @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsISupports.idl" + +[scriptable, uuid(D1899240-F9D2-11D2-BDD6-000064657374)] +interface nsISimpleEnumerator : nsISupports { + boolean HasMoreElements(); + nsISupports GetNext(); +}; + + diff --git a/mozilla/xpcom/idl/nsISupports.idl b/mozilla/xpcom/idl/nsISupports.idl index b8a51f8cc50..1c614c1a022 100644 --- a/mozilla/xpcom/idl/nsISupports.idl +++ b/mozilla/xpcom/idl/nsISupports.idl @@ -16,31 +16,20 @@ * Reserved. */ +#include "nsrootidl.idl" + %{C++ #include "nsDebug.h" #include "nsTraceRefcnt.h" #include "nsIID.h" -%} -#include "nsID.idl" -%{C++ #include "nsError.h" - #include "nsISupportsUtils.h" %} -native nsQIResult(void *); -native voidStar(void*); -native voidStarRef(void**); -native nsIIDRef(REFNSIID); - -typedef unsigned long nsrefcnt; - -[ - object, - uuid(00000000-0000-0000-c000-000000000046) -] +[scriptable, uuid(00000000-0000-0000-c000-000000000046)] interface nsISupports { - void QueryInterface(in nsIIDRef uuid, out nsQIResult result); - [notxpcom] nsrefcnt AddRef(); - [notxpcom] nsrefcnt Release(); + void QueryInterface(in nsIIDRef uuid, + [iid_is(uuid),retval] out nsQIResult result); + [noscript, notxpcom] nsrefcnt AddRef(); + [noscript, notxpcom] nsrefcnt Release(); }; diff --git a/mozilla/xpcom/idl/nsrootidl.idl b/mozilla/xpcom/idl/nsrootidl.idl new file mode 100644 index 00000000000..5aeeb484de5 --- /dev/null +++ b/mozilla/xpcom/idl/nsrootidl.idl @@ -0,0 +1,56 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* Root idl declarations to be used by all. */ + +%{C++ +/* + * Start commenting out the C++ versions of the below in the output header + */ +#if 0 +%} + +typedef octet PRUint8 ; +typedef unsigned short PRUint16 ; +typedef unsigned long PRUint32 ; +typedef unsigned long long PRUint64 ; +typedef short PRInt16 ; +typedef long PRInt32 ; +typedef long long PRInt64 ; + +typedef unsigned long nsrefcnt ; + +[ptr] native voidStar(void); +[ref] native voidRef(void); + +[ref, nsid] native nsIDRef(nsID); +[ref, nsid] native nsIIDRef(nsIID); +[ref, nsid] native nsCIDRef(nsCID); + +[ptr, nsid] native nsIDPtr(nsID); +[ptr, nsid] native nsIIDPtr(nsIID); +[ptr, nsid] native nsCIDPtr(nsCID); + +[ptr] native nsQIResult(void); + +%{C++ +/* + * End commenting out the C++ versions of the above in the output header + */ +#endif +%} diff --git a/mozilla/xpcom/macbuild/xpcom.exp b/mozilla/xpcom/macbuild/xpcom.exp index bcca81b9583..5b9354901d8 100644 --- a/mozilla/xpcom/macbuild/xpcom.exp +++ b/mozilla/xpcom/macbuild/xpcom.exp @@ -153,3 +153,33 @@ HeapMinimize__11nsAllocatorFv Free__11nsAllocatorFPv Realloc__11nsAllocatorFPvUi Alloc__11nsAllocatorFUi + +# NS_NewEmptyEnumerator +NS_NewEmptyEnumerator + +# nsArrayEnumerator +__ct__17nsArrayEnumeratorFP16nsISupportsArray +__dt__17nsArrayEnumeratorFv +AddRef__17nsArrayEnumeratorFv +Release__17nsArrayEnumeratorFv +QueryInterface__17nsArrayEnumeratorFRC4nsIDPPv +HasMoreElements__17nsArrayEnumeratorFPi +GetNext__17nsArrayEnumeratorFPP11nsISupports + +# nsSingletonEnumerator +__ct__21nsSingletonEnumeratorFP11nsISupports +__dt__21nsSingletonEnumeratorFv +AddRef__21nsSingletonEnumeratorFv +Release__21nsSingletonEnumeratorFv +QueryInterface__21nsSingletonEnumeratorFRC4nsIDPPv +HasMoreElements__21nsSingletonEnumeratorFPi +GetNext__21nsSingletonEnumeratorFPP11nsISupports + +# nsAdapterEnumerator +__ct__19nsAdapterEnumeratorFP13nsIEnumerator +__dt__19nsAdapterEnumeratorFv +AddRef__19nsAdapterEnumeratorFv +Release__19nsAdapterEnumeratorFv +QueryInterface__19nsAdapterEnumeratorFRC4nsIDPPv +HasMoreElements__19nsAdapterEnumeratorFPi +GetNext__19nsAdapterEnumeratorFPP11nsISupports diff --git a/mozilla/xpcom/macbuild/xpcomPPC.mcp b/mozilla/xpcom/macbuild/xpcomPPC.mcp index 98353026a95b9a2c5c0b6abfd7c0f82d4e429778..4becf380eea72b40d44d90a589a8a368aaa1a187 100644 GIT binary patch delta 538 zcmbO=i*?p4)(xu}U1b><7!(+R1Q2@zsSY4sz`(%%kAZ;)$OQ7sK@=F|fJr9T2|!v7 zh!vQC1Q7d8{=m3{189I3$dJh^m>M=4FgLPu0Hu7v(gp9OCwH^+ZGOacLYB1+sHuJP zat&ohQDz{M3y489$7Z*5X9fo2(8(*J6}K0tGQMV<7{EPQVI#}r6ks2j-DAmG5- z|1AN`f)b3Ob`BFA6*m7j&F5kD0t&WI)|;rz3Jwh*YsO}~Ns^44eO!3hCf^8@Vt0#u z#J~`&xIIyo@fYLd&%xp#k^lea>2BWG{DX1xs@4P+u+PB;<@GAF`T4b#85Ga55iY}fK&{J;VLOm~w9 delta 378 zcmbO=i*?p4)(xu}U8NZq7!(+R1Q2@ysWu>9z`($MiGhIw$OQ65l1qw`SQr>vKwLPG z0kRaBfCLcxO#Z;QWAX;31`Z&{4TwE98!$JrPfm1Gp4`pOxA_s*3E9n?G!z&o25^Wn z1NCqLF^J~atbFpp|NnbmPF@kMxVb_38{=e!jVzOs7duRL(y`sVs`V24kUZ|;o7j0M}ZJQzQ)002(lb&LQ2 diff --git a/mozilla/xpcom/public/MANIFEST b/mozilla/xpcom/public/MANIFEST index b7680e0700c..66e85a10fc7 100644 --- a/mozilla/xpcom/public/MANIFEST +++ b/mozilla/xpcom/public/MANIFEST @@ -6,6 +6,7 @@ nsCOMPtr.h nsCom.h nsAgg.h nsDebug.h +nsEnumeratorUtils.h nsError.h nsHashtable.h nsID.h @@ -31,3 +32,4 @@ nsIEventQueueService.h nsICollection.h nsIAllocator.h nsIGenericFactory.h +nsrootidl.h diff --git a/mozilla/xpcom/public/Makefile.in b/mozilla/xpcom/public/Makefile.in index 2e0709dc8de..a09f5221721 100644 --- a/mozilla/xpcom/public/Makefile.in +++ b/mozilla/xpcom/public/Makefile.in @@ -28,6 +28,7 @@ EXPORTS = \ nsCom.h \ nsAgg.h \ nsDebug.h \ + nsEnumeratorUtils.h \ nsError.h \ nsHashtable.h \ nsIAllocator.h \ @@ -53,6 +54,7 @@ EXPORTS = \ nsIEventQueueService.h \ nsIGenericFactory.h \ nsIRegistry.h \ + nsrootidl.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/xpcom/public/makefile.win b/mozilla/xpcom/public/makefile.win index 068b3d34cf2..0c2a9509c6c 100644 --- a/mozilla/xpcom/public/makefile.win +++ b/mozilla/xpcom/public/makefile.win @@ -24,6 +24,7 @@ EXPORTS = \ nsAgg.h \ nsCom.h \ nsDebug.h \ + nsEnumeratorUtils.h \ nsError.h \ nsHashtable.h \ nsICollection.h \ @@ -49,6 +50,7 @@ EXPORTS = \ nsIAllocator.h \ nsIRegistry.h \ nsIGenericFactory.h \ + nsrootidl.h \ $(NULL) MODULE = xpcom diff --git a/mozilla/xpcom/public/nsEnumeratorUtils.h b/mozilla/xpcom/public/nsEnumeratorUtils.h new file mode 100644 index 00000000000..2b5c053aa9a --- /dev/null +++ b/mozilla/xpcom/public/nsEnumeratorUtils.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsRDFCursorUtils_h__ +#define nsRDFCursorUtils_h__ + +#include "nsIEnumerator.h" +#include "nsISupportsArray.h" + +class NS_COM nsArrayEnumerator : public nsISimpleEnumerator +{ +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator interface + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + // nsRDFArrayEnumerator methods + nsArrayEnumerator(nsISupportsArray* aValueArray); + virtual ~nsArrayEnumerator(void); + +protected: + nsISupportsArray* mValueArray; + PRInt32 mIndex; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NS_COM nsSingletonEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator methods + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + nsSingletonEnumerator(nsISupports* aValue); + virtual ~nsSingletonEnumerator(); + +protected: + nsISupports* mValue; + PRBool mConsumed; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NS_COM nsAdapterEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + + // nsISimpleEnumerator methods + NS_IMETHOD HasMoreElements(PRBool* aResult); + NS_IMETHOD GetNext(nsISupports** aResult); + + nsAdapterEnumerator(nsIEnumerator* aEnum); + virtual ~nsAdapterEnumerator(); + +protected: + nsIEnumerator* mEnum; + nsISupports* mCurrent; + PRBool mStarted; +}; + +//////////////////////////////////////////////////////////////////////// + +#endif /* nsRDFCursorUtils_h__ */ diff --git a/mozilla/xpcom/public/nsIEnumerator.h b/mozilla/xpcom/public/nsIEnumerator.h index 79a2f2d99d9..b011c2762df 100644 --- a/mozilla/xpcom/public/nsIEnumerator.h +++ b/mozilla/xpcom/public/nsIEnumerator.h @@ -21,10 +21,21 @@ #include "nsISupports.h" -#if defined(XPIDL_JS_STUBS) -struct JSObject; -struct JSContext; -#endif +// {D1899240-F9D2-11d2-BDD6-000064657374} +#define NS_ISIMPLEENUMERATOR_IID \ +{ 0xd1899240, 0xf9d2, 0x11d2, { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } + +class nsISimpleEnumerator : public nsISupports { +public: + static const nsIID& GetIID(void) { static nsIID iid = NS_ISIMPLEENUMERATOR_IID; return iid; } + NS_IMETHOD HasMoreElements(PRBool* aResult) = 0; + NS_IMETHOD GetNext(nsISupports** aResult) = 0; +}; + + +extern "C" NS_COM nsresult +NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult); + #define NS_IENUMERATOR_IID \ { /* ad385286-cbc4-11d2-8cca-0060b0fc14a3 */ \ @@ -34,6 +45,7 @@ struct JSContext; {0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \ } + class nsIEnumerator : public nsISupports { public: @@ -57,19 +69,6 @@ public: * @param aItem return value */ NS_IMETHOD IsDone(void) = 0; - -#if defined(XPIDL_JS_STUBS) - // XXX Scriptability hack... - static NS_EXPORT_(JSObject*) InitJSClass(JSContext* cx) { - NS_NOTYETIMPLEMENTED("nsIEnumerator isn't XPIDL scriptable yet"); - return 0; - } - - static NS_EXPORT_(JSObject*) GetJSObject(JSContext* cx, nsIEnumerator* priv) { - NS_NOTYETIMPLEMENTED("nsIEnumerator isn't XPIDL scriptable yet"); - return 0; - } -#endif }; #define NS_IBIDIRECTIONALENUMERATOR_IID \ diff --git a/mozilla/xpcom/public/nsrootidl.h b/mozilla/xpcom/public/nsrootidl.h new file mode 100644 index 00000000000..3bf323aaded --- /dev/null +++ b/mozilla/xpcom/public/nsrootidl.h @@ -0,0 +1,30 @@ +/* + * DO NOT EDIT. THIS FILE IS GENERATED FROM nsrootidl.idl + */ + +#ifndef __gen_nsrootidl_h__ +#define __gen_nsrootidl_h__ + +#ifdef XPIDL_JS_STUBS +#include "jsapi.h" +#endif +/* + * Start commenting out the C++ versions of the below in the output header + */ +#if 0 + +typedef PRUint8 PRUint8; +typedef PRUint16 PRUint16; +typedef PRUint32 PRUint32; +typedef PRUint64 PRUint64; +typedef PRInt16 PRInt16; +typedef PRInt32 PRInt32; +typedef PRInt64 PRInt64; +typedef PRUint32 nsrefcnt; +/* + * End commenting out the C++ versions of the above in the output header + */ +#endif + + +#endif /* __gen_nsrootidl_h__ */ diff --git a/mozilla/xpcom/src/Makefile.in b/mozilla/xpcom/src/Makefile.in index f488e10f5c4..bb6779b65f8 100644 --- a/mozilla/xpcom/src/Makefile.in +++ b/mozilla/xpcom/src/Makefile.in @@ -33,6 +33,8 @@ CPPSRCS = \ nsHashtable.cpp \ nsID.cpp \ nsComponentManager.cpp \ + nsEnumeratorUtils.cpp \ + nsEmptyEnumerator.cpp \ nsRepository.cpp \ nsServiceManager.cpp \ nsSupportsArray.cpp \ diff --git a/mozilla/xpcom/src/makefile.win b/mozilla/xpcom/src/makefile.win index b0b8101f461..edf24b30a42 100644 --- a/mozilla/xpcom/src/makefile.win +++ b/mozilla/xpcom/src/makefile.win @@ -53,11 +53,14 @@ C_OBJS = \ CPPSRCS = \ nsDebug.cpp \ + nsEnumeratorUtils.cpp \ nsHashtable.cpp \ nsID.cpp \ nsCOMPtr.cpp \ nsProxyEvent.cpp \ nsComponentManager.cpp \ + nsEnumeratorUtils.cpp \ + nsEmptyEnumerator.cpp \ nsRepository.cpp \ nsServiceManager.cpp \ nsSupportsArray.cpp \ @@ -78,6 +81,8 @@ CPP_OBJS = \ .\$(OBJDIR)\nsHashtable.obj \ .\$(OBJDIR)\nsID.obj \ .\$(OBJDIR)\nsCOMPtr.obj \ + .\$(OBJDIR)\nsEnumeratorUtils.obj \ + .\$(OBJDIR)\nsEmptyEnumerator.obj \ .\$(OBJDIR)\nsProxyEvent.obj \ .\$(OBJDIR)\nsComponentManager.obj \ .\$(OBJDIR)\nsRepository.obj \ diff --git a/mozilla/xpcom/src/nsEmptyEnumerator.cpp b/mozilla/xpcom/src/nsEmptyEnumerator.cpp new file mode 100644 index 00000000000..e6fc17e51a6 --- /dev/null +++ b/mozilla/xpcom/src/nsEmptyEnumerator.cpp @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + + An empty enumerator. + + */ + +#include "nsIEnumerator.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +//////////////////////////////////////////////////////////////////////// + +class EmptyEnumeratorImpl : public nsISimpleEnumerator +{ +public: + EmptyEnumeratorImpl(void) {}; + virtual ~EmptyEnumeratorImpl(void) {}; + + // nsISupports interface + NS_IMETHOD_(nsrefcnt) AddRef(void) { + return 2; + } + + NS_IMETHOD_(nsrefcnt) Release(void) { + return 1; + } + + NS_IMETHOD QueryInterface(REFNSIID iid, void** result) { + if (! result) + return NS_ERROR_NULL_POINTER; + + if (iid.Equals(nsISimpleEnumerator::GetIID()) || + iid.Equals(kISupportsIID)) { + *result = (nsISimpleEnumerator*) this; + NS_ADDREF(this); + return NS_OK; + } + return NS_NOINTERFACE; + } + + // nsISimpleEnumerator + NS_IMETHOD HasMoreElements(PRBool* aResult) { + *aResult = PR_FALSE; + return NS_OK; + } + + NS_IMETHOD GetNext(nsISupports** aResult) { + return NS_ERROR_UNEXPECTED; + } +}; + +extern "C" NS_COM nsresult +NS_NewEmptyEnumerator(nsISimpleEnumerator** aResult) +{ + static EmptyEnumeratorImpl gEmptyEnumerator; + *aResult = &gEmptyEnumerator; + return NS_OK; +} + diff --git a/mozilla/xpcom/src/nsEnumeratorUtils.cpp b/mozilla/xpcom/src/nsEnumeratorUtils.cpp new file mode 100644 index 00000000000..75a1b3ab26f --- /dev/null +++ b/mozilla/xpcom/src/nsEnumeratorUtils.cpp @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsEnumeratorUtils.h" + + +nsArrayEnumerator::nsArrayEnumerator(nsISupportsArray* aValueArray) + : mValueArray(aValueArray), + mIndex(0) +{ + NS_INIT_REFCNT(); + NS_IF_ADDREF(mValueArray); +} + +nsArrayEnumerator::~nsArrayEnumerator(void) +{ + NS_IF_RELEASE(mValueArray); +} + +NS_IMPL_ISUPPORTS(nsArrayEnumerator, nsISimpleEnumerator::GetIID()); + +NS_IMETHODIMP +nsArrayEnumerator::HasMoreElements(PRBool* aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + *aResult = (mIndex < (PRInt32) mValueArray->Count()); + return NS_OK; +} + +NS_IMETHODIMP +nsArrayEnumerator::GetNext(nsISupports** aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (mIndex >= (PRInt32) mValueArray->Count()) + return NS_ERROR_UNEXPECTED; + + *aResult = mValueArray->ElementAt(mIndex++); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////////////// + +nsSingletonEnumerator::nsSingletonEnumerator(nsISupports* aValue) + : mValue(aValue) +{ + NS_INIT_REFCNT(); + NS_IF_ADDREF(mValue); + mConsumed = (mValue ? PR_FALSE : PR_TRUE); +} + +nsSingletonEnumerator::~nsSingletonEnumerator() +{ + NS_IF_RELEASE(mValue); +} + +NS_IMPL_ISUPPORTS(nsSingletonEnumerator, nsISimpleEnumerator::GetIID()); + +NS_IMETHODIMP +nsSingletonEnumerator::HasMoreElements(PRBool* aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + *aResult = !mConsumed; + return NS_OK; +} + + +NS_IMETHODIMP +nsSingletonEnumerator::GetNext(nsISupports** aResult) +{ + NS_PRECONDITION(aResult != 0, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + if (mConsumed) + return NS_ERROR_UNEXPECTED; + + mConsumed = PR_TRUE; + + NS_ADDREF(mValue); + *aResult = mValue; + return NS_OK; +} + + +//////////////////////////////////////////////////////////////////////// + + +nsAdapterEnumerator::nsAdapterEnumerator(nsIEnumerator* aEnum) + : mEnum(aEnum), mCurrent(0), mStarted(PR_FALSE) +{ + NS_INIT_REFCNT(); + NS_ADDREF(mEnum); +} + + +nsAdapterEnumerator::~nsAdapterEnumerator() +{ + NS_RELEASE(mEnum); + NS_IF_RELEASE(mCurrent); +} + + +NS_IMPL_ISUPPORTS(nsAdapterEnumerator, nsISimpleEnumerator::GetIID()); + + +NS_IMETHODIMP +nsAdapterEnumerator::HasMoreElements(PRBool* aResult) +{ + nsresult rv; + + if (mCurrent) { + *aResult = PR_TRUE; + return NS_OK; + } + + if (! mStarted) { + mStarted = PR_TRUE; + rv = mEnum->First(); + if (rv == NS_OK) { + mEnum->CurrentItem(&mCurrent); + *aResult = PR_TRUE; + } + else { + *aResult = PR_FALSE; + } + } + else { + *aResult = PR_FALSE; + + rv = mEnum->IsDone(); + if (rv != NS_OK) { + // We're not done. Advance to the next one. + rv = mEnum->Next(); + if (rv == NS_OK) { + mEnum->CurrentItem(&mCurrent); + *aResult = PR_TRUE; + } + } + } + return NS_OK; +} + + +NS_IMETHODIMP +nsAdapterEnumerator::GetNext(nsISupports** aResult) +{ + nsresult rv; + + PRBool hasMore; + rv = HasMoreElements(&hasMore); + if (NS_FAILED(rv)) return rv; + + if (! hasMore) + return NS_ERROR_UNEXPECTED; + + // No need to addref, we "transfer" the ownership to the caller. + *aResult = mCurrent; + mCurrent = 0; + return NS_OK; +} + +