* (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
* *
* $Id$
- * $Log$
- * Revision 1.1 1998/06/29 12:44:36 KB
- * Added my wxWindows based layout engine to the repository.
- * It arranges text and graphics for display on a wxDC.
- * This code is licensed under the LGPL.
- *
- * Revision 1.6 1998/06/27 20:06:10 KB
- * Added my layout code.
*
*******************************************************************/
struct kbListNode *next;
/// pointer to previous node or NULL
struct kbListNode *prev;
- /// pointer to the actual data
+ /// pointer to the actual data
void *element;
/** Constructor - it automatically links the node into the list, if
the iprev, inext parameters are given.
*/
void * operator*();
+ /** This operator allows us to write if(i). It is <em>not</em> a
+ dereference operator and the result is always useless apart
+ from its logical value!
+ */
+ operator void*() const { return node == NULL ? (void*)0 : (void*)(-1); }
+
/** Increment operator - prefix, goes to next node in list.
@return itself
*/
/** Comparison operator.
@return true if not equal.
*/
- bool operator !=(iterator const &) const;
+ bool operator !=(iterator const &) const;
/* Comparison operator.
@return true if equal
*/
- bool operator ==(iterator const &) const;
+ bool operator ==(iterator const &) const;
/** Returns a pointer to the node associated with this iterator.
This function is not for general use and should be
*/
bool ownsObjects(void)
{ return ownsEntries; }
-
+
/** Add an entry at the end of the list.
@param element pointer to data
*/
*/
void insert(iterator & i, void *element);
+ /** Remove an element from the list _without_ deleting the object.
+ @param i iterator pointing to the element to be deleted
+ @return the value of the element just removed
+ */
+ void *remove(iterator& i) { void *p = *i; doErase(i); return p; }
+
/** Erase an element, move iterator to following element.
@param i iterator pointing to the element to be deleted
*/
- void erase(iterator & i);
-
+ void erase(iterator & i) { deleteContent(i); doErase(i); }
+
/* Get head of list.
@return iterator pointing to head of list
*/
/* Query whether list is empty.
@return true if list is empty
*/
- bool empty(void) const
+ inline bool empty(void) const
{ return first == NULL ; }
-private:
+protected:
/// if true, list owns entries
bool ownsEntries;
/// pointer to first element in list
kbListNode *first;
/// pointer to last element in list
kbListNode *last;
+protected:
+ /** Erase an element, move iterator to following element.
+ @param i iterator pointing to the element to be deleted
+ */
+ void doErase(iterator & i);
+
+ /** Deletes the actual content if ownsflag is set.
+ param iterator i
+ */
+ inline void deleteContent(iterator i)
+ { if(ownsEntries) delete *i; }
+
+private:
/// forbid copy construction
kbList(kbList const &foo);
/// forbid assignments
/* the cast is needed for MS VC++ 5.0 */ \
{ return (type *)((kbList::iterator *)this)->operator*() ; } \
}; \
- inline name(bool ownsEntriesFlag = true) \
+ inline name(bool ownsEntriesFlag = TRUE) \
: kbList(ownsEntriesFlag) {} \
\
- inline void push_back(type *element) \
- { kbList::push_back((void *)element); } \
- \
- inline void push_front(type *element) \
- { kbList::push_front((void *)element); } \
- \
inline type *pop_back(void) \
{ return (type *) kbList::pop_back(); } \
\
inline type *pop_front(void) \
{ return (type *) kbList::pop_front(); } \
\
- inline void insert(iterator & i, type *element) \
- { kbList::insert(i, (void *) element); } \
- \
- void erase(iterator & i) \
- { kbList::erase(i); } \
+ type *remove(iterator& i) \
+ { return (type *)kbList::remove(i); } \
+ inline void erase(iterator & i) \
+ { deleteContent(i); kbList::erase(i); } \
\
inline iterator begin(void) const \
{ return kbList::begin(); } \
\
inline iterator tail(void) const \
{ return kbList::tail(); } \
+ ~name() \
+ { \
+ kbListNode *next; \
+ while ( first != NULL ) \
+ { \
+ next = first->next; \
+ if(ownsEntries) \
+ delete (type *)first->element; \
+ delete first; \
+ first = next; \
+ } \
+ } \
+protected: \
+ inline void deleteContent(iterator i) \
+ { if(ownsEntries) delete *i; } \
}
#ifdef MCONFIG_H