]> git.donarmstrong.com Git - lilypond.git/blob - flower/plist.hh
release: 0.0.18
[lilypond.git] / flower / plist.hh
1 /*
2   list.hh -- part of flowerlib
3
4   (c) 1996 Han-Wen Nienhuys & Jan Nieuwenhuizen
5 */
6
7 #ifndef PLIST_HH
8 #define PLIST_HH
9
10 #include "list.hh"
11
12 /// Use for list of pointers, e.g. PointerList<AbstractType*>.
13 template<class T>
14 class PointerList : public List<void *>
15 {
16  public:
17     PCursor<T> top() const{
18         return PCursor<T> (List<void*>::top());
19     }
20     PCursor<T> bottom() const {
21         return PCursor<T> (List<void*>::bottom());
22     }
23     PCursor<T> find(T) const;
24     void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
25     PointerList() {}
26 };
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.  */
31
32 ///  pl. which deletes pointers given to it.
33 template<class T>
34 struct IPointerList : public PointerList<T> {
35     IPointerList(const IPointerList&) { set_empty(); }
36     IPointerList() { }
37 protected:
38     virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
39     virtual void remove( PCursor<T> me );
40 };
41 /**
42   NOTE:
43   
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
46
47     new T(*cursor)
48
49   You have to copy this yourself, or use the macro PointerList__copy
50   
51   */
52 #define IPointerList__copy(T, to, from, op)   \
53   for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
54       to.bottom().add(_pc_->op)\
55   \
56
57
58 template<class T>
59 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
60
61
62 #define PL_instantiate(a)  template class PointerList<a*>
63 #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>
64
65 #include "plist.inl"
66
67 #endif