/// Use for list of pointers, e.g. PointerList<AbstractType*>.
template<class T>
-class PointerList : public List<T>
+class PointerList : public List<void *>
{
public:
- PointerList(PointerList&) { set_empty(); }
- PointerList( const T& thing ) : List<T>( thing ) { }
+ PCursor<T> top() { return PCursor<T> (List<void*>::top()); }
+ PCursor<T> bottom() { return PCursor<T> (List<void*>::bottom()); }
+
+ PointerList( const T& thing ) : List<void*>( thing ) { }
PointerList() {}
- ///
- virtual ~PointerList();
- /**
- This function deletes deletes the allocated pointers of all links.
- #\Ref{~List}# is used to delete the links themselves.
- */
-
- protected:
- virtual void remove( Cursor<T> me );
+};
+
+
+/// intrusive pl. deletes pointers given to it.
+template<class T>
+struct IPointerList : public PointerList<T> {
+ IPointerList(IPointerList&) { set_empty(); }
+ IPointerList() { }
+protected:
+ virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
+ virtual void remove( PCursor<T> me );
};
/**
NOTE:
You have to copy this yourself, or use the macro PointerList__copy
*/
-#define PointerList__copy(T, to, from, op) \
+#define IPointerList__copy(T, to, from, op) \
for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
to.bottom().add(_pc_->op)\
\
template<class T>
-void PL_copy(PointerList<T*> &dst,PointerList<T*> const&src);
+void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
+
#define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*>
+#define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>
#include "plist.inl"
#ifndef PLIST_INL
#define PLIST_INL
-
-
-template<class T>
-inline
-PointerList<T>::~PointerList()
-{
- Cursor<T> next(*this);
- for ( Cursor<T> c( *this ); c.ok(); c = next ) {
- next = c;
- next++;
- remove( c ); // PointerList::remove deletes the real data
- }
-}
-
-template<class T>
-inline void
-PointerList_print( PointerList<T> const & l )
-{
- for (PCursor<T> c(l ); c.ok(); c++ )
- c->print();
-}
-
template<class T>
-inline void
-PL_copy(PointerList<T*> &to,PointerList<T*> const&src)
+void
+PL_copy(IPointerList<T*> &to, IPointerList<T*> const&src)
{
for (PCursor<T*> pc(src); pc.ok(); pc++) {
T *q = pc;
- T *p=new T(*q) ; // argh, how do i do this in ANSI-C++
+ T *p=new T(*q) ;
to.bottom().add(p);
}
}
+
#endif