tsc_List

tsc_List is a class that contains a list of tsc_Object* items, in the manner of a .NET object<List> type.  The list capacity expands dynamically to accomodate added and inserted items.  Be aware that ownership of the objects (in memory) is something to be aware of; the list can be constructed to either ignore ownership or assume responsibility for deletion.

A NULL object pointer constitutes a valid item in a tsc_List.

Constructors

tsc_List (bool listTakesOwnership = false);
Constructs an empty list of objects, with no initial allocation.  Setting the listTakesOwnership argument to true specifies the list is to delete each object when it is removed or the list is destroyed.

The list will be allocated and expand in capacity as items are added.

tsc_List (int capacity, bool listTakesOwnership = false);
Constructs an empty list of objects, preallocated in size to the given capacity.  Setting the listTakesOwnership argument to true specifies the list is to delete each object when it is removed or the list is destroyed.

The list will expand in capacity as items are added.   

tsc_List (const tsc_List& objects, int capacity = 0);
Constructs a list of object pointers, preallocated in size to at least the specified capacity, and then adds the items from the given list.  The capacity will expand if necessary as items are added.

listTakesOwnership, as used in the other constructors, will always be set false; two lists owning the same objects is not permitted.

Destructor

virtual ~tsc_List();

Destruction of the list.  If the list was constructed with listTakesOwnership, then destruction will also delete all objects in the list.

Overloaded operators

tsc_List& operator= (const tsc_List& objects);
Copies the object pointers from the supplied list into this list.  listTakesOwnership will be set to false.

tsc_List operator+ (const tsc_Object* object) const;
Copies the list and adds the given object to the end.  object may be NULL. listTakesOwnership in the returned list is set to false.  Note that the objects copied from the source list remain owned by that list, and the added object is not owned by any list.

tsc_List  operator+ (const tsc_List& objects) const;
Copies the list and adds the given objects to the end. listTakesOwnership in the returned list is set to false; the objects remain owned by the two originating lists.

tsc_List& operator+= (const tsc_Object* object);
Adds an object to the end of the list.  object may be NULL.  If the list was created with listTakesOwnership set true, then the object becomes owned by the list and will be deleted when removed from the list or when the list is destroyed.

tsc_List& operator+= (const tsc_List& objects);
Appends the objects from another list. The listTakesOwnership argument must be false either in this list or in the other list, to prevent the appended objects belonging to two lists at once.

const tsc_Object* operator[] (int index) const;
tsc_Object*       operator[] (int index);
Retrieves a pointer to the object at the specified index.  Ownership of the object remains unchanged.

bool operator== (const tsc_List&  objects);
Compares the list for equality; that is, they contain the same objects.  Object equality occurs only if the two pointers are equal (including both being NULL).

bool operator!= (const tsc_List&  objects);
Returns false if the given list is equal (see == operator).

Methods

void Append (const tsc_Object* object);
Adds the object to the end of the list.  Ownership of the object is determined by the list's listTakesOwnership property.

void Insert (int index, const tsc_Object* object);
Inserts an object into the list at the specified index.  Ownership of the object is determined by the list's listTakesOwnership property.

void Remove (int index);
Removes the object at the specified index from the list.  If the list was constructed with listTakesOwnership = true, then the object is also deleted at this time.

void Remove (const tsc_Object* object);
Removes the first found instance of the specified object (including NULL) from the list.  A match is determined by pointer equality, and no error indication is given if a match is not found.  If the list was constructed with listTakesOwnership = true, the object is also deleted.

int Count () const;
Returns a count of the objects in the list.  This is unrelated to the list's capacity.

void Clear ();
Removes all objects from the list.  If constructed with listTakesOwnership = true, the objects are also deleted.

bool IsEmpty();
Returns true if the list contains no items.

int IndexOf (const tsc_Object* object) const;
Finds an object in the list by searching for its pointer and returns the index, or -1 if the object was not found.

bool Contains (const tsc_Object* object) const;
Returns true if the object pointer exists in the list.

bool ListTakesOwnership () const;
Returns true if the list takes ownership of all objects contained in it.  Ownership means an object is deleted when it is removed from the list or the list is destroyed.  This value may be set in the constructor, and is reset by some copy operations.