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