Main Page Compound List File List Compound Members
tmVector Class Reference
#include <tmVector.h>
List of all members.
|
Public Member Functions |
| tmVector () |
virtual | ~tmVector () |
nsresult | Init () |
nsresult | Add (void *aElement) |
nsresult | Remove (void *aElement) |
nsresult | RemoveAt (PRUint32 aIndex) |
void | Clear () |
void * | ElementAt (PRUint32 aIndex) |
void * | FirstElement () |
void * | LastElement () |
PRUint32 | Size () |
PRUint32 | Capacity () |
PRBool | Contains (void *aElement) |
void | Iterate () |
void * | Next () |
PRUint32 | GetIterator () |
Protected Member Functions |
nsresult | Grow () |
nsresult | Shrink () |
Protected Attributes |
PRUint32 | mIterator |
PRUint32 | mLastIterator |
PRUint32 | mIndex |
PRUint32 | mNext |
PRUint32 | mSize |
PRUint32 | mCapacity |
PRUint32 | mGrowthIncrement |
void ** | mElements |
Detailed Description
A simple, clear, self-growing, collection of objects. typed independant basically a growing array. Useful in situations where you need an indexed collection but do not know the size in advance and need the ability for increase and decrease in size. Not optimized for anything in particular, or any size in particular.
Is able to guarantee the index of an item will not change due to removals of a lower indexed item. The growing, and shrinking all happens to the end of the collection
Does not backfill, adds to the end. At some point this should be changed to make best use of space.
Constructor & Destructor Documentation
tmVector::tmVector |
( |
|
) |
[inline] |
|
|
Set some sane default values to set up the internal storage. Init() must be called after construction of the object to allcate the backing store. |
virtual tmVector::~tmVector |
( |
|
) |
[virtual] |
|
|
Reclaim the memory allocated in the Init() method. |
Member Function Documentation
nsresult tmVector::Add |
( |
void * |
aElement |
) |
|
|
|
- Returns:
- NS_ERROR_INVALID_ARG if the element passed in is null
NS_ERROR_OUT_OF_MEMORY if the collection needed to grow and the allocation of a new backing store failed.
NS_ERROR_GENERATE_SUCCESS(index) if the add was successful. The calling method can get the index of the element added by using the macro NS_ERROR_GET_CODE() on the return value. But for simple success test use NS_SUCCEEDED() on the return value.
|
PRUint32 tmVector::Capacity |
( |
|
) |
[inline] |
|
|
- Returns:
- the number of elements that can be held in the collection without needing to Grow() the backing store.
|
|
Does not call delete on the elements since we have no idea how to reclaim the memory. Sets all array slots to nsnull. |
PRBool tmVector::Contains |
( |
void * |
aElement |
) |
|
|
|
This does a simple equality comparison on the pointer values
- Returns:
- PR_TRUE if the pointer arg is contained in the collection
PR_FALSE if the pointer arg is not contained in the collection
|
void* tmVector::ElementAt |
( |
PRUint32 |
aIndex |
) |
|
|
|
- Returns:
- nsnull if the index is out of bounds OR if the slot indexed contains no element (nsnull)
the element at the index given (could still be nsnull)
|
void* tmVector::FirstElement |
( |
|
) |
|
|
|
This isn't neccessarily the element at index 0.
- Returns:
- the first non-null element in the collection
nsnull if the collection is empty
|
PRUint32 tmVector::GetIterator |
( |
|
) |
[inline] |
|
|
- Returns:
- the index of the element returned by the last Next() call
0 if called directly after an Iterate() call
|
nsresult tmVector::Init |
( |
|
) |
|
|
|
Allocates the storage back-end
- Returns:
- NS_OK if allocation succeeded
NS_ERROR_OUT_OF_MEMORY if the allocation failed
|
void tmVector::Iterate |
( |
|
) |
|
|
|
The iteration works in the following fashion. An initial call is made to Iterate(). This prepares the internal state of the vector to walk through all the elements. Then a call is made to Next() to get each element of the vector, initially it would hand back the first. Each successive call to Next() hands the next element in the vector. If removal or caching of the index for the element last returned by Next() is needed a call to GetIterator() is made which hands back the index of the last element to be returned by a call to Next().
The following code example demonstrates the cycling through all of the elements and their subsequent removal from the vector: tmVector aVector; aVector.Init(); ... populate the vector ...
aVector.Iterate(); void* anElement = nsnull; while (anElement = aVector.Next() != nsnull) { aVector.RemoveAt(aVector.GetIterator()); } |
void* tmVector::LastElement |
( |
|
) |
|
|
|
- Returns:
- the last non-null element in the collection nsnull if the collection is empty
|
|
Used during iteration through the collection
- Returns:
- the next non-null element in the collection
nsnull if there are no more elements in the collection
|
nsresult tmVector::Remove |
( |
void * |
aElement |
) |
|
|
|
This does not collapse the collection, it leaves holes. Note, it also doesn't delete the element, it merely removes it from the collection
- Returns:
- NS_OK if the item was removed successfully
NS_ERROR_INVALID_ARG if the index is out of bounds of the array
|
nsresult tmVector::RemoveAt |
( |
PRUint32 |
aIndex |
) |
|
|
|
This does not collapse the collection, it leaves holes.Note, it also doesn't delete the element, it merely removes it from the collection
- Returns:
- NS_OK if the item was removed successfully
NS_ERROR_INVALID_ARG if the index is out of bounds of the array
|
PRUint32 tmVector::Size |
( |
|
) |
[inline] |
|
|
- Returns:
- the number of elements stored
|
The documentation for this class was generated from the following file:
Generated on Mon Feb 24 10:22:51 2003 for transaction manager by
1.3-rc3