Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
nsTreeRows::Subtree Class Reference

A subtree in the tree. More...

#include <nsTreeRows.h>

Collaboration diagram for nsTreeRows::Subtree:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Subtree (Subtree *aParent)
 Creates a subtree with the specified parent.
 ~Subtree ()
PRInt32 Count () const
 Return the number of immediate child rows in the subtree.
PRInt32 GetSubtreeSize () const
 Return the number of rows in this subtree, as well as all the subtrees it contains.
const Rowoperator[] (PRInt32 aIndex) const
 Retrieve the immediate child row at the specified index.
Rowoperator[] (PRInt32 aIndex)
 Retrieve the immediate row at the specified index.
void Clear ()
 Remove all rows from the subtree.

Protected Member Functions

iterator InsertRowAt (nsTemplateMatch *aMatch, PRInt32 aIndex)
 Insert an immediate child row at the specified index.
void RemoveRowAt (PRInt32 aChildIndex)
 Remove an immediate child row from the specified index.

Protected Attributes

SubtreemParent
 The parent subtree; null if we're the root.
PRInt32 mCount
 The number of immediate children in this subtree.
PRInt32 mCapacity
 The capacity of the subtree.
PRInt32 mSubtreeSize
 The total number of rows in this subtree, recursively including child subtrees.
RowmRows
 The array of rows in the subtree.

Friends

class nsTreeRows

Detailed Description

A subtree in the tree.

A subtree contains rows, which may contain other subtrees.

Definition at line 101 of file nsTreeRows.h.


Constructor & Destructor Documentation

nsTreeRows::Subtree::Subtree ( Subtree aParent) [inline]

Creates a subtree with the specified parent.

Definition at line 135 of file nsTreeRows.h.

            : mParent(aParent),
              mCount(0),
              mCapacity(0),
              mSubtreeSize(0),
              mRows(nsnull) {}

Definition at line 208 of file nsTreeRows.cpp.

{
    Clear();
}

Here is the call graph for this function:


Member Function Documentation

Remove all rows from the subtree.

Definition at line 214 of file nsTreeRows.cpp.

{
    for (PRInt32 i = mCount - 1; i >= 0; --i)
        delete mRows[i].mSubtree;

    delete[] mRows;

    mRows = nsnull;
    mCount = mCapacity = mSubtreeSize = 0;
}

Here is the caller graph for this function:

PRInt32 nsTreeRows::Subtree::Count ( ) const [inline]

Return the number of immediate child rows in the subtree.

Definition at line 147 of file nsTreeRows.h.

{ return mCount; }

Here is the caller graph for this function:

Return the number of rows in this subtree, as well as all the subtrees it contains.

Definition at line 153 of file nsTreeRows.h.

{ return mSubtreeSize; }

Here is the caller graph for this function:

Insert an immediate child row at the specified index.

Definition at line 226 of file nsTreeRows.cpp.

{
    if (mCount >= mCapacity || aIndex >= mCapacity) {
        PRInt32 newCapacity = NS_MAX(mCapacity * 2, aIndex + 1);
        Row* newRows = new Row[newCapacity];
        if (! newRows)
            return iterator();

        for (PRInt32 i = mCount - 1; i >= 0; --i)
            newRows[i] = mRows[i];

        delete[] mRows;

        mRows = newRows;
        mCapacity = newCapacity;
    }

    for (PRInt32 i = mCount - 1; i >= aIndex; --i)
        mRows[i + 1] = mRows[i];

    mRows[aIndex].mMatch = aMatch;
    mRows[aIndex].mContainerType = eContainerType_Unknown;
    mRows[aIndex].mContainerState = eContainerState_Unknown;
    mRows[aIndex].mContainerFill = eContainerFill_Unknown;
    mRows[aIndex].mSubtree = nsnull;
    ++mCount;

    // Now build an iterator that points to the newly inserted element.
    PRInt32 rowIndex = 0;
    iterator result;
    result.Push(this, aIndex);

    for ( ; --aIndex >= 0; ++rowIndex) {
        // Account for open subtrees in the absolute row index.
        const Subtree *subtree = mRows[aIndex].mSubtree;
        if (subtree)
            rowIndex += subtree->mSubtreeSize;
    }

    Subtree *subtree = this;
    do {
        // Note that the subtree's size has expanded.
        ++subtree->mSubtreeSize;

        Subtree *parent = subtree->mParent;
        if (! parent)
            break;

        // Account for open subtrees in the absolute row index.
        PRInt32 count = parent->Count();
        for (aIndex = 0; aIndex < count; ++aIndex, ++rowIndex) {
            const Subtree *child = (*parent)[aIndex].mSubtree;
            if (subtree == child)
                break;

            if (child)
                rowIndex += child->mSubtreeSize;
        }

        NS_ASSERTION(aIndex < count, "couldn't find subtree in parent");

        result.Push(parent, aIndex);
        subtree = parent;
        ++rowIndex; // One for the parent row.
    } while (1);

    result.SetRowIndex(rowIndex);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const Row& nsTreeRows::Subtree::operator[] ( PRInt32  aIndex) const [inline]

Retrieve the immediate child row at the specified index.

Definition at line 158 of file nsTreeRows.h.

                                                    {
            NS_PRECONDITION(aIndex >= 0 && aIndex < mCount, "bad index");
            return mRows[aIndex]; }
Row& nsTreeRows::Subtree::operator[] ( PRInt32  aIndex) [inline]

Retrieve the immediate row at the specified index.

Definition at line 165 of file nsTreeRows.h.

                                        {
            NS_PRECONDITION(aIndex >= 0 && aIndex < mCount, "bad index");
            return mRows[aIndex]; }
void nsTreeRows::Subtree::RemoveRowAt ( PRInt32  aChildIndex) [protected]

Remove an immediate child row from the specified index.

Definition at line 297 of file nsTreeRows.cpp.

{
    NS_PRECONDITION(aIndex >= 0 && aIndex < Count(), "bad index");
    if (aIndex < 0 || aIndex >= Count())
        return;

    // How big is the subtree we're going to be removing?
    PRInt32 subtreeSize = mRows[aIndex].mSubtree
        ? mRows[aIndex].mSubtree->GetSubtreeSize()
        : 0;

    ++subtreeSize;

    delete mRows[aIndex].mSubtree;

    for (PRInt32 i = aIndex + 1; i < mCount; ++i)
        mRows[i - 1] = mRows[i];

    --mCount;

    for (Subtree* subtree = this; subtree != nsnull; subtree = subtree->mParent)
        subtree->mSubtreeSize -= subtreeSize;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsTreeRows [friend]

Definition at line 103 of file nsTreeRows.h.


Member Data Documentation

The capacity of the subtree.

Definition at line 118 of file nsTreeRows.h.

The number of immediate children in this subtree.

Definition at line 113 of file nsTreeRows.h.

The parent subtree; null if we're the root.

Definition at line 108 of file nsTreeRows.h.

The array of rows in the subtree.

Definition at line 129 of file nsTreeRows.h.

The total number of rows in this subtree, recursively including child subtrees.

Definition at line 124 of file nsTreeRows.h.


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