Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
nsEntryStack Class Reference

#include <nsDTDUtils.h>

Collaboration diagram for nsEntryStack:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsEntryStack ()
 Default constructor harishd 04/04/99 gess 04/22/99.
 ~nsEntryStack ()
 Default destructor harishd 04/04/99 gess 04/22/99.
nsTagEntryPopEntry ()
void PushEntry (nsTagEntry *aEntry, PRBool aRefCntNode=PR_TRUE)
void EnsureCapacityFor (PRInt32 aNewMax, PRInt32 aShiftOffset=0)
 gess 04/22/99
void Push (nsCParserNode *aNode, nsEntryStack *aStyleStack=0, PRBool aRefCntNode=PR_TRUE)
 gess 04/22/99
void PushFront (nsCParserNode *aNode, nsEntryStack *aStyleStack=0, PRBool aRefCntNode=PR_TRUE)
 This method inserts the given node onto the front of this stack.
void Append (nsEntryStack *aStack)
 gess 11/10/99
nsCParserNodePop (void)
 harishd 04/04/99 gess 04/21/99
nsCParserNodeRemove (PRInt32 anIndex, eHTMLTags aTag)
 This method removes the node for the given tag from anywhere within this entry stack, and shifts other entries down.
nsCParserNodeNodeAt (PRInt32 anIndex) const
 harishd 04/04/99 gess 04/21/99
eHTMLTags First () const
 harishd 04/04/99 gess 04/21/99
eHTMLTags TagAt (PRInt32 anIndex) const
 harishd 04/04/99 gess 04/21/99
nsTagEntryEntryAt (PRInt32 anIndex) const
 gess 04/21/99
eHTMLTags operator[] (PRInt32 anIndex) const
 harishd 04/04/99 gess 04/21/99
eHTMLTags Last () const
 harishd 04/04/99 gess 04/21/99
void Empty (void)
 Resets state of stack to be empty.
void ReleaseAll (nsNodeAllocator *aNodeAllocator)
 Release all objects in the entry stack.
PRInt32 FirstOf (eHTMLTags aTag) const
 Find the first instance of given tag on the stack.
PRInt32 LastOf (eHTMLTags aTag) const
 Find the last instance of given tag on the stack.

Public Attributes

nsTagEntrymEntries
PRInt32 mCount
PRInt32 mCapacity

Detailed Description

Definition at line 115 of file nsDTDUtils.h.


Constructor & Destructor Documentation

Default constructor harishd 04/04/99 gess 04/22/99.

Definition at line 73 of file nsDTDUtils.cpp.

Default destructor harishd 04/04/99 gess 04/22/99.

Definition at line 87 of file nsDTDUtils.cpp.

                            {

  MOZ_COUNT_DTOR(nsEntryStack);

  if(mEntries) {
    //add code here to recycle the node if you have one...  
    delete [] mEntries;
    mEntries=0;
  }

  mCount=mCapacity=0;
}

Member Function Documentation

gess 11/10/99

Definition at line 210 of file nsDTDUtils.cpp.

                                              {
  if(aStack) {

    PRInt32 theCount=aStack->mCount;

    EnsureCapacityFor(mCount+aStack->mCount,0);

    PRInt32 theIndex=0;
    for(theIndex=0;theIndex<theCount;++theIndex){
      mEntries[mCount]=aStack->mEntries[theIndex];
      mEntries[mCount++].mParent=0;
    }
  }
} 

Here is the call graph for this function:

Here is the caller graph for this function:

Resets state of stack to be empty.

harishd 04/04/99

Definition at line 121 of file nsDTDUtils.cpp.

                             {
  mCount=0;
}
void nsEntryStack::EnsureCapacityFor ( PRInt32  aNewMax,
PRInt32  aShiftOffset = 0 
)

gess 04/22/99

Definition at line 130 of file nsDTDUtils.cpp.

                                                                         {
  if(mCapacity<aNewMax){ 

    const int kDelta=16;

    PRInt32 theSize = kDelta * ((aNewMax / kDelta) + 1);
    nsTagEntry* temp=new nsTagEntry[theSize]; 
    mCapacity=theSize;

    if(temp){ 
      PRInt32 index=0; 
      for(index=0;index<mCount;++index) {
        temp[aShiftOffset+index]=mEntries[index];
      }
      if(mEntries) delete [] mEntries;
      mEntries=temp;
    }
    else{
      //XXX HACK! This is very bad! We failed to get memory.
    }
  } //if
}

