From: Marek P. <ma...@us...> - 2001-11-21 22:32:16
|
Update of /cvsroot/javaprofiler/library/src/list In directory usw-pr-cvs1:/tmp/cvs-serv12170/src/list Modified Files: list.h listItem.h refCount.h Added Files: Makefile Makefile.mak Makefile.rules dir.info listItem.cpp Log Message: some parts completely rewritten; changes in communication interface to make it faster; ported to linux --- NEW FILE: Makefile --- include ../../config.mk include Makefile.rules --- NEW FILE: Makefile.mak --- !include ../../config.mk !include Makefile.rules --- NEW FILE: Makefile.rules --- listItem.o \ listItem.obj: listItem.cpp $(CCC) $(CPPFLAGS) listItem.cpp --- NEW FILE: dir.info --- FILES = listItem CLEAN_FILES = *.pdb *.obj *.o --- NEW FILE: listItem.cpp --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ #include "../list/listItem.h" ListItem* ListItem::add( ListItem** list) { _next = *list; _prev = NULL; _list = list; if( _next) _next->_prev = this; addRef(); return this; } ListItem* ListItem::remove() { if( _prev) _prev->_next = _next; if( _next) _next->_prev = _prev; ListItem* p = _next; _next = NULL; _prev = NULL; if( _list && *_list == this) *_list = p; _list = NULL; releaseRef(); return p; } Index: list.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/list/list.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** list.h 2001/09/02 20:14:21 1.8 --- list.h 2001/11/21 22:31:43 1.9 *************** *** 36,39 **** --- 36,42 ---- #define _LIST_H_ + #include "../main/includes.h" + #include "../list/listItem.h" + /** List template. This template class implements a list of objects inherited ** generally from ListItem class. Better use one of the direct descendants *************** *** 71,75 **** _list( NULL) ! {}; /** Destructor. It destroys the list. The item of the list --- 74,78 ---- _list( NULL) ! {} /** Destructor. It destroys the list. The item of the list *************** *** 78,84 **** ** ** @see destroy() */ ! virtual ~List() { while( _list) destroy( (T*)(L*)_list);}; /** First item of the list. This method returns pointer ** to the first item of the list or NULL if the list is empty. --- 81,94 ---- ** ** @see destroy() */ + + ~List() { clear();} + + /** Clears the whole list. */ ! void clear() { + while( _list) destroy( static_cast<T*>( static_cast<L*>( _list))); + } + /** First item of the list. This method returns pointer ** to the first item of the list or NULL if the list is empty. *************** *** 88,103 **** ** @see next() */ ! T* first() const { return (T*)(L*)_list;} /** Gets next item in the list for iterating. ** Returns NULL if the end of the list was reached. ** - ** @param item pointer to list item ** @return pointer to the next list item or NULL ** ** @see first() */ ! T* next(T* item) const { return (T*)(L*)(((L*)item)->next()); } /** Check for empty list. This method returns non-zero value ** if the list is empty or zero if it isn't. --- 98,117 ---- ** @see next() */ ! T* first() const { return static_cast<T*>( static_cast<L*>( _list));} /** Gets next item in the list for iterating. ** Returns NULL if the end of the list was reached. + ** + ** @param item pointer to list item ** ** @return pointer to the next list item or NULL ** ** @see first() */ ! T* next( T* item) const { + return static_cast<T*>( static_cast<L*>( item->L::next())); + } + /** Check for empty list. This method returns non-zero value ** if the list is empty or zero if it isn't. *************** *** 119,125 **** T* add( T* p) { - if ( !p) return NULL; - ((L*)p)->add(&_list); return p; } --- 133,141 ---- T* add( T* p) { + + if( !p) return NULL; + + _list = p->L::add( &_list); return p; } *************** *** 138,144 **** T* remove( T* p) { ! if( !p) return NULL; ! ((L*)p)->remove(); return p; } --- 154,163 ---- T* remove( T* p) { ! if( !p) return NULL; ! ! ListItem* q = p->L::remove(); ! if( p == static_cast<T*>( static_cast<L*>( _list))) _list = q; ! return p; } *************** *** 154,160 **** void destroy( T* p) { ! if( !p) return; ! ((L*)remove( p))->destroy(); } --- 173,180 ---- void destroy( T* p) { ! if( !p) return; ! ! remove( p)->L::destroy(); } *************** *** 167,171 **** ** code as 'f'. Else when it finishes it returns 0. ** ! ** @param f pointer to function ** @param inout the second argument of 'f' function ** --- 187,191 ---- ** code as 'f'. Else when it finishes it returns 0. ** ! ** @param f pointer to function ** @param inout the second argument of 'f' function ** *************** *** 178,184 **** while( p) { if( rc = f( p, inout)) return rc; ! p = next(p); } return 0; } --- 198,206 ---- while( p) { + if( rc = f( p, inout)) return rc; ! p = next( p); } + return 0; } *************** *** 191,195 **** int len = 0; ! for (T* p = first(); p; p = next(p), len++); return len; } --- 213,217 ---- int len = 0; ! for( T* p = first(); p; p = next( p), len++); return len; } *************** *** 197,199 **** #endif // _LIST_H_ - --- 219,220 ---- Index: listItem.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/list/listItem.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** listItem.h 2001/09/02 20:14:21 1.8 --- listItem.h 2001/11/21 22:31:43 1.9 *************** *** 36,39 **** --- 36,42 ---- #define _LIST_ITEM_H_ + #include "../main/includes.h" + #include "../list/refCount.h" + /** List item implementation. This class implements one item of the list. ** In truth it implements the list itself. This class has all needed methods *************** *** 55,61 **** /// pointer to next ListItem object in the list ListItem* _next; ! /// pointer to self link pointer ! ListItem** _self; public: --- 58,67 ---- /// pointer to next ListItem object in the list ListItem* _next; + + /// pointer to previous ListItem object in the list + ListItem* _prev; ! /// pointer where pointer to head of list is stored ! ListItem** _list; public: *************** *** 65,71 **** _next( NULL), ! _self( NULL) ! {}; /// Destructor. --- 71,78 ---- _next( NULL), ! _prev( NULL), ! _list( NULL) ! {} /// Destructor. *************** *** 79,111 **** ListItem* next() const { return _next;} ! /** Adds self to the list. ** ! ** @param list list ** ** @see remove() */ - - void add( ListItem** list) { - - _next = *list; - if (_next) _next->_self = &_next; - *list = this; - _self = list; ! addRef(); ! } /** Removes self from a list. ** ** @see add() */ - - void remove() { ! *_self = _next; ! if (_next) _next->_self = _self; ! _next = NULL; ! _self = NULL; ! ! releaseRef(); ! } }; --- 86,106 ---- ListItem* next() const { return _next;} ! /** Adds self to the head of list. ! ** ! ** @param list pointer to pointer to head of list ** ! ** @return new head of list ** ** @see remove() */ ! ListItem* add( ListItem** list); /** Removes self from a list. ** + ** @return pointer to next item in the list + ** ** @see add() */ ! ListItem* remove(); }; *************** *** 151,153 **** #endif // _LIST_ITEM_H_ - --- 146,147 ---- Index: refCount.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/list/refCount.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** refCount.h 2001/09/02 20:14:21 1.4 --- refCount.h 2001/11/21 22:31:43 1.5 *************** *** 36,39 **** --- 36,41 ---- #define _REF_COUNT_H_ + #include "../main/includes.h" + /** An abstract class for reference counting. ** Each class, which needs reference counting, must be a descendant *************** *** 54,68 **** protected: ! /// Default constructor. RefCount() : _count( 0) ! {}; public: /// Destructor. It does nothing. ! virtual ~RefCount() {}; /** Reference count incrementation. --- 56,70 ---- protected: ! /// Default _PROTECTED_ constructor. RefCount() : _count( 0) ! {} public: /// Destructor. It does nothing. ! virtual ~RefCount() {} /** Reference count incrementation. *************** *** 83,93 **** ** this method destroys the instance it was called for. ** The object should be created dynamically ;-) */ - - virtual void destroy() { ! if( !_count) delete this; ! } }; #endif // _REF_COUNT_H_ - --- 85,91 ---- ** this method destroys the instance it was called for. ** The object should be created dynamically ;-) */ ! virtual void destroy() { if( !_count) delete this;} }; #endif // _REF_COUNT_H_ |