Back to index

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

This class maintains the state of the XUL tree builder's rows. More...

#include <nsTreeRows.h>

Collaboration diagram for nsTreeRows:
Collaboration graph
[legend]

List of all members.

Classes

class  iterator
 An iterator that can be used to traverse the tree view. More...
struct  Link
 A link in the path through the view's tree. More...
struct  Row
 A row in the tree. More...
class  Subtree
 A subtree in the tree. More...

Public Types

enum  Direction { eDirection_Forwards = +1, eDirection_Backwards = -1 }
enum  ContainerType { eContainerType_Unknown = 0, eContainerType_Noncontainer = 1, eContainerType_Container = -2 }
enum  ContainerState { eContainerState_Unknown = 0, eContainerState_Open = 1, eContainerState_Closed = -2 }
enum  ContainerFill { eContainerFill_Unknown = 0, eContainerFill_Empty = 1, eContainerFill_Nonempty = -2 }
enum  { kMaxDepth = 32 }

Public Member Functions

iterator First ()
 Retrieve the first element in the view.
iterator Last ()
 Retrieve (one past) the last element in the view.
iterator Find (nsConflictSet &aConflictSet, nsIRDFResource *aMember)
 Find the row that contains the match with the specified member resource.
iterator operator[] (PRInt32 aIndex)
 Retrieve the ith element in the view.
 nsTreeRows ()
 ~nsTreeRows ()
SubtreeEnsureSubtreeFor (Subtree *aParent, PRInt32 aChildIndex)
 Ensure that a child subtree exists within the specified parent at the specified child index within the parent.
SubtreeEnsureSubtreeFor (iterator &aIterator)
 Ensure that a child subtree exists at the iterator's position.
SubtreeGetSubtreeFor (const Subtree *aParent, PRInt32 aChildIndex, PRInt32 *aSubtreeSize=nsnull)
 Get the child subtree for the specified parent at the specified child index.
PRInt32 GetSubtreeSizeFor (const Subtree *aParent, PRInt32 aChildIndex)
 Retrieve the size of the subtree within the specified parent.
PRInt32 GetSubtreeSizeFor (const iterator &aIterator)
 Retrieve the size of the subtree within the specified parent.
void RemoveSubtreeFor (Subtree *aParent, PRInt32 aChildIndex)
 Remove the specified subtree for a row, leaving the row itself intact.
void RemoveSubtreeFor (iterator &aIterator)
 Remove the specified subtree for a row, leaving the row itself intact.
PRInt32 RemoveRowAt (iterator &aIterator)
 Remove the specified row from the view.
iterator InsertRowAt (nsTemplateMatch *aMatch, Subtree *aSubtree, PRInt32 aChildIndex)
 Insert a new match into the view.
RowGetRowsFor (Subtree *aSubtree)
 Raw access to the rows; e.g., for sorting.
void Clear ()
 Remove all of the rows.
PRInt32 Count () const
 Return the total number of rows in the tree view.
SubtreeGetRoot ()
 Retrieve the root subtree.
void SetRootResource (nsIRDFResource *aResource)
 Set the root resource for the view.
nsIRDFResourceGetRootResource ()
 Retrieve hte root resource for the view.
void InvalidateCachedRow ()
 Invalidate the cached row; e.g., because the view has changed in a way that would corrupt the iterator.

Protected Attributes

Subtree mRoot
 The root subtree.
nsCOMPtr< nsIRDFResourcemRootResource
 The root resource for the view.
iterator mLastRow
 The last row that was asked for by operator[].

Friends

class iterator
class Subtree

Detailed Description

This class maintains the state of the XUL tree builder's rows.

It maps a row number to the nsTemplateMatch object that populates the row.

Definition at line 53 of file nsTreeRows.h.


Class Documentation

struct nsTreeRows::Row

A row in the tree.

Contains the match that the row corresponds to, and a pointer to the row's subtree, if there are any.

Definition at line 88 of file nsTreeRows.h.

Collaboration diagram for nsTreeRows::Row:
Class Members
ContainerFill mContainerFill: 2
ContainerState mContainerState: 2
ContainerType mContainerType: 2
nsTemplateMatch * mMatch
Subtree * mSubtree

Member Enumeration Documentation

anonymous enum
Enumerator:
kMaxDepth 

Definition at line 188 of file nsTreeRows.h.

{ kMaxDepth = 32 };
Enumerator:
eContainerFill_Unknown 
eContainerFill_Empty 
eContainerFill_Nonempty 

Definition at line 75 of file nsTreeRows.h.

Enumerator:
eContainerState_Unknown 
eContainerState_Open 
eContainerState_Closed 

