Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

TPList Class Template Reference

An improved list for pointers only. More...

#include <plist.h>

Inheritance diagram for TPList:

Inheritance graph
[legend]
Collaboration diagram for TPList:

Collaboration graph
[legend]
List of all members.

Public Types

typedef list< X *>::iterator iterator
typedef list< X *>::const_iterator const_iterator

Public Methods

 TPList (bool autoDelete=false)
 TPList (const TPList< X > &src)
virtual ~TPList ()
void add (X *obj)
void deleteAll ()
iterator find (X *obj)
X * getFirst () const
iterator goTo (int4 n)
TPList< X > & operator= (const TPList &Src)
bool remove (X *obj)
bool remove (iterator it)
void setAutoDeleteMode (bool autoDelete)

Protected Attributes

bool fAutoDelete

Detailed Description

template<class X>
class TPList< X >

An improved list for pointers only.

Author:
Marco Krohn <marco.krohn@gmx.de>
Version:
Id:
plist.h,v 1.12 2002/05/10 10:35:19 mkrohn5 Exp
See also:
TPEList
This template class makes handling a list of pointers a bit easier since the autodelete (see setAutoDeleteMode) feature is added. If you also need load and save methods have a look at the extended version TPEList.

Example:

 TPList<TSubFleet> fSubFleets;
 fSubFleets.setAutoDeleteMode( true );

 subFleet = new TSubFleet(...);
 fSubFleets.push_back( subFleet );
 fSubFleets.push_back( new TSubFleet(...) );
 fSubFleets.remove( subFleet );        // <= also deltes the subFleet itself!
 

So usage is similar to a list. Note though the remove command and that a destructor call of TPList<...> also deletes all objects if the "auto delete mode" is set to true.


Constructor & Destructor Documentation

template<class X>
TPList< X >::TPList bool    autoDelete = false [inline]
 

The constructor initializes the auto delete variable (SetAutoDeleteMode).

Parameters:
autoDelete  The new settings for the fAutoDelete variable.

template<class X>
virtual TPList< X >::~TPList   [inline, virtual]
 

The destructor calls deleteAll to clean up everything.


Member Function Documentation

template<class X>
void TPList< X >::add X *    obj [inline]
 

Adds a object to the list. Note this method is doing the same as the list method "push_back". There is no check which prevents adding the same object twice.

Parameters:
pObj  The new object.

template<class X>
void TPList< X >::deleteAll   [inline]
 

Deletes all elements from the list.

See also:
fAutoDelete

template<class X>
iterator TPList< X >::find X *    obj [inline]
 

Returns:
The first iterator i in the list, such that *i == pObj. It returns end() if no such object exist.

template<class X>
X* TPList< X >::getFirst   const [inline]
 

Returns:
The first element in the list or 0 if the list is empty.

template<class X>
iterator TPList< X >::goTo int4    n [inline]
 

Returns the iterator for the n-th element. Note: this operation is slow O(n).

Parameters:
n  The n-th element of the list (n=0 means the first element).
Returns:
The n-th element of the list. If n is greater than the list size the return value is end() (especially if the list is empty).

template<class X>
TPList<X>& TPList< X >::operator= const TPList< X > &    Src [inline]
 

The operator= copies the pointer list, but not the variable fAutoDelete. fAutoDelete is not copied, but set to false, to prevent that objects are deleted twice.

Parameters:
The  source list.
Returns:
The modified object.

template<class X>
bool TPList< X >::remove iterator    it [inline]
 

Removes an object from the list. Note that this method is the same as erase, if and only if fAutoDelete is set to false. If fAutoDelete is true, than the object is also deleted.

Parameters:
it  the object to remove (and perhaps also delete).
Returns:
true if the object was removed from the list successfuly, otherwise false.

template<class X>
bool TPList< X >::remove X *    obj [inline]
 

Removes an object from the list. Note that this method is the same as erase, if and only if fAutoDelete is set to false. If fAutoDelete is true, than the object is also deleted.

Parameters:
obj  is the object to remove (and perhaps also delete).
Returns:
true if the object was removed from the list successfuly, otherwise false.

template<class X>
void TPList< X >::setAutoDeleteMode bool    autoDelete [inline]
 

Sets the auto delete mode (see fAutoDelete for details).

Parameters:
autoDelete  The new settings for the fAutoDelete variable.


Member Data Documentation

template<class X>
bool TPList::fAutoDelete [protected]
 

If set to true not only the list is deleted, but also all elements. false on the other hand will delete the list only without taking care of the objects.


The documentation for this class was generated from the following file:
Generated on Thu Jun 20 18:13:29 2002 for Stellar Legacy by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001