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