lilypond-0.0.1
[lilypond.git] / flower / list.hh
blob97e672f2e091df7499f7162818f0b35bc52bb193
1 // list.hh
3 #ifndef __LIST_HH
4 #define __LIST_HH
6 class ostream;
7 template<class T> class Cursor;
8 template<class T> class Link;
10 /// all purpose list
11 template<class T>
12 class List
14 public:
15 /// construct empty list
16 List();
18 /// construct list from first item.
19 List( const T& thing );
21 virtual ~List();
23 Cursor<T> bottom();
25 int size() const;
26 Cursor<T> top();
27 void OK() const;
28 protected:
29 friend class Cursor<T>;
30 friend class Link<T>;
32 /// add after after_me
33 void add( const T& thing, Cursor<T> after_me );
35 /// put thing before #before_me#
36 void insert( const T& thing, Cursor<T> before_me );
37 virtual void remove( Cursor<T> me );
39 int size_;
40 Link<T>* top_;
41 Link<T>* bottom_;
43 /**
44 a doubly linked list;
45 List can be seen as all items written down on paper,
46 from top to bottom
48 class Cursor is used to extend List
50 items are always stored as copies in List, but:
51 #List<String># : copies of #String# stored
52 #List<String*># : copies of #String*# stored!
53 (do not use, use \Ref{PointerList}#<String*># instead.)
55 {\bf note:}
56 retrieving "invalid" cursors, i.e.
57 #top()/bottom()# from empty list, #find()# without success,
58 results in a nonvalid Cursor ( #!ok()# )
61 INVARIANTEN!
65 /// Use for list of pointers, e.g. PointerList<AbstractType*>.
66 template<class T>
67 class PointerList : public List<T>
69 public:
70 PointerList();
71 PointerList( const T& thing );
73 ///
74 virtual ~PointerList();
75 /**
76 This function deletes deletes the allocated pointers of all links.
77 #\Ref{~List}# is used to delete the links themselves.
78 */
80 protected:
81 virtual void remove( Cursor<T> me );
84 #include "list.inl"
85 #include "cursor.hh"
87 // instantiate a template: explicit instantiation.
88 #define L_instantiate(a) template class List<a>; template class Cursor<a>; \
89 template class Link<a>
90 #define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*>
92 #endif // __LIST_HH //