HepAList


HepAList is a template based list class for storing (pointers to) objects. An object can be a member of many lists at a time. Before an object is destructed, it must explicitly be taken out of any lists (otherwise there will be pointers left pointing to deallocated space). Objects does not have to be allocated on the free store, however if they are not, calling the function HepAListDeleteAll(HepAList<T> &) is not to recommended.

Only pointers to objects are stored in the list although there are methods to insert object references. Hence no object is copied in the process of handeling the list.

The list is implemented as an array of pointers. Appending an object to the end of the list (append() and operator +=) is cheap. Removing objects (except for the last) and inserting at the beginning of the list is more expensive. HepAList is designed to be very space effective; The number of bytes needed for a list is (3 + number of objects) * sizeof (void*).

HepAList was developed from an original (non-template) list class written by Dag Bruck.

Author

Leif Lonnblad

See also

HepAListBase, HepCList, HepConstAList, HepAListIteratorBase, HepAListIterator, HepCListIterator, HepConstAListIterator

Declaration

#include "CLHEP/Alist/AList.h"

template <class T>
class HepAList : public HepAListBase

Public Member Functions

Constructor
inline HepAList()
Constructs a list with no objects.
Copy constructor
inline HepAList(const HepAList<T> &)
Destructor
inline ~HepAList()
Destroys the list. The objects in the list are not destroyed.
Use HepAListDeleteAll(HepAList &) to destroy all objects in the list.
=
inline void operator = (const HepAList<T> &)
Assignment.
+=
inline void operator += (T *)
inline void operator += (T &)
Appends an object in the end of the list.

inline void operator += (const HepAList<T> &l)
Appends all objects of the list l to the end of this list.
[]
inline T * operator[] (unsigned i) const
Returns the i-th object in the list.
NOTE! The objects are numbered from 0 to n-1.
append
inline void append(T *)
inline void append(T &)
Appends the object in the end of the list.

inline void append(T *e, T *r)
inline void append(T &e, T &r)
Appends the object e just after the last occurrence of the object r in the list.

inline void append(const HepAList<T> &l)
Appends all objects of list l to the end of this list.
fIndex
inline int fIndex(T *) const
inline int fIndex(T &) const
Returns the index of the first occurence of the object.
NOTE! The objects are numbered from 0 to n-1.
first
inline T * first() const
Returns a pointer to the first object in the list.
hasMember
inline HepBoolean hasMember(T *) const
inline HepBoolean hasMember(T &) const
Returns true if the object is a member of the list.
index
inline int index(T *) const
inline int index(T &) const
Returns the index of the last occurrence of the object.
NOTE! The objects are numbered from 0 to n-1.
insert
inline void insert(T *)
inline void insert(T &)
Inserts an object first in the list.

inline void insert(T *e, T *r)
inline void insert(T &e, T &r)
Inserts the object e just before the first occurence of the object r in the list.

inline void insert(T *e, unsigned pos)
inline void insert(T &e, unsigned pos)
Inserts the object e at the position pos in the list.
If pos is outside the list, the object will be appended.
last
inline T * last() const
Returns a pointer to the last object in the list.
member
inline HepBoolean member(T *) const
inline HepBoolean member(T &) const
Returns true if the object is a member of the list.
remove
inline void remove(T *)
inline void remove(T &)
Remove all occurencies of the object from the list.

inline void remove(unsigned)
Remove an object from the list.

inline void remove(const HepAList<T> &l)
Remove all occurencies of the objects in list l from this list.
replace
inline void replace(T *eo, T *en)
inline void replace(T &eo, T &en)
Replace all occurencies of the object eo with object en.
sort
inline void sort(int (*compfunc)(const T **, const T **) )
Sort the list according to the function.
The function is the same as one used by the C standard routine qsort.

Non-Member Functions

AListReverseSort
template <class T>
inline void AListReverseSort(HepAList<T> &)
Reverse sort the list if the operator< is defined on T.
AListSort
template <class T>
inline void AListSort(HepAList<T> &)
Sort the list if the operator< is defined on T.
HepAListDeleteAll
template <class T>
inline void HepAListDeleteAll(HepAList<T> &l)
Deletes all elements in a list.
NOTE! Use this function with care. Make sure that all elements in the list has been allocated with new.

Example

CLHEP/test/testAList.cc


24 September 1997
EVC