]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/plist.hh
469a8d444a4d1b3e45a29dec429b8fea49390758
[lilypond.git] / flower / include / 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 /**
13   A list of pointers.
14   
15   Use for list of pointers, e.g. Link_list<AbstractType*>. 
16   This class does no deletion of the pointers, but it knows how to
17   copy itself (shallow copy). We could have derived it from List<T>,
18   but this design saves a lot of code dup; for all Link_lists in the
19   program only one parent List<void*> is instantiated.
20   */
21 template<class T>
22 class Link_list : public List<void *>
23 {
24  public:
25     PCursor<T> top() const{
26         return PCursor<T> (List<void*>::top());
27     }
28     PCursor<T> bottom() const {
29         return PCursor<T> (List<void*>::bottom());
30     }
31     PCursor<T> find(T) const;
32     void concatenate(Link_list<T> const &s) { List<void*>::concatenate(s); }
33     Link_list() {}
34 };
35
36 /**   Link_list which deletes pointers given to it. 
37   NOTE:
38   
39   The copy constructor doesn't do what you'd want:
40   Since T might have a virtual ctor, we don't try to do a
41
42     new T(*cursor)
43
44   You have to copy this yourself, or use the macro Link_list__copy
45   
46   */
47 template<class T>
48 class Pointer_list : public Link_list<T> {
49 public:
50     Pointer_list(Pointer_list const &) { set_empty(); }
51     Pointer_list() { }
52     ~Pointer_list();
53 };
54
55 #define Pointer_list__copy(T, to, from, op)   \
56   for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
57       to.bottom().add(_pc_->op)\
58   \
59
60
61 template<class T>
62 void PL_copy(Pointer_list<T*> &dst,Pointer_list<T*> const&src);
63
64
65
66 #include "plist.icc"
67
68 #endif