more type-safety

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-07-21 16:13:27 +00:00
parent ee31c392ac
commit 63b522d64b

View File

@@ -1,12 +1,14 @@
/*-*- c++ -*-******************************************************** /*-*- c++ -*-********************************************************
* kbList.h : a double linked list * * kbList.h : a double linked list *
* * * *
* (C) 1998 by Karsten Ball<6C>der (Ballueder@usa.net) * * (C) 1998-1999 by Karsten Ball<6C>der (karsten@phy.hw.ac.uk) *
* * * *
* $Id$ * $Id$
* *
*******************************************************************/ *******************************************************************/
#ifndef KBLIST_H #ifndef KBLIST_H
# define KBLIST_H # define KBLIST_H
@@ -76,6 +78,7 @@ public:
*/ */
operator void*() const { return node == NULL ? (void*)0 : (void*)(-1); } operator void*() const { return node == NULL ? (void*)0 : (void*)(-1); }
/** Increment operator - prefix, goes to next node in list. /** Increment operator - prefix, goes to next node in list.
@return itself @return itself
*/ */
@@ -142,6 +145,8 @@ public:
bool ownsObjects(void) bool ownsObjects(void)
{ return ownsEntries; } { return ownsEntries; }
// This must be protected to disallow insertion of wrong elements.
protected:
/** Add an entry at the end of the list. /** Add an entry at the end of the list.
@param element pointer to data @param element pointer to data
*/ */
@@ -152,25 +157,26 @@ public:
*/ */
void push_front(void *element); void push_front(void *element);
/** Insert an element into the list.
@param i an iterator pointing to the element, before which the new one should be inserted
@param element the element data
*/
void insert(iterator & i, void *element);
public:
/** Get element from end of the list and delete it. /** Get element from end of the list and delete it.
NOTE: In this case the element's data will not get deleted by NOTE: In this case the element's data will not get deleted by
the list. It is the responsibility of the caller to free it. the list. It is the responsibility of the caller to free it.
@return the element data @return the element data
*/ */
void *pop_back(void); void * pop_back(void);
/** Get element from head of the list and delete it. /** Get element from head of the list and delete it.
NOTE: In this case the element's data will not get deleted by NOTE: In this case the element's data will not get deleted by
the list. It is the responsibility of the caller to free it. the list. It is the responsibility of the caller to free it.
@return the element data @return the element data
*/ */
void *pop_front(void); void * pop_front(void);
/** Insert an element into the list.
@param i an iterator pointing to the element, before which the new one should be inserted
@param element the element data
*/
void insert(iterator & i, void *element);
/** Remove an element from the list _without_ deleting the object. /** Remove an element from the list _without_ deleting the object.
@param i iterator pointing to the element to be deleted @param i iterator pointing to the element to be deleted
@@ -276,7 +282,12 @@ public: \
\ \
inline type *pop_front(void) \ inline type *pop_front(void) \
{ return (type *) kbList::pop_front(); } \ { return (type *) kbList::pop_front(); } \
\ inline void push_back(type *element) \
{ kbList::push_back( (void *) element); } \
void push_front(type *element) \
{ kbList::push_front( (void *) element); } \
void insert(iterator & i, void *element) \
{ kbList::insert( i, (void *) element); } \
type *remove(iterator& i) \ type *remove(iterator& i) \
{ return (type *)kbList::remove(i); } \ { return (type *)kbList::remove(i); } \
inline void erase(iterator & i) \ inline void erase(iterator & i) \
@@ -312,4 +323,5 @@ protected: \
KBLIST_DEFINE(kbStringList, String); KBLIST_DEFINE(kbStringList, String);
#endif #endif
//@} //@}
#endif // KBLIST_H #endif // KBLIST_H