]> git.donarmstrong.com Git - lilypond.git/blob - flower/list.hh
release: 0.0.2
[lilypond.git] / flower / list.hh
1 // list.hh
2
3 #ifndef __LIST_HH
4 #define __LIST_HH
5
6 class ostream;
7 template<class T> class Cursor;
8 template<class T> class Link;
9
10 /// all purpose list
11 template<class T>
12 class List
13 {
14  public:
15      /// construct empty list                
16     List(); 
17
18     /// construct list from first item.  
19     List( const T& thing );
20     
21     virtual ~List();
22         
23     Cursor<T> bottom();
24
25     int size() const;
26     Cursor<T> top();
27     void OK() const; 
28  protected:
29     friend class Cursor<T>;
30     friend class Link<T>;
31     
32     /// add after after_me
33     void add( const T& thing, Cursor<T> after_me );
34
35     /// put thing before #before_me#
36     void insert( const T& thing, Cursor<T> before_me );
37     virtual void remove( Cursor<T> me );
38     /**
39       Remove link pointed to by me.
40
41       POST
42       none; WARNING: do not use #me#.
43      */
44     int size_;
45     Link<T>* top_;
46     Link<T>* bottom_;
47 };
48 /**
49   a doubly linked list; 
50   List can be seen as all items written down on paper,
51   from top to bottom
52
53   class Cursor is used to extend List
54
55    items are always stored as copies in List, but:
56    #List<String># :  copies of #String# stored 
57    #List<String*># : copies of #String*# stored! 
58    (do not use, use \Ref{PointerList}#<String*># instead.)
59  
60    {\bf note:} 
61    retrieving "invalid" cursors, i.e. 
62    #top()/bottom()# from empty list, #find()# without success,
63     results in a nonvalid Cursor ( #!ok()# )
64
65
66     INVARIANTEN!
67 */
68
69
70 /// Use for list of pointers, e.g. PointerList<AbstractType*>.
71 template<class T>
72 class PointerList : public List<T>
73 {
74  public:
75     PointerList();
76     PointerList( const T& thing );
77
78     ///
79     virtual ~PointerList();
80     /**
81       This function deletes deletes the allocated pointers of all links. 
82       #\Ref{~List}# is used to delete the links themselves.
83       */ 
84
85  protected:
86     virtual void remove( Cursor<T> me );
87 };
88
89 #include "list.inl"
90 #include "cursor.hh"
91
92 // instantiate a template:  explicit instantiation.
93 #define L_instantiate(a)  template class List<a>; template class Cursor<a>; \
94   template class Link<a>
95 #define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*>
96
97 #endif // __LIST_HH //
98     
99    
100
101