Here is the caller graph for this function:

gess 04/21/99

Definition at line 357 of file nsDTDUtils.cpp.

{
  nsTagEntry *result=0;
  if((0<mCount) && (anIndex<mCount)) {
    result=&mEntries[anIndex];
  }
  return result;
}

Here is the caller graph for this function:

harishd 04/04/99 gess 04/21/99

Definition at line 316 of file nsDTDUtils.cpp.

{
  eHTMLTags result=eHTMLTag_unknown;
  if(0<mCount){
    result=mEntries[0].mTag;
  }
  return result;
}

Here is the caller graph for this function:

PRInt32 nsEntryStack::FirstOf ( eHTMLTags  aTag) const [inline]

Find the first instance of given tag on the stack.

gess 12/14/99

Parameters:
aTag
Returns:
index of tag, or kNotFound if not found

Definition at line 148 of file nsDTDUtils.h.

                                               {
    PRInt32 index=-1;
    
    if(0<mCount) {
      while(++index<mCount) {
        if(aTag==mEntries[index].mTag) {
          return index;
        }
      } //while
    }
    return kNotFound;
  }

Here is the caller graph for this function:

harishd 04/04/99 gess 04/21/99

Definition at line 387 of file nsDTDUtils.cpp.

{
  eHTMLTags result=eHTMLTag_unknown;
  if(0<mCount) {
    result=mEntries[mCount-1].mTag;
  }
  return result;
}

Here is the caller graph for this function:

PRInt32 nsEntryStack::LastOf ( eHTMLTags  aTag) const [inline]

Find the last instance of given tag on the stack.

gess 12/14/99

Parameters:
aTag
Returns:
index of tag, or kNotFound if not found

Definition at line 168 of file nsDTDUtils.h.

                                              {
    PRInt32 index=mCount;
    while(--index>=0) {
        if(aTag==mEntries[index].mTag) {
          return index; 
        }
    }
    return kNotFound;
  }

Here is the caller graph for this function:

harishd 04/04/99 gess 04/21/99

Definition at line 330 of file nsDTDUtils.cpp.

{
  nsCParserNode* result=0;
  if((0<mCount) && (anIndex<mCount)) {
    result=mEntries[anIndex].mNode;
  }
  return result;
}

Here is the caller graph for this function:

eHTMLTags nsEntryStack::operator[] ( PRInt32  anIndex) const

harishd 04/04/99 gess 04/21/99

Definition at line 372 of file nsDTDUtils.cpp.

{
  eHTMLTags result=eHTMLTag_unknown;
  if((0<mCount) && (anIndex<mCount)) {
    result=mEntries[anIndex].mTag;
  }
  return result;
}

harishd 04/04/99 gess 04/21/99

Definition at line 277 of file nsDTDUtils.cpp.

{
  nsCParserNode* result = 0;
  if (0 < mCount) {
    result = mEntries[--mCount].mNode;
    if (result)
      result->mUseCount--;
    mEntries[mCount].mNode = 0;
    mEntries[mCount].mStyles = 0;
    nsEntryStack* theStyleStack=mEntries[mCount].mParent;
    if (theStyleStack) {
      //now we have to tell the residual style stack where this tag
      //originated that it's no longer in use.
      PRUint32 scount = theStyleStack->mCount;

      // XXX If this NS_ENSURE_TRUE fails, it means that the style stack was
      //     empty before we were removed.
      NS_ENSURE_TRUE(scount != 0, result);

      PRUint32 sindex = 0;
      nsTagEntry *theStyleEntry=theStyleStack->mEntries;

      for (sindex=scount-1;sindex>0;--sindex){            
        if (theStyleEntry->mTag==mEntries[mCount].mTag) {
          theStyleEntry->mParent=0;  //this tells us that the style is not open at any level
          break;
        }
        ++theStyleEntry;
      } //for
    }
  }
  return result;
} 

Here is the caller graph for this function:

Definition at line 397 of file nsDTDUtils.cpp.

