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() const{
18 return PCursor<T> (List<void*>::top());
20 PCursor<T> bottom() const {
21 return PCursor<T> (List<void*>::bottom());
23 PCursor<T> find(T) const;
24 void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
27 /** This class does no deletion of the pointers, but it knows how to
28 copy itself (shallow copy). We could have derived it from List<T>,
29 but this design saves a lot of code dup; for all PointerLists in the
30 program only one parent List<void*> is instantiated. */
32 /// pl. which deletes pointers given to it.
34 struct IPointerList : public PointerList<T> {
35 IPointerList(const IPointerList&) { set_empty(); }
38 virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
39 virtual void remove( PCursor<T> me );
44 The copy constructor doesn't do what you'd want:
45 Since T might have a virtual ctor, we don't try to do a
49 You have to copy this yourself, or use the macro PointerList__copy
52 #define IPointerList__copy(T, to, from, op) \
53 for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
54 to.bottom().add(_pc_->op)\
59 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
62 #define PL_instantiate(a) template class PointerList<a*>
63 #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>