Back to index

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

An iterator that can be used to traverse the tree view. More...

#include <nsTreeRows.h>

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

List of all members.

Public Member Functions

 iterator ()
 iterator (const iterator &aIterator)
iteratoroperator= (const iterator &aIterator)
PRBool operator== (const iterator &aIterator) const
PRBool operator!= (const iterator &aIterator) const
const Rowoperator* () const
Rowoperator* ()
const Rowoperator-> () const
Rowoperator-> ()
iteratoroperator++ ()
iterator operator++ (int)
iteratoroperator-- ()
iterator operator-- (int)
SubtreeGetParent ()
 Return the current parent link.
const SubtreeGetParent () const
PRInt32 GetChildIndex () const
 Return the current child index.
PRInt32 GetDepth () const
 Return the depth of the path the iterator is maintaining into the tree.
PRInt32 GetRowIndex () const
 Return the current row index of the iterator.
iteratorPop ()
 Pop the iterator up a level.

Protected Member Functions

void Next ()
void Prev ()
void Append (Subtree *aParent, PRInt32 aChildIndex)
 Used by operator[]() to initialize an iterator.
void Push (Subtree *aParent, PRInt32 aChildIndex)
 Used by InsertRowAt() to initialize an iterator.
void SetRowIndex (PRInt32 aRowIndex)
 Used by operator[]() and InsertRowAt() to initialize an iterator.

Protected Attributes

PRInt32 mTop
PRInt32 mRowIndex
Link mLink [kMaxDepth]

Friends

class Subtree
class nsTreeRows

Detailed Description

An iterator that can be used to traverse the tree view.

Definition at line 222 of file nsTreeRows.h.


Constructor & Destructor Documentation

Definition at line 250 of file nsTreeRows.h.

: mTop(-1), mRowIndex(-1) {}

Definition at line 326 of file nsTreeRows.cpp.

    : mTop(aIterator.mTop),
      mRowIndex(aIterator.mRowIndex)
{
    for (PRInt32 i = mTop; i >= 0; --i)
        mLink[i] = aIterator.mLink[i];
}

Member Function Documentation

void nsTreeRows::iterator::Append ( Subtree aParent,
PRInt32  aChildIndex 
) [protected]

Used by operator[]() to initialize an iterator.

Definition at line 345 of file nsTreeRows.cpp.

{
    if (mTop < kMaxDepth - 1) {
        ++mTop;
        mLink[mTop].mParent     = aParent;
        mLink[mTop].mChildIndex = aChildIndex;
    }
    else
        NS_ERROR("overflow");
}

Here is the caller graph for this function:

Return the current child index.

