flower-1.1.5
[lilypond.git] / flower / plist.hh
blob426b861c024f079364f3c5d5d68ee7a9f0eb79dc
1 /*
2 list.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys & Jan Nieuwenhuizen
5 */
7 #ifndef PLIST_HH
8 #define PLIST_HH
10 #include "list.hh"
12 /**
13 A list of pointers.
15 Use for list of pointers, e.g. PointerList<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 PointerLists in the
19 program only one parent List<void*> is instantiated.
21 template<class T>
22 class PointerList : public List<void *>
24 public:
25 PCursor<T> top() const{
26 return PCursor<T> (List<void*>::top());
28 PCursor<T> bottom() const {
29 return PCursor<T> (List<void*>::bottom());
31 PCursor<T> find(T) const;
32 void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
33 PointerList() {}
36 /** PointerList which deletes pointers given to it.
37 NOTE:
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
42 new T(*cursor)
44 You have to copy this yourself, or use the macro PointerList__copy
47 template<class T>
48 class IPointerList : public PointerList<T> {
49 public:
50 IPointerList(const IPointerList&) { set_empty(); }
51 IPointerList() { }
52 ~IPointerList();
55 #define IPointerList__copy(T, to, from, op) \
56 for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\
57 to.bottom().add(_pc_->op)\
61 template<class T>
62 void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src);
65 #define PL_instantiate(a) template class PointerList<a*>; \
66 template class PCursor<a*>;
67 #define IPL_instantiate(a) PL_instantiate(a); \
68 template class IPointerList<a*>
70 #include "plist.inl"
72 #endif