Diffpack Documentation


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

DpList(Type,Itemtype) Class Reference

a template class for lists. More...

#include <DpList_Type.h>

List of all members.

Public Methods

 DpList(Type,Itemtype) ()
virtual ~DpList(Type,Itemtype) ()
 DpList(Type,Itemtype) (const DpList(Type,Itemtype) &list_)
void operator= (const DpList(Type,Itemtype) &list_)
DpList(Type,Itemtype)& insert (const Type &object)
DpList(Type,Itemtype)& append (const Type &object)
void remove ()
void removeCurr ()
Type* start ()
Type* end ()
Type* next ()
Type* prev ()
Type* curr ()
Type* start () const
Type* end () const
Type* next () const
Type* prev () const
Type* curr () const
int size () const
int getNoEntries () const
Type* operator() (int i)
const Type* operator() (int i) const
bool memberAdr (const Type &object)
void removeAdr (const Type &object)
void sort ()
void insertSorted (DpList(Type,Itemtype) &list_)
void remove (const Type &object)
bool member (const Type &object)
void print (Os os)
bool convert2vector (VecSimplest(Type) &vec)

Static Public Attributes

long nitems_alloc
long nitems_dealloc

Protected Methods

void remove (Itemtype(Type) *pt)
void moveInFront (Itemtype(Type) *item1, Itemtype(Type) *item2)
void insertInFront (const Type &obj, Itemtype(Type) *pt)

Protected Attributes

Itemtype(Type)* head
Itemtype(Type)* tail
Itemtype(Type)* current


Detailed Description

a template class for lists.

NAME: DpList - a template class for lists

DESCRIPTION:

Class "DpList" offers a standard list structure. The items in the list can be of three types: 1) pointers, 2) instances, or 3) handles. The "DpList" class is parameterized by two parameters, one reflecting the type of objects in the list and one reflecting which of the three types of items that are used in the list. For example, ""DpList(String,DpListItemInst)"" is a list of strings where each string is represented as an instance, ""DpList(GridFE,DpListItemHandle)"" is a list of finite element grids where each grid is represented in terms of a handle and ""DpList(Matrix(real)),DpListItemPtr"" is a list of matrices where each matrix is represented in terms of an ordinary pointer. It is recommended to use "DpListItemHandle" instead of "DpListItemPtr" since handles are safer and easier to use than pointers. However, some classes are not equipped with handles of efficiency reasons (class "Ptv" and "VecSimple" for example) and for such classes "DpListItemPtr" is the natural choice.

How should one choose between the instance, handle and pointer type of list items? That will depend on the type of objects that are managed in the list. Using "DpListItemInst", each item will take a full copy (using "operator=") of the objects that are appended to the list. When the list is removed, all the copies are deleted while the original objects are untouched. With "DpListItemPtr" there are pointers to the original objects, and when the list is destroyed, only the pointers are deleted (hence the original objects are untouched). Finally, "DpListItemHandle" has a handle to each object that is appended to the list. When the list is cleaned up, and if there are no other handles to the object, the object is deleted. "DpListItemHandle" is therefore the only list item type that can delete the original objects. A rule of thumb is to use "DpListItemInst" for small objects ("int", "real", "Ptv"), "DpListItemHandle" for larger objects and "DpListItemPtr" for classes that do not have handles implemented ("VecSimple" for example).


Constructor & Destructor Documentation

DpList(Type,Itemtype)::DpList_Type,Itemtype ( ) [inline]
 

The only constructor creates an empty list. The member functions "insert" and "append" are used to insert objects in the front of the list and at the end of the list respectively.

DpList(Type,Itemtype)::~DpList(Type,Itemtype) ( ) [inline, virtual]
 

DpList(Type,Itemtype)::DpList_Type,Itemtype ( const DpList(Type,Itemtype) & list_ )
 

See documentation of one of the overloaded constructor.


Member Function Documentation

DpList(Type,Itemtype) & DpList(Type,Itemtype)::append ( const Type & object )
 

appends object to the end (tail) of the list.

bool DpList(Type,Itemtype)::convert2vector ( VecSimplest(Type) & vec )
 

fills a vector "VecSimplest"(Type) with the contents of the list. The vector is automatically redimensioned in the function. To read a vector of unknown length, one can first read the elements into a list and then create the vector from the list using "convert2vector". The return value is "bool". A false value reflects an empty list and no modifications of the vector are performed. A true value reflects that the vector is redimensioned and filled with list entries. The function requires that a class "VecSimplest(Type)" is defined and that "Type operator =" is meaningful. If this is not the case, one can define the preprocessor variable "PRIMITIVE_LISTITEM". This will exclude the "convert2vector" function from the "DpList" class.

Type * DpList(Type,Itemtype)::curr ( ) const [inline]
 

See documentation of one of the overloaded functions.

Type * DpList(Type,Itemtype)::curr ( )
 

