]> git.donarmstrong.com Git - lilypond.git/blob - flower/plist.hh
99be3ff811a7d673f8c31b2be656261b1aeb1d51
[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() {  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); }
21     PointerList() {}
22 };
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.  */
27
28 ///  pl. which deletes pointers given to it.
29 template<class T>
30 struct IPointerList : public PointerList<T> {
31     IPointerList(const IPointerList&) { set_empty(); }
32     IPointerList() { }
33 protected:
34     virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
35     virtual void remove( PCursor<T> me );
36 };
37 /**
38   NOTE:
39   
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
42
43     new T(*cursor)
44
45   You have to copy this yourself, or use the macro PointerList__copy
46   
47   */
48 #define IPointerList__copy(T, to, from, op)   \
49   for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
50       to.bottom().add(_pc_->op)\
51   \
52
53
54 template<class T>
55 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
56
57
58 #define PL_instantiate(a)  template class PointerList<a*>
59 #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>
60
61 #include "plist.inl"
62
63 #endif