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
This commit is contained in:
waterson%netscape.com
1999-04-24 02:38:54 +00:00
parent 24bc601a81
commit f0e906aeae
21 changed files with 954 additions and 70 deletions

View File

@@ -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();
};

View File

@@ -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
%}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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__ */

View File

@@ -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 \

View File

@@ -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();
};

View File

@@ -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();
};

View File

@@ -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
%}

View File

@@ -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

Binary file not shown.

View File

@@ -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

View File

@@ -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))

View File

@@ -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

View File

@@ -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__ */

View File

@@ -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 \

View File

@@ -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__ */

View File

@@ -33,6 +33,8 @@ CPPSRCS = \
nsHashtable.cpp \
nsID.cpp \
nsComponentManager.cpp \
nsEnumeratorUtils.cpp \
nsEmptyEnumerator.cpp \
nsRepository.cpp \
nsServiceManager.cpp \
nsSupportsArray.cpp \

View File

@@ -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 \

View File

@@ -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;
}

View File

@@ -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;
}