Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ContainingList Class Template Reference

#include <LinkedList.h>

List of all members.


Detailed Description

template<class ITEMTYPE>
class toolbox::ContainingList< ITEMTYPE >

A ContainingList contains a variable number of items, that are linked like a chain.

This makes enumeration, enqueueing and dequeueing fast, but looking up items by their position slow.

Note:
ContainingLists contain ContainingListItems, that are a little more performant, but may not be added twice to the same list, nor be added to two different lists. If you require this, use the PointeredList and PointeredListItem. To use ContainingLists, derive at least from the ContainingListItem, and put your data in there.
See also:
See collections.txt for an overview of the available collection classes.

PointeredList

PointeredListItem

Author:
Thomas Jacob

Definition at line 33 of file LinkedList.h.

Public Member Functions

void Append (ITEMTYPE *Item)
 Appends an item to the list.

virtual int Compare (const ITEMTYPE *Item1, const ITEMTYPE *Item2) const
 Compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.

 ContainingList ()
 Creates a new list.

bool Delete (ITEMTYPE *Item, int(*compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2))
 Deletes an item that is equal to a given item from the list.

bool Delete (ITEMTYPE *Item)
 Deletes an item that is equal to a given item from the list.

bool Delete (long nr)
 Deletes an given item from the list.

void DeleteAll ()
 Deletes all items from the list.

void DeleteDirectly (ITEMTYPE *Item)
 Deletes a given item from the list without looking it up.

bool DeleteFirst ()
 Deletes the first item from the list.

bool DeleteLast ()
 Deletes the last item from the list.

ITEMTYPE * Get (const ITEMTYPE *SearchItem, int(*compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2)) const
 Returns an item that is equal to a given item.

ITEMTYPE * Get (const ITEMTYPE *SearchItem) const
 Returns an item that is equal to a given item.

ITEMTYPE * Get (long nr) const
 Returns the item at a given position.

long GetCount () const
 Returns the number of items in the list.

ITEMTYPE * GetFirst () const
 Returns the first item of the list.

ITEMTYPE * GetLast () const
 Returns the last item of the list.

void Insert (ITEMTYPE *Item, long nr)
 Inserts an item before a given position.

bool IsEmpty () const
 Returns, if there are no items in the list.

void Prepend (ITEMTYPE *Item)
 Prepends an item to the list.

void Reverse ()
 Turns around the order of all items in the list.

void Sort (int(*compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2))
 Sorts the items in the list according to a given comparison function.

void Sort ()
 Sorts the items in the list according to the Compare method.

ITEMTYPE * Unlink (ITEMTYPE *Item, int(*compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2))
 Removes an item that is equal to a given item from the list.

ITEMTYPE * Unlink (ITEMTYPE *Item)
 Removes an item that is equal to a given item from the list.

ITEMTYPE * Unlink (long nr)
 Removes an item at a given position.

void UnlinkAll ()
 Removes all items from the list without freeing them or returning them.

ITEMTYPE * UnlinkDirectly (ITEMTYPE *Item)
 Removes a given item from the list without looking it up.

ITEMTYPE * UnlinkFirst ()
 Removes the first item of the list.

ITEMTYPE * UnlinkLast ()
 Removes the last item of the list.

virtual ~ContainingList ()
 Destroys the list.


Private Attributes

long Count
 The number of items in the list.

ITEMTYPE * First
 The first list item.

ITEMTYPE * Last
 The next list item.


Constructor & Destructor Documentation

ContainingList  ) 
 

Creates a new list.

virtual ~ContainingList  )  [virtual]
 

Destroys the list.

When deleting the list, all contained items are also freed.


Member Function Documentation

void Append ITEMTYPE *  Item  ) 
 

Appends an item to the list.

Parameters:
Item The item to be appended.

virtual int Compare const ITEMTYPE *  Item1,
const ITEMTYPE *  Item2
const [virtual]
 

Compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.

This method is used for comparison method like Delete and Get, if you specify an item to look up. Override this method to provide your own comparison.

Parameters:
Item1 The first item to be compared.
Item2 The second item to be compared.
Returns:
-1, 0 or 1, if Item1<Item2, Item1==Item2 or Item1>Item2.

bool Delete ITEMTYPE *  Item,
int(*  compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2)
 

Deletes an item that is equal to a given item from the list.

The item is searched, removed from the list and freed.

Parameters:
Item The item to be deleted.
compare A functions that compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.
Returns:
If the deletion was successful.

bool Delete ITEMTYPE *  Item  ) 
 

Deletes an item that is equal to a given item from the list.

The item is searched using the class's compare method, so override it to set your own comparison. After that, the item is removed from the list and freed.

Parameters:
Item The item to be deleted.
Returns:
If the deletion was successful.

bool Delete long  nr  ) 
 

Deletes an given item from the list.

The item is removed from the list and freed.

Parameters:
nr The position of the item.
Returns:
If the deletion was successful.

