Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes
nsUint32ToContentHashEntry Class Reference

Hashentry using a PRUint32 key and a cheap set of nsIContent* owning pointers for the value. More...

#include <nsDocument.h>

Inheritance diagram for nsUint32ToContentHashEntry:
Inheritance graph
[legend]
Collaboration diagram for nsUint32ToContentHashEntry:
Collaboration graph
[legend]

List of all members.

Classes

struct  Visitor

Public Types

enum  { ALLOW_MEMMOVE = PR_TRUE }
typedef const PRUint32KeyType
typedef const PRUint32KeyTypePointer

Public Member Functions

 nsUint32ToContentHashEntry (const KeyTypePointer key)
 nsUint32ToContentHashEntry (const nsUint32ToContentHashEntry &toCopy)
 ~nsUint32ToContentHashEntry ()
KeyType GetKey () const
KeyTypePointer GetKeyPointer () const
PRBool KeyEquals (KeyTypePointer aKey) const
nsresult PutContent (nsIContent *aContent)
void RemoveContent (nsIContent *aContent)
void VisitContent (Visitor *aVisitor)
PRBool IsEmpty ()

Static Public Member Functions

static KeyTypePointer KeyToPointer (KeyType aKey)
static PLDHashNumber HashKey (KeyTypePointer aKey)

Public Attributes

PLDHashNumber keyHash

Private Types

typedef unsigned long PtrBits
typedef nsTHashtable
< nsISupportsHashKey
HashSet

Private Member Functions

HashSetGetHashSet ()
 Get the hash pointer (or null if we're not a hash)
nsIContentGetContent ()
 Find out whether it is an nsIContent (returns weak)
nsresult SetContent (nsIContent *aVal)
 Set the single element, adding a reference.
nsresult InitHashSet (HashSet **aSet)
 Initialize the hash.
void Destroy ()

Private Attributes

const PRUint32 mValue
voidmValOrHash
 A hash or nsIContent ptr, depending on the lower bit (0=hash, 1=ptr)

Detailed Description

Hashentry using a PRUint32 key and a cheap set of nsIContent* owning pointers for the value.

See also:
nsTHashtable::EntryType for specification

Definition at line 121 of file nsDocument.h.


Member Typedef Documentation

Definition at line 163 of file nsDocument.h.

Definition at line 124 of file nsDocument.h.

Definition at line 125 of file nsDocument.h.

typedef unsigned long nsUint32ToContentHashEntry::PtrBits [private]

Definition at line 162 of file nsDocument.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
ALLOW_MEMMOVE 

Definition at line 147 of file nsDocument.h.


Constructor & Destructor Documentation

Definition at line 127 of file nsDocument.h.

Definition at line 129 of file nsDocument.h.

                                                                         :
      mValue(toCopy.mValue), mValOrHash(toCopy.mValOrHash)
    {
      // Pathetic attempt to not die: clear out the other mValOrHash so we're
      // effectively stealing it. If toCopy is destroyed right after this,
      // we'll be OK.
      NS_CONST_CAST(nsUint32ToContentHashEntry&, toCopy).mValOrHash = nsnull;
      NS_ERROR("Copying not supported. Fasten your seat belt.");
    }

Definition at line 138 of file nsDocument.h.

{ Destroy(); }

Here is the call graph for this function:


Member Function Documentation

Definition at line 159 of file nsDocument.cpp.

{
  HashSet* set = GetHashSet();
  if (set) {
    delete set;
  } else {
    nsIContent* content = GetContent();
    NS_IF_RELEASE(content);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Find out whether it is an nsIContent (returns weak)

Definition at line 170 of file nsDocument.h.

    {
      return (PtrBits(mValOrHash) & 0x1)
             ? (nsIContent*)(PtrBits(mValOrHash) & ~0x1)
             : nsnull;
    }

Here is the caller graph for this function:

Get the hash pointer (or null if we're not a hash)

Definition at line 165 of file nsDocument.h.

    {
      return (PtrBits(mValOrHash) & 0x1) ? nsnull : (HashSet*)mValOrHash;
    }

Here is the caller graph for this function:

Definition at line 140 of file nsDocument.h.

{ return mValue; }

Definition at line 141 of file nsDocument.h.

{ return &mValue; }

Definition at line 146 of file nsDocument.h.

{ return *aKey; }

Initialize the hash.

Definition at line 223 of file nsDocument.cpp.

{
  HashSet* newSet = new HashSet();
  if (!newSet) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  nsresult rv = newSet->Init();
  NS_ENSURE_SUCCESS(rv, rv);

  mValOrHash = newSet;
  *aSet = newSet;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 159 of file nsDocument.h.

{ return mValOrHash == nsnull; }

Definition at line 143 of file nsDocument.h.

{ return mValue == *aKey; }

Definition at line 145 of file nsDocument.h.

{ return &aKey; }

Definition at line 171 of file nsDocument.cpp.

{
  // Add the value to the hash if it is there
  HashSet* set = GetHashSet();
  if (set) {
    nsISupportsHashKey* entry = set->PutEntry(aVal);
    return entry ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
  }

  // If an element is already there, create a hashtable and both of these to it
  if (GetContent()) {
    nsIContent* oldVal = GetContent();
    nsresult rv = InitHashSet(&set);
    NS_ENSURE_SUCCESS(rv, rv);

    nsISupportsHashKey* entry = set->PutEntry(oldVal);
    if (!entry)
      return NS_ERROR_OUT_OF_MEMORY;
    // The hashset adds its own reference, so release the one we had
    NS_RELEASE(oldVal);

    entry = set->PutEntry(aVal);
    return entry ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
  }

  // Nothing exists in the hash right now, so just set the single pointer
  return SetContent(aVal);
}

Here is the call graph for this function:

Definition at line 201 of file nsDocument.cpp.

{
  // Remove from the hash if the hash is there
  HashSet* set = GetHashSet();
  if (set) {
    set->RemoveEntry(aVal);
    if (set->Count() == 0) {
      delete set;
      mValOrHash = nsnull;
    }
    return;
  }

  // Remove the ptr if there is just a ptr
  nsIContent* v = GetContent();
  if (v == aVal) {
    NS_IF_RELEASE(v);
    mValOrHash = nsnull;
  }
}

Here is the call graph for this function:

Set the single element, adding a reference.

Definition at line 177 of file nsDocument.h.

    {
      NS_IF_ADDREF(aVal);
      mValOrHash = (void*)(PtrBits(aVal) | 0x1);
      return NS_OK;
    }

Here is the caller graph for this function:

Definition at line 249 of file nsDocument.cpp.

{
  HashSet* set = GetHashSet();
  if (set) {
    set->EnumerateEntries(nsUint32ToContentHashEntryVisitorCallback, aVisitor);
    if (set->Count() == 0) {
      delete set;
      mValOrHash = nsnull;
    }
    return;
  }

  nsIContent* v = GetContent();
  if (v) {
    aVisitor->Visit(v);
  }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 113 of file pldhash.h.

A hash or nsIContent ptr, depending on the lower bit (0=hash, 1=ptr)

Definition at line 191 of file nsDocument.h.

Definition at line 189 of file nsDocument.h.


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