Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsInterfaceHashtable< KeyClass, Interface > Class Template Reference

templated hashtable class maps keys to interface pointers. More...

#include <nsInterfaceHashtable.h>

Inheritance diagram for nsInterfaceHashtable< KeyClass, Interface >:
Inheritance graph
[legend]
Collaboration diagram for nsInterfaceHashtable< KeyClass, Interface >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef KeyClass::KeyType KeyType
 KeyType is typedef'ed for ease of use.
typedef Interface * UserDataType
typedef nsBaseHashtableET
< KeyClass, nsCOMPtr
< Interface > > 
EntryType
typedef PLDHashOperator(* PR_CALLBACK )(KeyType aKey, Interface *aData, void *userArg)
 function type provided by the application for enumeration.
typedef PLDHashOperator(* PR_CALLBACK )(KeyType aKey, nsCOMPtr< Interface > &aData, void *userArg)
 function type provided by the application for enumeration.

Public Member Functions

PRBool Get (KeyType aKey, UserDataType *pData) const
 retrieve the value for a key.
Interface * GetWeak (KeyType aKey, PRBool *aFound=nsnull) const
 Gets a weak reference to the hashtable entry.
PRBool Init (PRUint32 initSize=PL_DHASH_MIN_SIZE)
 Initialize the object.
PRBool IsInitialized () const
 Check whether the table has been initialized.
PRUint32 Count () const
 Return the number of entries in the table.
PRBool Put (KeyType aKey, Interface *aData)
 put a new value for the associated key
void Remove (KeyType aKey)
 remove the data for the associated key
PRUint32 EnumerateRead (EnumReadFunction enumFunc, void *userArg) const
 enumerate entries in the hashtable, without allowing changes
PRUint32 Enumerate (EnumFunction enumFunc, void *userArg)
 enumerate entries in the hashtable, allowing changes.
void Clear ()
 reset the hashtable, removing all entries

Protected Types

typedef nsBaseHashtableET
< KeyClass, nsCOMPtr
< Interface >
>::KeyTypePointer 
KeyTypePointer
 KeyTypePointer is typedef'ed for ease of use.

Protected Member Functions

nsBaseHashtableET< KeyClass,
nsCOMPtr< Interface > > * 
GetEntry (KeyType aKey) const
 Get the entry associated with a key.
nsBaseHashtableET< KeyClass,
nsCOMPtr< Interface > > * 
PutEntry (KeyType aKey)
 Get the entry associated with a key, or create a new entry,.
void RemoveEntry (KeyType aKey)
 Remove the entry associated with a key.
void RawRemoveEntry (nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > *aEntry)
 Remove the entry associated with a key, but don't resize the hashtable.
PRUint32 EnumerateEntries (Enumerator enumFunc, void *userArg)
 Enumerate all the entries of the function.

Static Protected Member Functions

