2 list.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys & Jan Nieuwenhuizen
12 /// Use for list of pointers, e.g. PointerList<AbstractType*>.
14 class PointerList : public List<void *>
17 PCursor<T> top() { return PCursor<T> (List<void*>::top()); }
18 PCursor<T> bottom() { return PCursor<T> (List<void*>::bottom()); }
19 PCursor<T> find(T) const;
20 void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
23 /** This class does no deletion of the pointers, but it knows how to
24 copy itself (shallow copy). We could have derived it from List<T>,
25 but this design saves a lot of code dup; for all PointerLists in the
26 program only one parent List<void*> is instantiated. */
28 /// pl. which deletes pointers given to it.
30 struct IPointerList : public PointerList<T> {
31 IPointerList(const IPointerList&) { set_empty(); }
34 virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
35 virtual void remove( PCursor<T> me );
40 The copy constructor doesn't do what you'd want:
41 Since T might have a virtual ctor, we don't try to do a
45 You have to copy this yourself, or use the macro PointerList__copy
48 #define IPointerList__copy(T, to, from, op) \
49 for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
50 to.bottom().add(_pc_->op)\
55 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
58 #define PL_instantiate(a) template class PointerList<a*>
59 #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>