Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CategoryNode Class Reference

CategoryNode keeps a hashtable of it's entries. More...

#include <nsCategoryManager.h>

Collaboration diagram for CategoryNode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_METHOD GetLeaf (const char *aEntryName, char **_retval)
NS_METHOD AddLeaf (const char *aEntryName, const char *aValue, PRBool aPersist, PRBool aReplace, char **_retval, PLArenaPool *aArena)
NS_METHOD DeleteLeaf (const char *aEntryName, PRBool aDontPersist)
void Clear ()
PRUint32 Count ()
NS_METHOD Enumerate (nsISimpleEnumerator **_retval)
PRBool WritePersistentEntries (PRFileDesc *fd, const char *aCategoryName)
 ~CategoryNode ()
void operator delete (void *)

Static Public Member Functions

static CategoryNodeCreate (PLArenaPool *aArena)

Private Member Functions

 CategoryNode ()
voidoperator new (size_t aSize, PLArenaPool *aArena)

Private Attributes

nsTHashtable< CategoryLeafmTable
PRLockmLock

Detailed Description

CategoryNode keeps a hashtable of it's entries.

the CategoryNode itself is permanently allocated in the arena.

Definition at line 80 of file nsCategoryManager.h.


Constructor & Destructor Documentation

Definition at line 252 of file nsCategoryManager.cpp.

Here is the call graph for this function:

CategoryNode::CategoryNode ( ) [inline, private]

Definition at line 119 of file nsCategoryManager.h.

{ }

Here is the caller graph for this function:


Member Function Documentation

NS_METHOD CategoryNode::AddLeaf ( const char *  aEntryName,
const char *  aValue,
PRBool  aPersist,
PRBool  aReplace,
char **  _retval,
PLArenaPool aArena 
)

Definition at line 287 of file nsCategoryManager.cpp.

{
  PR_Lock(mLock);
  CategoryLeaf* leaf = 
    mTable.GetEntry(aEntryName);

  nsresult rv = NS_OK;
  if (leaf) {
    //if the entry was found, aReplace must be specified
    if (!aReplace && (leaf->nonpValue || (aPersist && leaf->pValue )))
      rv = NS_ERROR_INVALID_ARG;
  } else {
    const char* arenaEntryName = ArenaStrdup(aEntryName, aArena);
    if (!arenaEntryName) {
      rv = NS_ERROR_OUT_OF_MEMORY;
    } else {
      leaf = mTable.PutEntry(arenaEntryName);
      if (!leaf)
        rv = NS_ERROR_OUT_OF_MEMORY;
    }
  }

  if (NS_SUCCEEDED(rv)) {
    const char* arenaValue = ArenaStrdup(aValue, aArena);
    if (!arenaValue) {
      rv = NS_ERROR_OUT_OF_MEMORY;
    } else {
      leaf->nonpValue = arenaValue;
      if (aPersist)
        leaf->pValue = arenaValue;
    }
  }
    
  PR_Unlock(mLock);
  return rv;
}

Here is the call graph for this function:

void CategoryNode::Clear ( void  ) [inline]

Definition at line 96 of file nsCategoryManager.h.

Here is the call graph for this function:

Definition at line 102 of file nsCategoryManager.h.

                   {
    PR_Lock(mLock);
    PRUint32 tCount = mTable.Count();
    PR_Unlock(mLock);
    return tCount;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

CategoryNode * CategoryNode::Create ( PLArenaPool aArena) [static]

Definition at line 232 of file nsCategoryManager.cpp.

{
  CategoryNode* node = new(aArena) CategoryNode();
  if (!node)
    return nsnull;

  if (!node->mTable.Init()) {
    delete node;
    return nsnull;
  }

  node->mLock = PR_NewLock();
  if (!node->mLock) {
    delete node;
    return nsnull;
  }

  return node;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_METHOD CategoryNode::DeleteLeaf ( const char *  aEntryName,
PRBool  aDontPersist 
)

Definition at line 330 of file nsCategoryManager.cpp.

{
  // we don't throw any errors, because it normally doesn't matter
  // and it makes JS a lot cleaner
  PR_Lock(mLock);

  if (aDontPersist) {
    // we can just remove the entire hash entry without introspection
    mTable.RemoveEntry(aEntryName);
  } else {
    // if we are keeping the persistent value, we need to look at
    // the contents of the current entry
    CategoryLeaf* leaf = mTable.GetEntry(aEntryName);
    if (leaf) {
      if (leaf->pValue) {
        leaf->nonpValue = nsnull;
      } else {
        // if there is no persistent value, just remove the entry
        mTable.RawRemoveEntry(leaf);
      }
    }
  }
  PR_Unlock(mLock);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 359 of file nsCategoryManager.cpp.

{
  NS_ENSURE_ARG_POINTER(_retval);

  PR_Lock(mLock);
  EntryEnumerator* enumObj = EntryEnumerator::Create(mTable);
  PR_Unlock(mLock);

  if (!enumObj)
    return NS_ERROR_OUT_OF_MEMORY;

  *_retval = enumObj;
  NS_ADDREF(*_retval);
  return NS_OK;
}

Here is the call graph for this function:

NS_METHOD CategoryNode::GetLeaf ( const char *  aEntryName,
char **  _retval 
)

Definition at line 267 of file nsCategoryManager.cpp.

{
  PR_Lock(mLock);
  nsresult rv = NS_ERROR_NOT_AVAILABLE;
  CategoryLeaf* ent =
    mTable.GetEntry(aEntryName);

  // we only want the non-persistent value
  if (ent && ent->nonpValue) {
    *_retval = nsCRT::strdup(ent->nonpValue);
    if (*_retval)
      rv = NS_OK;
  }
  PR_Unlock(mLock);

  return rv;
}

Here is the call graph for this function:

void CategoryNode::operator delete ( void ) [inline]

Definition at line 116 of file nsCategoryManager.h.

{ }
void * CategoryNode::operator new ( size_t  aSize,
PLArenaPool aArena 
) [private]

Definition at line 259 of file nsCategoryManager.cpp.

{
  void* p;
  PL_ARENA_ALLOCATE(p, aArena, aSize);
  return p;
}
PRBool CategoryNode::WritePersistentEntries ( PRFileDesc fd,
const char *  aCategoryName 
)

Definition at line 404 of file nsCategoryManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 123 of file nsCategoryManager.h.

Definition at line 122 of file nsCategoryManager.h.


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