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

list.h

00001 /*
00002  *                         Sun Public License Notice
00003  *
00004  * The contents of this file are subject to the Sun Public License
00005  * Version 1.0 (the "License"); you may not use this file except
00006  * in compliance with the License. A copy of the License is available
00007  * at http://www.sun.com/
00008  *
00009  * The Original Code is the Java Profiler module.  The Initial Developers
00010  * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00011  * Lukas Petru and Marek Przeczek.
00012  *
00013  * Portions created by Jan Stola are Copyright (C) 2000-2001.
00014  * All Rights Reserved.
00015  *
00016  * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
00017  * All Rights Reserved.
00018  *
00019  * Portions created by Michal Pise are Copyright (C) 2000-2001.
00020  * All Rights Reserved.
00021  *
00022  * Portions created by Petr Luner are Copyright (C) 2000-2001.
00023  * All Rights Reserved.
00024  *
00025  * Portions created by Lukas Petru are Copyright (C) 2000-2001.
00026  * All Rights Reserved.
00027  *
00028  * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
00029  * All Rights Reserved.
00030  *
00031  * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00032  *               Lukas Petru and Marek Przeczek.
00033  */
00034 
00035 #ifndef _LIST_H_
00036 #define _LIST_H_
00037 
00038 #include "../main/includes.h"
00039 #include "../list/listItem.h"
00040 
00064 template<class T, class L> class List {
00065 
00067         ListItem* _list;
00068 
00069 public:
00070         
00072         List() :
00073         
00074                 _list( NULL)
00075                 
00076                 {}
00077 
00084         ~List() { clear();}
00085 
00088         void clear() {
00089 
00090                 while( _list) destroy( static_cast<T*>( static_cast<L*>( _list)));
00091         }
00092 
00100         T* first() const { return static_cast<T*>( static_cast<L*>( _list));}
00101 
00111         T* next( T* item) const {
00112 
00113                 return static_cast<T*>( static_cast<L*>( item->L::next()));
00114         }
00115 
00122         int isEmpty() const { return !_list;}
00123 
00134         T* add( T* p) {
00135 
00136                 if( !p) return NULL;
00137 
00138                 _list = p->L::add( &_list);
00139 
00140                 return p;
00141         }
00142         
00155         T* remove( T* p) {
00156 
00157                 if( !p) return NULL;
00158 
00159                 ListItem* q = p->L::remove();
00160                 if( p == static_cast<T*>( static_cast<L*>( _list))) _list = q;
00161 
00162                 return p;
00163         }
00164 
00174         void destroy( T* p) {
00175 
00176                 if( !p) return;
00177 
00178                 remove( p)->L::destroy();
00179         }
00180 
00194         int forEach( int (*f)( T*, void**), void** inout) {
00195 
00196                 T* p = first();
00197                 int rc;
00198 
00199                 while( p) {
00200 
00201                         if( rc = f( p, inout)) return rc;
00202                         p = next( p);
00203                 }
00204 
00205                 return 0;
00206         }
00207 
00212         int length() const {
00213 
00214                 int len = 0;
00215                 for( T* p = first(); p; p = next( p), len++);
00216                 return len;
00217         }
00218 };
00219 
00220 #endif // _LIST_H_

Generated on Mon Jan 28 14:53:26 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001