Added closure argument to nsHashtable::Enumerate.

This commit is contained in:
warren%netscape.com 1998-09-01 00:16:47 +00:00
Родитель 0a534a0c5d
Коммит 28969e9e90
11 изменённых файлов: 43 добавлений и 81 удалений

Просмотреть файл

@ -51,7 +51,7 @@ char *gSession;
char *gDenied; char *gDenied;
nsPrivilegeTable *gPrivilegeTable; nsPrivilegeTable *gPrivilegeTable;
static PRBool getPrincipalString(nsHashKey *aKey, void *aData); static PRBool getPrincipalString(nsHashKey *aKey, void *aData, void* closure);
static nsPrincipal *RDF_getPrincipal(JSec_Principal jsec_pr); static nsPrincipal *RDF_getPrincipal(JSec_Principal jsec_pr);
static PRBool RDF_RemovePrincipal(nsPrincipal *prin); static PRBool RDF_RemovePrincipal(nsPrincipal *prin);
@ -765,7 +765,7 @@ PRBool nsPrivilegeManager::checkMatchPrincipal(void* context, nsPrincipal *prin,
return (comparePrincipalArray(prinArray, classPrinArray) != nsSetComparisonType_NoSubset) ? PR_TRUE : PR_FALSE; return (comparePrincipalArray(prinArray, classPrinArray) != nsSetComparisonType_NoSubset) ? PR_TRUE : PR_FALSE;
} }
static PRBool getPrincipalString(nsHashKey *aKey, void *aData) static PRBool getPrincipalString(nsHashKey *aKey, void *aData, void* closure)
{ {
/* Admin UI */ /* Admin UI */
/* XXX: Ignore empty strings */ /* XXX: Ignore empty strings */
@ -813,7 +813,7 @@ nsPrincipal * nsPrivilegeManager::getPrincipalFromString(char *prinName)
return prin; return prin;
} }
static PRBool getPermissionsString(nsHashKey *aKey, void *aData) static PRBool getPermissionsString(nsHashKey *aKey, void *aData, void* closure)
{ {
/* Admin UI */ /* Admin UI */
TargetKey *targetKey = (TargetKey *) aKey; TargetKey *targetKey = (TargetKey *) aKey;
@ -895,7 +895,7 @@ PRBool nsPrivilegeManager::removePrincipalsPrivilege(char *prinName,
return PR_TRUE; return PR_TRUE;
} }
static PRBool updatePrivileges(nsHashKey *aKey, void *aData) static PRBool updatePrivileges(nsHashKey *aKey, void *aData, void* closure)
{ {
/* Admin UI */ /* Admin UI */
TargetKey *targetKey = (TargetKey *) aKey; TargetKey *targetKey = (TargetKey *) aKey;

Просмотреть файл

@ -227,7 +227,7 @@ static nsHashtable *theTargetRegistry = new nsHashtable();
static nsHashtable *theSystemTargetRegistry = new nsHashtable(); static nsHashtable *theSystemTargetRegistry = new nsHashtable();
static nsHashtable *theDescToTargetRegistry = new nsHashtable(); static nsHashtable *theDescToTargetRegistry = new nsHashtable();
static PRBool addToTargetArray(nsHashKey *aKey, void *aData); static PRBool addToTargetArray(nsHashKey *aKey, void *aData, void* closure);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -1323,7 +1323,7 @@ void nsTarget::getFlattenedTargets(nsHashtable *targHash,
} }
} }
static PRBool addToTargetArray(nsHashKey *aKey, void *aData) static PRBool addToTargetArray(nsHashKey *aKey, void *aData, void* closure)
{ {
TargetKey *targetKey = (TargetKey *) aKey; TargetKey *targetKey = (TargetKey *) aKey;
nsTarget *target = targetKey->itsTarget; nsTarget *target = targetKey->itsTarget;

Просмотреть файл

@ -250,7 +250,7 @@ StyleSetImpl::StyleSetImpl()
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
PRBool ReleaseContext(nsHashKey *aKey, void *aData) PRBool ReleaseContext(nsHashKey *aKey, void *aData, void* closure)
{ {
((nsIStyleContext*)aData)->Release(); ((nsIStyleContext*)aData)->Release();
return PR_TRUE; return PR_TRUE;
@ -726,7 +726,7 @@ static ContextNode* FindNode(nsIStyleContext* aContext, ContextNode* aStart)
return nsnull; return nsnull;
} }
PRBool GatherContexts(nsHashKey *aKey, void *aData) PRBool GatherContexts(nsHashKey *aKey, void *aData, void* closure)
{ {
PRBool result = PR_TRUE; PRBool result = PR_TRUE;

Просмотреть файл

@ -144,7 +144,7 @@ RuleHash::RuleHash(void)
{ {
} }
static PRBool DeleteValue(nsHashKey* aKey, void* aValue) static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
{ {
delete ((RuleValue*)aValue); delete ((RuleValue*)aValue);
return PR_TRUE; return PR_TRUE;

Просмотреть файл

@ -250,7 +250,7 @@ StyleSetImpl::StyleSetImpl()
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
PRBool ReleaseContext(nsHashKey *aKey, void *aData) PRBool ReleaseContext(nsHashKey *aKey, void *aData, void* closure)
{ {
((nsIStyleContext*)aData)->Release(); ((nsIStyleContext*)aData)->Release();
return PR_TRUE; return PR_TRUE;
@ -726,7 +726,7 @@ static ContextNode* FindNode(nsIStyleContext* aContext, ContextNode* aStart)
return nsnull; return nsnull;
} }
PRBool GatherContexts(nsHashKey *aKey, void *aData) PRBool GatherContexts(nsHashKey *aKey, void *aData, void* closure)
{ {
PRBool result = PR_TRUE; PRBool result = PR_TRUE;

Просмотреть файл

@ -144,7 +144,7 @@ RuleHash::RuleHash(void)
{ {
} }
static PRBool DeleteValue(nsHashKey* aKey, void* aValue) static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
{ {
delete ((RuleValue*)aValue); delete ((RuleValue*)aValue);
return PR_TRUE; return PR_TRUE;

Просмотреть файл

@ -144,7 +144,7 @@ RuleHash::RuleHash(void)
{ {
} }
static PRBool DeleteValue(nsHashKey* aKey, void* aValue) static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
{ {
delete ((RuleValue*)aValue); delete ((RuleValue*)aValue);
return PR_TRUE; return PR_TRUE;

Просмотреть файл

@ -250,7 +250,7 @@ StyleSetImpl::StyleSetImpl()
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
PRBool ReleaseContext(nsHashKey *aKey, void *aData) PRBool ReleaseContext(nsHashKey *aKey, void *aData, void* closure)
{ {
((nsIStyleContext*)aData)->Release(); ((nsIStyleContext*)aData)->Release();
return PR_TRUE; return PR_TRUE;
@ -726,7 +726,7 @@ static ContextNode* FindNode(nsIStyleContext* aContext, ContextNode* aStart)
return nsnull; return nsnull;
} }
PRBool GatherContexts(nsHashKey *aKey, void *aData) PRBool GatherContexts(nsHashKey *aKey, void *aData, void* closure)
{ {
PRBool result = PR_TRUE; PRBool result = PR_TRUE;

Просмотреть файл

@ -71,11 +71,17 @@ static PLHashAllocOps _hashAllocOps = {
// Enumerator callback // Enumerator callback
// //
struct _HashEnumerateArgs {
nsHashtableEnumFunc fn;
void* arg;
};
static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg) static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
{ {
return ((nsHashtableEnumFunc) arg)((nsHashKey *) he->key, he->value) ? _HashEnumerateArgs* thunk = (_HashEnumerateArgs*)arg;
HT_ENUMERATE_NEXT : return thunk->fn((nsHashKey *) he->key, he->value, thunk->arg)
HT_ENUMERATE_STOP; ? HT_ENUMERATE_NEXT
: HT_ENUMERATE_STOP;
} }
// //
@ -151,6 +157,9 @@ nsHashtable * nsHashtable::Clone() {
return newHashTable; return newHashTable;
} }
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc) { void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure) {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, aEnumFunc); _HashEnumerateArgs thunk;
thunk.fn = aEnumFunc;
thunk.arg = closure;
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, &thunk);
} }

Просмотреть файл

@ -71,11 +71,17 @@ static PLHashAllocOps _hashAllocOps = {
// Enumerator callback // Enumerator callback
// //
struct _HashEnumerateArgs {
nsHashtableEnumFunc fn;
void* arg;
};
static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg) static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
{ {
return ((nsHashtableEnumFunc) arg)((nsHashKey *) he->key, he->value) ? _HashEnumerateArgs* thunk = (_HashEnumerateArgs*)arg;
HT_ENUMERATE_NEXT : return thunk->fn((nsHashKey *) he->key, he->value, thunk->arg)
HT_ENUMERATE_STOP; ? HT_ENUMERATE_NEXT
: HT_ENUMERATE_STOP;
} }
// //
@ -151,6 +157,9 @@ nsHashtable * nsHashtable::Clone() {
return newHashTable; return newHashTable;
} }
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc) { void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure) {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, aEnumFunc); _HashEnumerateArgs thunk;
thunk.fn = aEnumFunc;
thunk.arg = closure;
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, &thunk);
} }

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* 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 nsHashtable_h__
#define nsHashtable_h__
#include "plhash.h"
#include "nsCom.h"
class NS_COM nsHashKey {
protected:
nsHashKey(void);
public:
virtual ~nsHashKey(void);
virtual PRUint32 HashValue(void) const = 0;
virtual PRBool Equals(const nsHashKey *aKey) const = 0;
virtual nsHashKey *Clone(void) const = 0;
};
// Enumerator callback function. Use
typedef PRBool (*nsHashtableEnumFunc)(nsHashKey *aKey, void *aData);
class NS_COM nsHashtable {
private:
// members
PLHashTable *hashtable;
public:
nsHashtable(PRUint32 aSize = 256);
~nsHashtable();
PRInt32 Count(void) { return hashtable->nentries; }
void *Put(nsHashKey *aKey, void *aData);
void *Get(nsHashKey *aKey);
void *Remove(nsHashKey *aKey);
nsHashtable *Clone();
void Enumerate(nsHashtableEnumFunc aEnumFunc);
};
#endif