returns access to current item. There is an internal pointer, hereafter referred to as the current pointer, which the user may utilize when iterating over list items. The functions "next", "prev", "start" and "end" alter the value of the current pointer. If the list is empty, or the current pointer has been moved beyond the beginning or end of the list, "curr" returns NULL.

Type * DpList(Type,Itemtype)::end ( ) const [inline]
 

See documentation of one of the overloaded functions.

Type * DpList(Type,Itemtype)::end ( )
 

sets the current pointer to point at the end (or tail) of the list, returning access to the first item, or "NULL" if list is empty. Useful for initializing an iteration over the list, starting at the tail and moving towards the beginning of the list.

int DpList(Type,Itemtype)::getNoEntries ( ) const
 

a synonym for "size", kept for compatibility.

DpList(Type,Itemtype) & DpList(Type,Itemtype)::insert ( const Type & object )
 

inserts object at the front (head) of the list.

void DpList(Type,Itemtype)::insertInFront ( const Type & obj,
Itemtype(Type) * pt ) [protected]
 

used by "insertSorted". The object "obj" is inserted in front of the object pointed to by "pt".

void DpList(Type,Itemtype)::insertSorted ( DpList(Type,Itemtype) & list_ )
 

inserts a second list, given as argument, into the existing list. The resulting list will remain sorted if the existing list was sorted.

bool DpList(Type,Itemtype)::member ( const Type & object )
 

returns true if "object" is a member of the list. This function requires that class "Type" has an "operator==" function.

bool DpList(Type,Itemtype)::memberAdr ( const Type & object )
 

returns true if "object" is a member of the list. This function considers two objects equal only if they have the same address, and is therefore useful only with "DpListItemHandle" and "DpListItemInst". It does not require an "operator==" to be defined for the list object type.

void DpList(Type,Itemtype)::moveInFront ( Itemtype(Type) * item1,
Itemtype(Type) * item2 ) [protected]
 

used by "sort". The object pointed to by "item1" is moved from its current position in the list and placed in front of the object pointed to by "item2".

Type * DpList(Type,Itemtype)::next ( ) const [inline]
 

See documentation of one of the overloaded functions.

Type * DpList(Type,Itemtype)::next ( )
 

returns access to the next list item. The current pointer is updated and will point to the next item after a call to "next". If the current item was the last, "next", and further calls to "curr", will return "NULL".

const Type * DpList(Type,Itemtype)::operator() ( int i ) const
 

Type * DpList(Type,Itemtype)::operator() ( int i )
 

void DpList(Type,Itemtype)::operator= ( const DpList(Type,Itemtype) & list_ )
 

Type * DpList(Type,Itemtype)::prev ( ) const [inline]
 

See documentation of one of the overloaded functions.

Type * DpList(Type,Itemtype)::prev ( )
 

returns access to the previous list item. The current pointer is updated and will point to the previous item after a call to "prev". If the current item was the first, "prev", and further calls to "curr", will return "NULL".

void DpList(Type,Itemtype)::print ( Os os )
 

prints the list. The function requires "Type operator <<" to be defined. If this is not the case, setting the preprocessor variable "PRIMITIVE_LISTITEM" will disable the "print" function in the list class.

void DpList(Type,Itemtype)::remove ( Itemtype(Type) * pt ) [protected]
 

See documentation of one of the overloaded functions.

void DpList(Type,Itemtype)::remove ( const Type & object )
 

See documentation of one of the overloaded functions.

void DpList(Type,Itemtype)::remove ( )
 

See documentation of one of the overloaded functions.

void DpList(Type,Itemtype)::removeAdr ( const Type & object )
 

removes the given object from the list, comparing addresses.

void DpList(Type,Itemtype)::removeCurr ( )
 

removes the item pointed to by the ""current"" pointer (see below). This remove function is intended for the case where the user runs through the list and examines the items with respect to removal or not. The tests should be performed using "DpList curr()" to ensure that one really knows what the current object is. The call modifies the current pointer the same way as a call to "next" would.

int DpList(Type,Itemtype)::size ( ) const
 

returns the number of objects in the list. To test if a list is empty, simply test if "size()==0".

void DpList(Type,Itemtype)::sort ( )
 

sorts the entries in the list. The function requires that the objects in the list (of class "Type") has a function "operator<".

Type * DpList(Type,Itemtype)::start ( ) const [inline]
 

See documentation of one of the overloaded functions.

Type * DpList(Type,Itemtype)::start ( )
 

sets the current pointer to point at the start (or head) of he list, returning access to the first item, or "NULL" if list is empty. Useful for initializing an iteration over the list, starting at the head.


Member Data Documentation

Itemtype(Type) * DpList(Type,Itemtype)::current [protected]
 

Itemtype(Type) * DpList(Type,Itemtype)::head [protected]
 

long DpList(Type,Itemtype)::nitems_alloc [static]
 

long DpList(Type,Itemtype)::nitems_dealloc [static]
 

Itemtype(Type) * DpList(Type,Itemtype)::tail [protected]
 


The documentation for this class was generated from the following file:
Copyright © 2003 inuTech GmbH. All rights reserved.