]> git.donarmstrong.com Git - lilypond.git/blob - flower/plist.hh
release: 0.0.9
[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     void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
20 //    PointerList( const T& thing ) : List<void*>( thing ) { }
21     PointerList() {}
22 };
23
24
25 /// intrusive pl. deletes pointers given to it.
26 template<class T>
27 struct IPointerList : public PointerList<T> {
28     IPointerList(IPointerList&) { set_empty(); }
29     IPointerList() { }
30 protected:
31     virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); }
32     virtual void remove( PCursor<T> me );
33 };
34 /**
35   NOTE:
36   The copy constructor doesn't do what you'd want:
37   Since T might have a virtual ctor, we don't try to do a
38
39     new T(*cursor)
40
41   You have to copy this yourself, or use the macro PointerList__copy
42   
43   */
44 #define IPointerList__copy(T, to, from, op)   \
45   for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
46       to.bottom().add(_pc_->op)\
47   \
48
49
50 template<class T>
51 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
52
53
54 #define PL_instantiate(a)  template class PointerList<a*>
55 #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*>
56
57 #include "plist.inl"
58
59 #endif