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