static PLDHashOperator s_EnumReadStub (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
static PLDHashOperator s_EnumStub (PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, void *arg)
static const void *PR_CALLBACK s_GetKey (PLDHashTable *table, PLDHashEntryHdr *entry)
static PLDHashNumber PR_CALLBACK s_HashKey (PLDHashTable *table, const void *key)
static PRBool PR_CALLBACK s_MatchEntry (PLDHashTable *table, const PLDHashEntryHdr *entry, const void *key)
static void PR_CALLBACK s_CopyEntry (PLDHashTable *table, const PLDHashEntryHdr *from, PLDHashEntryHdr *to)
static void PR_CALLBACK s_ClearEntry (PLDHashTable *table, PLDHashEntryHdr *entry)
static PRBool PR_CALLBACK s_InitEntry (PLDHashTable *table, PLDHashEntryHdr *entry, const void *key)

Protected Attributes

PLDHashTable mTable

Detailed Description

template<class KeyClass, class Interface>
class nsInterfaceHashtable< KeyClass, Interface >

templated hashtable class maps keys to interface pointers.

See nsBaseHashtable for complete declaration.

Parameters:
KeyClassa wrapper-class for the hashtable key, see nsHashKeys.h for a complete specification.
Interfacethe interface-type being wrapped
See also:
nsDataHashtable, nsClassHashtable

Definition at line 54 of file nsInterfaceHashtable.h.


Member Typedef Documentation

typedef nsBaseHashtableET<KeyClass,nsCOMPtr< Interface > > nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::EntryType [inherited]

Definition at line 87 of file nsBaseHashtable.h.

template<class KeyClass, class Interface>
typedef KeyClass::KeyType nsInterfaceHashtable< KeyClass, Interface >::KeyType

KeyType is typedef'ed for ease of use.

Reimplemented from nsBaseHashtable< KeyClass, nsCOMPtr< Interface >, Interface * >.

Definition at line 58 of file nsInterfaceHashtable.h.

KeyTypePointer is typedef'ed for ease of use.

Definition at line 144 of file nsTHashtable.h.

typedef PLDHashOperator(* nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::PR_CALLBACK)(KeyType aKey, Interface * aData, void *userArg) [inherited]

function type provided by the application for enumeration.

Parameters:
aKeythe key being enumerated
aDatadata being enumerated userArg passed unchanged from Enumerate
Returns:
either PL_DHASH_NEXT or PL_DHASH_STOP

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 171 of file nsBaseHashtable.h.

typedef PLDHashOperator(* nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::PR_CALLBACK)(KeyType aKey, nsCOMPtr< Interface > &aData, void *userArg) [inherited]

function type provided by the application for enumeration.

Parameters:
aKeythe key being enumerated
aDataReference to data being enumerated, may be altered. e.g. for nsInterfaceHashtable this is an nsCOMPtr reference... userArg passed unchanged from Enumerate
Returns:
bitflag combination of PLDHashOperator::PL_DHASH_REMOVE, PL_DHASH_NEXT , or PL_DHASH_STOP

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 203 of file nsBaseHashtable.h.

template<class KeyClass, class Interface>
typedef Interface* nsInterfaceHashtable< KeyClass, Interface >::UserDataType

Definition at line 59 of file nsInterfaceHashtable.h.


Member Function Documentation

void nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Clear ( void  ) [inline, inherited]

reset the hashtable, removing all entries

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 227 of file nsBaseHashtable.h.

Here is the caller graph for this function:

PRUint32 nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Count ( void  ) const [inline, inherited]

Return the number of entries in the table.

Returns:
number of entries

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 112 of file nsBaseHashtable.h.

PRUint32 nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Enumerate ( EnumFunction  enumFunc,
void userArg 
) [inline, inherited]

enumerate entries in the hashtable, allowing changes.

This functions write-locks the hashtable.

Parameters:
enumFuncenumeration callback
userArgpassed unchanged to the EnumFunction

Definition at line 213 of file nsBaseHashtable.h.

  {
    NS_ASSERTION(this->mTable.entrySize,
                 "nsBaseHashtable was not initialized properly.");

    s_EnumArgs enumData = { enumFunc, userArg };
    return PL_DHashTableEnumerate(&this->mTable,
                                  s_EnumStub,
                                  &enumData);
  }

Here is the caller graph for this function:

PRUint32 nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::EnumerateEntries ( Enumerator  enumFunc,
void userArg 
) [inline, inherited]

Enumerate all the entries of the function.

Parameters:
enumFuncthe Enumerator function to call
userArga pointer to pass to the Enumerator function
Returns:
the number of entries actually enumerated

Definition at line 233 of file nsTHashtable.h.

  {
    NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
    
    s_EnumArgs args = { enumFunc, userArg };
    return PL_DHashTableEnumerate(&mTable, s_EnumStub, &args);
  }
PRUint32 nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::EnumerateRead ( EnumReadFunction  enumFunc,
void userArg 
) const [inline, inherited]

enumerate entries in the hashtable, without allowing changes

Parameters:
enumFuncenumeration callback
userArgpassed unchanged to the EnumReadFunction

Definition at line 180 of file nsBaseHashtable.h.

  {
    NS_ASSERTION(this->mTable.entrySize,
                 "nsBaseHashtable was not initialized properly.");

    s_EnumReadArgs enumData = { enumFunc, userArg };
    return PL_DHashTableEnumerate(NS_CONST_CAST(PLDHashTable*, &this->mTable),
                                  s_EnumReadStub,
                                  &enumData);
  }

Here is the caller graph for this function:

template<class KeyClass , class Interface >
PRBool nsInterfaceHashtable< KeyClass, Interface >::Get ( KeyType  aKey,
UserDataType pData 
) const

retrieve the value for a key.

Parameters:
aKeythe key to retreive
pDatadata associated with this key will be placed at this pointer. If you only need to check if the key exists, pData may be null.
Returns:
PR_TRUE if the key exists. If key does not exist, pData is not modified.

Parameters:
pDataThis is an XPCOM getter, so pData is already_addrefed. If the key doesn't exist, pData will be set to nsnull.

Reimplemented from nsBaseHashtable< KeyClass, nsCOMPtr< Interface >, Interface * >.

Definition at line 111 of file nsInterfaceHashtable.h.

{
  typename nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*>::EntryType* ent =
    GetEntry(aKey);

  if (ent)
  {
    if (pInterface)
    {
      *pInterface = ent->mData;

      NS_IF_ADDREF(*pInterface);
    }

    return PR_TRUE;
  }

  // if the key doesn't exist, set *pInterface to null
  // so that it is a valid XPCOM getter
  if (pInterface)
    *pInterface = nsnull;

  return PR_FALSE;
}

Here is the caller graph for this function:

nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > * nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::GetEntry ( KeyType  aKey) const [inline, inherited]

Get the entry associated with a key.

Parameters:
aKeythe key to retrieve
Returns:
pointer to the entry class, if the key exists; nsnull if the key doesn't exist

Definition at line 158 of file nsTHashtable.h.

  {
    NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
  
    EntryType* entry =
      NS_REINTERPRET_CAST(EntryType*,
                          PL_DHashTableOperate(
                            NS_CONST_CAST(PLDHashTable*,&mTable),
                            EntryType::KeyToPointer(aKey),
                            PL_DHASH_LOOKUP));
    return PL_DHASH_ENTRY_IS_BUSY(entry) ? entry : nsnull;
  }
template<class KeyClass , class Interface >
Interface * nsInterfaceHashtable< KeyClass, Interface >::GetWeak ( KeyType  aKey,
PRBool aFound = nsnull 
) const

Gets a weak reference to the hashtable entry.

Parameters:
aFoundIf not nsnull, will be set to PR_TRUE if the entry is found, to PR_FALSE otherwise.
Returns:
The entry, or nsnull if not found. Do not release this pointer!

Definition at line 139 of file nsInterfaceHashtable.h.

{
  typename nsBaseHashtable<KeyClass, nsCOMPtr<Interface>, Interface*>::EntryType* ent =
    GetEntry(aKey);

  if (ent)
  {
    if (aFound)
      *aFound = PR_TRUE;

    return ent->mData;
  }

  // Key does not exist, return nsnull and set aFound to PR_FALSE
  if (aFound)
    *aFound = PR_FALSE;
  return nsnull;
}

Here is the caller graph for this function:

PRBool nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Init ( PRUint32  initSize = PL_DHASH_MIN_SIZE) [inline, inherited]

Initialize the object.

Parameters:
initSizethe initial number of buckets in the hashtable, default 16 locking on all class methods
Returns:
PR_TRUE if the object was initialized properly.

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 98 of file nsBaseHashtable.h.

  { return nsTHashtable<EntryType>::Init(initSize); }

Here is the caller graph for this function:

PRBool nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::IsInitialized ( ) const [inline, inherited]

Check whether the table has been initialized.

This function is especially useful for static hashtables.

Returns:
PR_TRUE if the table has been initialized.

Reimplemented from nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >.

Definition at line 106 of file nsBaseHashtable.h.

{ return this->mTable.entrySize; }
PRBool nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Put ( KeyType  aKey,
Interface *  aData 
) [inline, inherited]

put a new value for the associated key

Parameters:
aKeythe key to put
aDatathe new data
Returns:
always PR_TRUE, unless memory allocation failed

Definition at line 143 of file nsBaseHashtable.h.

  {
    EntryType* ent = PutEntry(aKey);

    if (!ent)
      return PR_FALSE;

    ent->mData = aData;

    return PR_TRUE;
  }

Here is the caller graph for this function:

nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > * nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::PutEntry ( KeyType  aKey) [inline, inherited]

Get the entry associated with a key, or create a new entry,.

Parameters:
aKeythe key to retrieve
Returns:
pointer to the entry class retreived; nsnull only if memory can't be allocated

Definition at line 177 of file nsTHashtable.h.

  {
    NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");
    
    return NS_STATIC_CAST(EntryType*,
                          PL_DHashTableOperate(
                            &mTable,
                            EntryType::KeyToPointer(aKey),
                            PL_DHASH_ADD));
  }
void nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::RawRemoveEntry ( nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > *  aEntry) [inline, inherited]

Remove the entry associated with a key, but don't resize the hashtable.

This is a low-level method, and is not recommended unless you know what you're doing and you need the extra performance. This method can be used during enumeration, while RemoveEntry() cannot.

Parameters:
aEntrythe entry-pointer to remove (obtained from GetEntry or the enumerator

Definition at line 209 of file nsTHashtable.h.

void nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::Remove ( KeyType  aKey) [inline, inherited]

remove the data for the associated key

Parameters:
aKeythe key to remove from the hashtable

Definition at line 159 of file nsBaseHashtable.h.

{ RemoveEntry(aKey); }

Here is the caller graph for this function:

void nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::RemoveEntry ( KeyType  aKey) [inline, inherited]

Remove the entry associated with a key.

Parameters:
aKeyof the entry to remove

Definition at line 192 of file nsTHashtable.h.

  {
    NS_ASSERTION(mTable.entrySize, "nsTHashtable was not initialized properly.");

    PL_DHashTableOperate(&mTable,
                         EntryType::KeyToPointer(aKey),
                         PL_DHASH_REMOVE);
  }
static void PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_ClearEntry ( PLDHashTable table,
PLDHashEntryHdr entry 
) [static, protected, inherited]
static void PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_CopyEntry ( PLDHashTable table,
const PLDHashEntryHdr from,
PLDHashEntryHdr to 
) [static, protected, inherited]
static PLDHashOperator nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::s_EnumReadStub ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
) [static, protected, inherited]
static PLDHashOperator nsBaseHashtable< KeyClass, nsCOMPtr< Interface > , Interface * >::s_EnumStub ( PLDHashTable table,
PLDHashEntryHdr hdr,
PRUint32  number,
void arg 
) [static, protected, inherited]
static const void* PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_GetKey ( PLDHashTable table,
PLDHashEntryHdr entry 
) [static, protected, inherited]
static PLDHashNumber PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_HashKey ( PLDHashTable table,
const void key 
) [static, protected, inherited]
static PRBool PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_InitEntry ( PLDHashTable table,
PLDHashEntryHdr entry,
const void key 
) [static, protected, inherited]
static PRBool PR_CALLBACK nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::s_MatchEntry ( PLDHashTable table,
const PLDHashEntryHdr entry,
const void key 
) [static, protected, inherited]

Member Data Documentation

PLDHashTable nsTHashtable< nsBaseHashtableET< KeyClass, nsCOMPtr< Interface > > >::mTable [protected, inherited]

Definition at line 252 of file nsTHashtable.h.


The documentation for this class was generated from the following file: