]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/list.hh
release: 0.1.12
[lilypond.git] / flower / 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{Link_list} #<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   void junk_links();
46     
47 protected:
48   friend class Cursor<T>;
49   friend class Link<T>;
50
51   void concatenate (List<T> const &s);
52     
53   /**  make *this empty. 
54
55     POST:
56     size == 0
57       
58     WARNING:
59     contents lost, and not deleted.
60     */
61   void set_empty();
62   
63   void add (T const & thing, Cursor<T> &after_me);
64
65   /// put thing before #before_me#
66   void insert (T const & thing, Cursor<T> &before_me);
67
68   /** Remove link pointed to by me. Destructor of contents called
69     (nop for pointers)
70
71     POST
72     none;
73
74
75     WARNING: do not use #me# after calling
76     */
77   void remove (Cursor<T> me);
78    
79
80   /* ************** */
81     
82   int size_;
83   Link<T>* top_;
84   Link<T>* bottom_;
85 };
86
87 #include "list.icc"
88 #include "cursor.hh"
89
90 #endif // __LIST_HH //
91     
92    
93
94