Definition at line 69 of file nsTreeRows.h.

Enumerator:
eContainerType_Unknown 
eContainerType_Noncontainer 
eContainerType_Container 

Definition at line 63 of file nsTreeRows.h.

Enumerator:
eDirection_Forwards 
eDirection_Backwards 

Definition at line 59 of file nsTreeRows.h.


Constructor & Destructor Documentation

nsTreeRows::nsTreeRows ( ) [inline]

Definition at line 324 of file nsTreeRows.h.

Definition at line 325 of file nsTreeRows.h.

{}

Member Function Documentation

Remove all of the rows.

Definition at line 197 of file nsTreeRows.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsTreeRows::Count ( ) const [inline]

Return the total number of rows in the tree view.

Definition at line 420 of file nsTreeRows.h.

{ return mRoot.GetSubtreeSize(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Ensure that a child subtree exists within the specified parent at the specified child index within the parent.

(In other words, create a subtree if one doesn't already exist.)

Definition at line 44 of file nsTreeRows.cpp.

{
    Subtree* subtree = GetSubtreeFor(aParent, aChildIndex);

    if (! subtree) {
        subtree = aParent->mRows[aChildIndex].mSubtree = new Subtree(aParent);
        InvalidateCachedRow();
    }

    return subtree;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Subtree* nsTreeRows::EnsureSubtreeFor ( iterator aIterator) [inline]

Ensure that a child subtree exists at the iterator's position.

Definition at line 339 of file nsTreeRows.h.

                                          {
        return EnsureSubtreeFor(aIterator.GetParent(),
                                aIterator.GetChildIndex()); }

Here is the call graph for this function:

Find the row that contains the match with the specified member resource.

Definition at line 177 of file nsTreeRows.cpp.

{
    // XXX Mmm, scan through the rows one-by-one...
    iterator last = Last();
    iterator iter;

    for (iter = First(); iter != last; ++iter) {
        nsTemplateMatch* match = iter->mMatch;

        Value val;
        match->GetAssignmentFor(aConflictSet, match->mRule->GetMemberVariable(), &val);

        if (VALUE_TO_IRDFRESOURCE(val) == aMember)
            break;
    }

    return iter;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve the first element in the view.

Definition at line 98 of file nsTreeRows.cpp.

{
    iterator result;
    result.Append(&mRoot, 0);
    result.SetRowIndex(0);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve the root subtree.

Definition at line 425 of file nsTreeRows.h.

{ return &mRoot; }

Here is the caller graph for this function:

Retrieve hte root resource for the view.

Definition at line 436 of file nsTreeRows.h.

                                      {
        return mRootResource.get(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Row* nsTreeRows::GetRowsFor ( Subtree aSubtree) [inline]

Raw access to the rows; e.g., for sorting.

Definition at line 410 of file nsTreeRows.h.

{ return aSubtree->mRows; }

Here is the caller graph for this function:

nsTreeRows::Subtree * nsTreeRows::GetSubtreeFor ( const Subtree aParent,
PRInt32  aChildIndex,
PRInt32 aSubtreeSize = nsnull 
)

Get the child subtree for the specified parent at the specified child index.

Optionally return the child subtree's size. Will return `null' if no subtree exists.

Definition at line 58 of file nsTreeRows.cpp.

{
    NS_PRECONDITION(aParent, "no parent");
    NS_PRECONDITION(aChildIndex >= 0, "bad child index");

    Subtree* result = nsnull;

    if (aChildIndex < aParent->mCount)
        result = aParent->mRows[aChildIndex].mSubtree;

    if (aSubtreeSize)
        *aSubtreeSize = result ? result->mSubtreeSize : 0;

    return result;
}

Here is the caller graph for this function:

PRInt32 nsTreeRows::GetSubtreeSizeFor ( const Subtree aParent,
PRInt32  aChildIndex 
) [inline]

Retrieve the size of the subtree within the specified parent.

Definition at line 357 of file nsTreeRows.h.

                                           {
        PRInt32 size;
        GetSubtreeFor(aParent, aChildIndex, &size);
        return size; }

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve the size of the subtree within the specified parent.

Definition at line 367 of file nsTreeRows.h.

                                                 {
        PRInt32 size;
        GetSubtreeFor(aIterator.GetParent(), aIterator.GetChildIndex(), &size);
        return size; }

Here is the call graph for this function:

iterator nsTreeRows::InsertRowAt ( nsTemplateMatch aMatch,
Subtree aSubtree,
PRInt32  aChildIndex 
) [inline]

Insert a new match into the view.

Definition at line 402 of file nsTreeRows.h.

                                                                                 {
        InvalidateCachedRow();
        return aSubtree->InsertRowAt(aMatch, aChildIndex); }

Here is the call graph for this function:

Here is the caller graph for this function:

Invalidate the cached row; e.g., because the view has changed in a way that would corrupt the iterator.

Definition at line 444 of file nsTreeRows.h.

{ mLastRow = iterator(); }

Here is the caller graph for this function:

Retrieve (one past) the last element in the view.

Definition at line 107 of file nsTreeRows.cpp.

{
    iterator result;

    // Build up a path along the rightmost edge of the tree
    Subtree* current = &mRoot;
    PRInt32 count = current->Count();
    do  {
        PRInt32 last = count - 1;
        result.Append(current, last);
        current = count ? GetSubtreeFor(current, last) : nsnull;
    } while (current && ((count = current->Count()) != 0));

    // Now, at the bottom rightmost leaf, advance us one off the end.
    result.mLink[result.mTop].mChildIndex++;

    // Our row index will be the size of the root subree, plus one.
    result.SetRowIndex(mRoot.GetSubtreeSize() + 1);

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsTreeRows::iterator nsTreeRows::operator[] ( PRInt32  aIndex)

Retrieve the ith element in the view.

Definition at line 130 of file nsTreeRows.cpp.

{
    // See if we're just lucky, and end up with something
    // nearby. (This tends to happen a lot due to the way that we get
    // asked for rows n' stuff.)
    PRInt32 last = mLastRow.GetRowIndex();
    if (last != -1) {
        if (aRow == last)
            return mLastRow;
        else if (last + 1 == aRow)
            return ++mLastRow;
        else if (last - 1 == aRow)
            return --mLastRow;
    }

    // Nope. Construct a path to the specified index. This is a little
    // bit better than O(n), because we can skip over subtrees. (So it
    // ends up being approximately linear in the subtree size, instead
    // of the entire view size. But, most of the time, big views are
    // flat. Oh well.)
    iterator result;
    Subtree* current = &mRoot;

    PRInt32 index = 0;
    result.SetRowIndex(aRow);

    do {
        PRInt32 subtreeSize;
        Subtree* subtree = GetSubtreeFor(current, index, &subtreeSize);

        if (subtreeSize >= aRow) {
            result.Append(current, index);
            current = subtree;
            index = 0;
            --aRow;
        }
        else {
            ++index;
            aRow -= subtreeSize + 1;
        }
    } while (aRow >= 0);

    mLastRow = result;
    return result;
}

Here is the call graph for this function:

PRInt32 nsTreeRows::RemoveRowAt ( iterator aIterator) [inline]

Remove the specified row from the view.

Definition at line 391 of file nsTreeRows.h.

                                     {
        iterator temp = aIterator--;
        Subtree* parent = temp.GetParent();
        parent->RemoveRowAt(temp.GetChildIndex());
        InvalidateCachedRow();
        return parent->Count(); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRows::RemoveSubtreeFor ( Subtree aParent,
PRInt32  aChildIndex 
)

Remove the specified subtree for a row, leaving the row itself intact.

Definition at line 77 of file nsTreeRows.cpp.

{
    NS_PRECONDITION(aParent, "no parent");
    NS_PRECONDITION(aChildIndex >= 0 && aChildIndex < aParent->mCount, "bad child index");

    Row& row = aParent->mRows[aChildIndex];

    if (row.mSubtree) {
        PRInt32 subtreeSize = row.mSubtree->GetSubtreeSize();

        delete row.mSubtree;
        row.mSubtree = nsnull;

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

    InvalidateCachedRow();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRows::RemoveSubtreeFor ( iterator aIterator) [inline]

Remove the specified subtree for a row, leaving the row itself intact.

Definition at line 384 of file nsTreeRows.h.

                                          {
        RemoveSubtreeFor(aIterator.GetParent(), aIterator.GetChildIndex()); }

Here is the call graph for this function:

void nsTreeRows::SetRootResource ( nsIRDFResource aResource) [inline]

Set the root resource for the view.

Definition at line 430 of file nsTreeRows.h.

                                                    {
        mRootResource = aResource; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class iterator [friend]

Definition at line 56 of file nsTreeRows.h.

friend class Subtree [friend]

Definition at line 186 of file nsTreeRows.h.


Member Data Documentation

The last row that was asked for by operator[].

By remembering this, we can usually avoid the O(n) search through the row array to find the row at the specified index.

Definition at line 462 of file nsTreeRows.h.

The root subtree.

Definition at line 450 of file nsTreeRows.h.

The root resource for the view.

Definition at line 455 of file nsTreeRows.h.


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