{
  nsTagEntry* entry = EntryAt(mCount-1);
  this->Pop();
  return entry;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEntryStack::Push ( nsCParserNode aNode,
nsEntryStack aStyleStack = 0,
PRBool  aRefCntNode = PR_TRUE 
)

gess 04/22/99

Definition at line 157 of file nsDTDUtils.cpp.

{
  if(aNode) {
    EnsureCapacityFor(mCount+1);
    mEntries[mCount].mTag = (eHTMLTags)aNode->GetNodeType();
    if (aRefCntNode) {
      aNode->mUseCount++;
      mEntries[mCount].mNode = NS_CONST_CAST(nsCParserNode*,aNode);
      IF_HOLD(mEntries[mCount].mNode);
    }
    mEntries[mCount].mParent=aStyleStack;
    mEntries[mCount++].mStyles=0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEntryStack::PushEntry ( nsTagEntry aEntry,
PRBool  aRefCntNode = PR_TRUE 
)

Definition at line 404 of file nsDTDUtils.cpp.

{
  if (aEntry) {
    EnsureCapacityFor(mCount+1);
    mEntries[mCount].mNode   = aEntry->mNode;
    mEntries[mCount].mTag    = aEntry->mTag;
    mEntries[mCount].mParent = aEntry->mParent;
    mEntries[mCount].mStyles = aEntry->mStyles;
    if (aRefCntNode && mEntries[mCount].mNode) {
      mEntries[mCount].mNode->mUseCount++;
      IF_HOLD(mEntries[mCount].mNode);
    }
    mCount++;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsEntryStack::PushFront ( nsCParserNode aNode,
nsEntryStack aStyleStack = 0,
PRBool  aRefCntNode = PR_TRUE 
)

This method inserts the given node onto the front of this stack.

gess 11/10/99

Definition at line 180 of file nsDTDUtils.cpp.

{
  if(aNode) {
    if(mCount<mCapacity) {
      PRInt32 index=0; 
      for(index=mCount;index>0;index--) {
        mEntries[index]=mEntries[index-1];
      }
    }
    else {
      EnsureCapacityFor(mCount+1,1);
    }
    mEntries[0].mTag = (eHTMLTags)aNode->GetNodeType();
    if (aRefCntNode) {
      aNode->mUseCount++;
      mEntries[0].mNode = NS_CONST_CAST(nsCParserNode*,aNode);
      IF_HOLD(mEntries[0].mNode);
    }
    mEntries[0].mParent=aStyleStack;
    mEntries[0].mStyles=0;
    ++mCount;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Release all objects in the entry stack.

Definition at line 104 of file nsDTDUtils.cpp.

{
  NS_WARN_IF_FALSE(aNodeAllocator,"no allocator? - potential leak!");

  if(aNodeAllocator) {
    NS_WARN_IF_FALSE(mCount >= 0,"count should not be negative");
    while(mCount > 0) {
      nsCParserNode* node=this->Pop();
      IF_FREE(node,aNodeAllocator);
    }
  }
}

Here is the call graph for this function:

This method removes the node for the given tag from anywhere within this entry stack, and shifts other entries down.

NOTE: It's odd to be removing an element from the middle of a stack, but it's necessary because of how MALFORMED html can be.

anIndex: the index within the stack of the tag to be removed aTag: the id of the tag to be removed gess 02/25/00

Definition at line 238 of file nsDTDUtils.cpp.

{
  nsCParserNode* result = 0;
  if (0 < mCount && anIndex < mCount){
    result = mEntries[anIndex].mNode;
    if (result)
      result->mUseCount--;
    PRInt32 theIndex = 0;
    mCount -= 1;
    for( theIndex = anIndex; theIndex < mCount; ++theIndex){
      mEntries[theIndex] = mEntries[theIndex+1];
    }
    mEntries[mCount].mNode = 0;
    mEntries[mCount].mStyles = 0;
    nsEntryStack* theStyleStack = mEntries[anIndex].mParent;
    if (theStyleStack) {
      //now we have to tell the residual style stack where this tag
      //originated that it's no longer in use.
      PRUint32 scount = theStyleStack->mCount;
      PRUint32 sindex = 0;
      nsTagEntry *theStyleEntry=theStyleStack->mEntries;
      for (sindex=scount-1;sindex>0;--sindex){            
        if (theStyleEntry->mTag==aTag) {
          theStyleEntry->mParent=0;  //this tells us that the style is not open at any level
          break;
        }
        ++theStyleEntry;
      } //for
    }
  }
  return result;
}

Here is the caller graph for this function:

harishd 04/04/99 gess 04/21/99

Definition at line 344 of file nsDTDUtils.cpp.

{
  eHTMLTags result=eHTMLTag_unknown;
  if((0<mCount) && (anIndex<mCount)) {
    result=mEntries[anIndex].mTag;
  }
  return result;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 180 of file nsDTDUtils.h.

Definition at line 179 of file nsDTDUtils.h.

Definition at line 178 of file nsDTDUtils.h.


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