Definition at line 283 of file nsTreeRows.h.

                                      {
            return mLink[mTop].GetChildIndex(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Return the depth of the path the iterator is maintaining into the tree.

Definition at line 290 of file nsTreeRows.h.

{ return mTop + 1; }

Here is the caller graph for this function:

Return the current parent link.

Definition at line 274 of file nsTreeRows.h.

                             {
            return mLink[mTop].GetParent(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 277 of file nsTreeRows.h.

                                         {
            return mLink[mTop].GetParent(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Return the current row index of the iterator.

Definition at line 295 of file nsTreeRows.h.

{ return mRowIndex; }

Here is the caller graph for this function:

Definition at line 384 of file nsTreeRows.cpp.

{
    NS_PRECONDITION(mTop >= 0, "cannot increment an uninitialized iterator");

    // Increment the absolute row index
    ++mRowIndex;

    Link& top = mLink[mTop];

    // Is there a child subtree? If so, descend into the child
    // subtree.
    Subtree* subtree = top.GetRow().mSubtree;

    if (subtree && subtree->Count()) {
        Append(subtree, 0);
        return;
    }

    // Have we exhausted the current subtree?
    if (top.mChildIndex >= top.mParent->Count() - 1) {
        // Yep. See if we've just iterated path the last element in
        // the tree, period. Walk back up the stack, looking for any
        // unfinished subtrees.
        PRInt32 unfinished;
        for (unfinished = mTop - 1; unfinished >= 0; --unfinished) {
            const Link& link = mLink[unfinished];
            if (link.mChildIndex < link.mParent->Count() - 1)
                break;
        }

        // If there are no unfinished subtrees in the stack, then this
        // iterator is exhausted. Leave it in the same state that
        // Last() does.
        if (unfinished < 0) {
            top.mChildIndex++;
            return;
        }

        // Otherwise, we ran off the end of one of the inner
        // subtrees. Pop up to the next unfinished level in the stack.
        mTop = unfinished;
    }

    // Advance to the next child in this subtree
    ++(mLink[mTop].mChildIndex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsTreeRows::iterator::operator!= ( const iterator aIterator) const [inline]

Definition at line 257 of file nsTreeRows.h.

                                                           {
            return !aIterator.operator==(*this); }
const Row& nsTreeRows::iterator::operator* ( ) const [inline]

Definition at line 260 of file nsTreeRows.h.

{ return mLink[mTop].GetRow(); }

Here is the call graph for this function:

Row& nsTreeRows::iterator::operator* ( ) [inline]

Definition at line 261 of file nsTreeRows.h.

{ return mLink[mTop].GetRow(); }

Here is the call graph for this function:

iterator& nsTreeRows::iterator::operator++ ( ) [inline]

Definition at line 266 of file nsTreeRows.h.

{ Next(); return *this; }

Here is the call graph for this function:

iterator nsTreeRows::iterator::operator++ ( int  ) [inline]

Definition at line 267 of file nsTreeRows.h.

{ iterator temp(*this); Next(); return temp; }

Here is the call graph for this function:

iterator& nsTreeRows::iterator::operator-- ( ) [inline]

Definition at line 268 of file nsTreeRows.h.

{ Prev(); return *this; }

Here is the call graph for this function:

iterator nsTreeRows::iterator::operator-- ( int  ) [inline]

Definition at line 269 of file nsTreeRows.h.

{ iterator temp(*this); Prev(); return temp; }

Here is the call graph for this function:

const Row* nsTreeRows::iterator::operator-> ( ) const [inline]

Definition at line 263 of file nsTreeRows.h.

{ return &(mLink[mTop].GetRow()); }

Here is the call graph for this function:

Row* nsTreeRows::iterator::operator-> ( ) [inline]

Definition at line 264 of file nsTreeRows.h.

{ return &(mLink[mTop].GetRow()); }

Here is the call graph for this function:

nsTreeRows::iterator & nsTreeRows::iterator::operator= ( const iterator aIterator)

Definition at line 335 of file nsTreeRows.cpp.

{
    mTop = aIterator.mTop;
    mRowIndex = aIterator.mRowIndex;
    for (PRInt32 i = mTop; i >= 0; --i)
        mLink[i] = aIterator.mLink[i];
    return *this;
}
PRBool nsTreeRows::iterator::operator== ( const iterator aIterator) const

Definition at line 372 of file nsTreeRows.cpp.

{
    if (mTop != aIterator.mTop)
        return PR_FALSE;

    if (mTop == -1)
        return PR_TRUE;

    return PRBool(mLink[mTop] == aIterator.mLink[mTop]);
}

Pop the iterator up a level.

Definition at line 300 of file nsTreeRows.h.

{ --mTop; return *this; }

Here is the caller graph for this function:

Definition at line 432 of file nsTreeRows.cpp.

{
    NS_PRECONDITION(mTop >= 0, "cannot increment an uninitialized iterator");

    // Decrement the absolute row index
    --mRowIndex;

    // Move to the previous child in this subtree
    --(mLink[mTop].mChildIndex);

    // Have we exhausted the current subtree?
    if (mLink[mTop].mChildIndex < 0) {
        // Yep. See if we've just iterated back to the first element
        // in the tree, period. Walk back up the stack, looking for
        // any unfinished subtrees.
        PRInt32 unfinished;
        for (unfinished = mTop - 1; unfinished >= 0; --unfinished) {
            const Link& link = mLink[unfinished];
            if (link.mChildIndex >= 0)
                break;
        }

        // If there are no unfinished subtrees in the stack, then this
        // iterator is exhausted. Leave it in the same state that
        // First() does.
        if (unfinished < 0)
            return;

        // Otherwise, we ran off the end of one of the inner
        // subtrees. Pop up to the next unfinished level in the stack.
        mTop = unfinished;
        return;
    }

    // Is there a child subtree immediately prior to our current
    // position? If so, descend into it, grovelling down to the
    // deepest, rightmost left edge.
    Subtree* parent = mLink[mTop].GetParent();
    PRInt32 index = mLink[mTop].GetChildIndex();

    Subtree* subtree = (*parent)[index].mSubtree;

    if (subtree && subtree->Count()) {
        do {
            index = subtree->Count() - 1;
            Append(subtree, index);

            parent = subtree;
            subtree = (*parent)[index].mSubtree;
        } while (subtree && subtree->Count());
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTreeRows::iterator::Push ( Subtree aParent,
PRInt32  aChildIndex 
) [protected]

Used by InsertRowAt() to initialize an iterator.

Definition at line 357 of file nsTreeRows.cpp.

{
    if (mTop < kMaxDepth - 1) {
        for (PRInt32 i = mTop; i >= 0; --i)
            mLink[i + 1] = mLink[i];

        mLink[0].mParent     = aParent;
        mLink[0].mChildIndex = aChildIndex;
        ++mTop;
    }
    else
        NS_ERROR("overflow");
}

Here is the caller graph for this function:

void nsTreeRows::iterator::SetRowIndex ( PRInt32  aRowIndex) [inline, protected]

Used by operator[]() and InsertRowAt() to initialize an iterator.

Definition at line 247 of file nsTreeRows.h.

{ mRowIndex = aRowIndex; }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsTreeRows [friend]

Definition at line 232 of file nsTreeRows.h.

friend class Subtree [friend]

Definition at line 231 of file nsTreeRows.h.


Member Data Documentation

Definition at line 226 of file nsTreeRows.h.

Definition at line 225 of file nsTreeRows.h.

Definition at line 224 of file nsTreeRows.h.


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