void DeleteAll  ) 
 

Deletes all items from the list.

All items are removed from the list and freed.

void DeleteDirectly ITEMTYPE *  Item  )  [inline]
 

Deletes a given item from the list without looking it up.

Use this method to increase performance, but only, if you are sure that the item is in the list. If not, that list will remain inconsistent. The item is removed from the list an freed.

Parameters:
Item The item to be deleted.

bool DeleteFirst  ) 
 

Deletes the first item from the list.

The item is removed from the list and freed.

Returns:
If the deletion was successful.

bool DeleteLast  ) 
 

Deletes the last item from the list.

The item is removed from the list and freed.

Returns:
If the deletion was successful.

ITEMTYPE* Get const ITEMTYPE *  SearchItem,
int(*  compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2)
const
 

Returns an item that is equal to a given item.

Parameters:
SearchItem The item to be compared to.
compare A functions that compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.
Returns:
The found item or NULL, if the item wasn't found.

ITEMTYPE* Get const ITEMTYPE *  SearchItem  )  const [inline]
 

Returns an item that is equal to a given item.

The item is searched using the class's compare method, so override it to set your own comparison. After that, the item is removed from the list and freed.

Parameters:
SearchItem The item to be compared to.
Returns:
The found item or NULL, if the item wasn't found.

ITEMTYPE* Get long  nr  )  const
 

Returns the item at a given position.

Parameters:
nr The position of the item.
Returns:
The item at the position.

long GetCount  )  const [inline]
 

Returns the number of items in the list.

Returns:
The number of items in the list.

ITEMTYPE* GetFirst  )  const [inline]
 

Returns the first item of the list.

Returns:
The first item of the list.

ITEMTYPE* GetLast  )  const [inline]
 

Returns the last item of the list.

Returns:
The last item of the list.

void Insert ITEMTYPE *  Item,
long  nr
 

Inserts an item before a given position.

Parameters:
Item The item to be inserted.
nr The position to insert before.

bool IsEmpty  )  const [inline]
 

Returns, if there are no items in the list.

void Prepend ITEMTYPE *  Item  )  [inline]
 

Prepends an item to the list.

Parameters:
Item The item to be prepended.

void Reverse  ) 
 

Turns around the order of all items in the list.

The whole list has the reverse order afterwards, but is not harmed at all in any other way. All items remain the same.

void Sort int(*  compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2)  ) 
 

Sorts the items in the list according to a given comparison function.

The whole list has a sorted order afterwards, but is not harmed at all in any other way. All items remain the same.

Parameters:
compare A functions that compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.

void Sort  )  [inline]
 

Sorts the items in the list according to the Compare method.

The whole list has a sorted order afterwards, but is not harmed at all in any other way. All items remain the same.

ITEMTYPE* Unlink ITEMTYPE *  Item,
int(*  compare)(const ITEMTYPE *Item1, const ITEMTYPE *Item2)
 

Removes an item that is equal to a given item from the list.

The item is not freed, but returned.

Parameters:
Item The item to be compared.
compare A functions that compares two items and returns -1, if the first is less than the second, 0, if both items are equal and 1, if the first is more than the second.
Returns:
The item.

ITEMTYPE* Unlink ITEMTYPE *  Item  ) 
 

Removes an item that is equal to a given item from the list.

The item is searched using the class's compare method, so override it to set your own comparison. Afterwards, the item is not freed, but returned.

Parameters:
Item The item to be compared.
Returns:
The item.

ITEMTYPE* Unlink long  nr  ) 
 

Removes an item at a given position.

The item is not freed, but returned.

Parameters:
nr The position of the item.
Returns:
The item.

void UnlinkAll  ) 
 

Removes all items from the list without freeing them or returning them.

Warning:
No item is freed, so you have to have a pointer to the objects, or the memory is lost.

ITEMTYPE* UnlinkDirectly ITEMTYPE *  Item  ) 
 

Removes a given item from the list without looking it up.

Use this method to increase performance, but only, if you are sure that the item is in the list. If not, that list will become inconsistent. Afterwards, the item is not freed, but returned.

Parameters:
nr The position of the item.
Returns:
The item.

ITEMTYPE* UnlinkFirst  )  [inline]
 

Removes the first item of the list.

The item is not freed, but returned.

Returns:
The item.

ITEMTYPE* UnlinkLast  ) 
 

Removes the last item of the list.

The item is not freed, but returned.

Returns:
The item.


Member Data Documentation

long Count [private]
 

The number of items in the list.

Definition at line 40 of file LinkedList.h.

ITEMTYPE* First [private]
 

The first list item.

Definition at line 45 of file LinkedList.h.

ITEMTYPE* Last [private]
 

The next list item.

Definition at line 57 of file LinkedList.h.


The documentation for this class was generated from the following file:
Generated on Tue Oct 3 00:23:39 2006 for ToolBox by doxygen 1.3.6