Back to index

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

Represents an ordered list of Object pointers. More...

#include <txList.h>

Collaboration diagram for txList:
Collaboration graph
[legend]

List of all members.

Classes

struct  ListItem

Public Member Functions

 txList ()
 Creates an empty txList.
virtual ~txList ()
 txList destructor, object references will not be deleted.
voidget (int index)
 Returns the object located at the given index.
PRInt32 getLength ()
 Returns the number of items in this txList.
nsresult insert (int index, void *objPtr)
 Adds the given Object to the specified position in the list.
nsresult add (void *objPtr)
 Adds the given Object to the list.
voidremove (void *objPtr)
 Removes the given Object pointer from the list.
void clear ()

Protected Member Functions

ListItemgetFirstItem ()
ListItemgetLastItem ()
ListItemremove (ListItem *sItem)
 Removes the given ListItem pointer from the list.

Private Member Functions

 txList (const txList &aOther)
nsresult insertAfter (void *objPtr, ListItem *sItem)
 Inserts the given Object pointer as the item just after refItem.
nsresult insertBefore (void *objPtr, ListItem *sItem)
 Inserts the given Object pointer as the item just before refItem.

Private Attributes

ListItemfirstItem
ListItemlastItem
PRInt32 itemCount

Friends

class txListIterator

Detailed Description

Represents an ordered list of Object pointers.

Modeled after a Java 2 List.

Definition at line 49 of file txList.h.


Class Documentation

struct txList::ListItem

Definition at line 100 of file txList.h.

Collaboration diagram for txList::ListItem:
Class Members
ListItem * nextItem
void * objPtr
ListItem * prevItem

Constructor & Destructor Documentation

Creates an empty txList.

Default constructor for a txList;.

Definition at line 49 of file txList.cpp.

               {
   firstItem  = 0;
   lastItem   = 0;
   itemCount  = 0;
} //-- txList;
txList::~txList ( ) [virtual]

txList destructor, object references will not be deleted.

txList destructor, cleans up ListItems, but will not delete the Object references

Definition at line 59 of file txList.cpp.

                {
    clear();
} //-- ~txList

Here is the call graph for this function:

txList::txList ( const txList aOther) [private]

Member Function Documentation

nsresult txList::add ( void objPtr)

Adds the given Object to the list.

Definition at line 75 of file txList.cpp.

{
    return insertBefore(objPtr, 0);
} //-- add

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file txList.cpp.

{
    ListItem* item = firstItem;
    while (item) {
        ListItem* tItem = item;
        item = item->nextItem;
        delete tItem;
    }
    firstItem  = 0;
    lastItem   = 0;
    itemCount  = 0;
}

Here is the caller graph for this function:

void * txList::get ( int  index)

Returns the object located at the given index.

This may be slow or fast depending on the implementation.

Returns:
the object located at the given index

This may be slow or fast depending on the implementation. Note: Currently this list is implemented via a linked list, so this method will be slow (unless the list only has a couple members) as it will need traverse the links each time

Returns:
the object located at the given index

Definition at line 89 of file txList.cpp.

                           {

    if (index < 0 || index >= itemCount)
        return 0;

    int c = 0;
    ListItem* item = firstItem;
    while ((c != index) && item) {
        item = item->nextItem;
        ++c;
    }

    if (item)
        return item->objPtr;
    return 0;
} //-- get(int)

Here is the caller graph for this function:

Definition at line 106 of file txList.cpp.

                                     {
    return firstItem;
} //-- getFirstItem

Definition at line 110 of file txList.cpp.

                                    {
    return lastItem;
} //-- getLastItem

Returns the number of items in this txList.

Definition at line 117 of file txList.cpp.

                        {
   return itemCount;
} //-- getLength

Here is the caller graph for this function:

nsresult txList::insert ( int  index,
void objPtr 
)

Adds the given Object to the specified position in the list.

Definition at line 63 of file txList.cpp.

{
    if (index >= itemCount) {
        return insertBefore(objPtr, 0);
    }
    // add inside the list
    ListItem* nextItem = firstItem;
    for (int i = 0; i < index; i++)
        nextItem = nextItem->nextItem;
    return insertBefore(objPtr, nextItem);
} //-- insert

Here is the call graph for this function:

nsresult txList::insertAfter ( void objPtr,
ListItem refItem 
) [private]

Inserts the given Object pointer as the item just after refItem.

If refItem is a null pointer the Object will be inserted at the beginning of the txList (ie, insert after nothing). This method assumes refItem is a member of this list, and since this is a private method, I feel that's a valid assumption

Definition at line 129 of file txList.cpp.

{
    //-- if refItem == null insert at front
    if (!refItem)
        return insertBefore(objPtr, firstItem);
    return insertBefore(objPtr, refItem->nextItem);
} //-- insertAfter

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txList::insertBefore ( void objPtr,
ListItem refItem 
) [private]

Inserts the given Object pointer as the item just before refItem.

If refItem is a null pointer the Object will be inserted at the end of the txList (ie, insert before nothing). This method assumes refItem is a member of this list, and since this is a private method, I feel that's a valid assumption

Definition at line 144 of file txList.cpp.

{
    ListItem* item = new ListItem;
    NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);

    item->objPtr = objPtr;
    item->nextItem = 0;
    item->prevItem = 0;

    //-- if refItem == null insert at end
    if (!refItem) {
        //-- add to back of list
        if (lastItem) {
            lastItem->nextItem = item;
            item->prevItem = lastItem;
        }
        lastItem = item;
        if (!firstItem)
            firstItem = item;
    }
    else {
        //-- insert before given item
        item->nextItem = refItem;
        item->prevItem = refItem->prevItem;
        refItem->prevItem = item;

        if (item->prevItem)
            item->prevItem->nextItem = item;
        else
            firstItem = item;
    }

    // increase the item count
    ++itemCount;
    
    return NS_OK;
} //-- insertBefore

Here is the caller graph for this function:

void * txList::remove ( void objPtr)

Removes the given Object pointer from the list.

Definition at line 182 of file txList.cpp.

                                 {
   ListItem* item = firstItem;
   while (item) {
      if (item->objPtr == objPtr) {
         remove(item);
         delete item;
         return objPtr;
      }
      item = item->nextItem;
   }
   // not in list
   return 0;
} //-- remove

Here is the caller graph for this function:

txList::ListItem * txList::remove ( ListItem sItem) [protected]

Removes the given ListItem pointer from the list.

Definition at line 196 of file txList.cpp.

                                             {

    if (!item)
        return item;

    //-- adjust the previous item's next pointer
    if (item->prevItem) {
        item->prevItem->nextItem = item->nextItem;
    }
    //-- adjust the next item's previous pointer
    if (item->nextItem) {
        item->nextItem->prevItem = item->prevItem;
    }

    //-- adjust first and last items
    if (item == firstItem)
        firstItem = item->nextItem;
    if (item == lastItem)
        lastItem = item->prevItem;

    //-- decrease Item count
    --itemCount;
    return item;
} //-- remove

Friends And Related Function Documentation

friend class txListIterator [friend]

Definition at line 51 of file txList.h.


Member Data Documentation

Definition at line 117 of file txList.h.

Definition at line 119 of file txList.h.

Definition at line 118 of file txList.h.


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