]> git.donarmstrong.com Git - lilypond.git/blob - flower/list.hh
release: 0.0.7
[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     List(List const&src);
16
17     /// construct empty list                
18     List();
19     
20     /// construct list from first item.  
21     List( const T& thing );
22     
23     virtual ~List();
24         
25     Cursor<T> bottom();
26
27     int size() const;
28     Cursor<T> top();
29     void OK() const; 
30  protected:
31     friend class Cursor<T>;
32     friend class Link<T>;
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