]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/include/cursor.hh
partial: 0.0.42.pre3.hanjan
[lilypond.git] / flower / lib / include / cursor.hh
1 // cursor.hh
2
3 #ifndef __CURSOR_HH
4 #define __CURSOR_HH
5
6 #include "link.hh"
7 template<class T> class List;
8
9 /**  iterator to List.  
10   add and insert extend the list
11   items are always stored as copies in List, but:
12   List<String> :  copies of String stored 
13   List<String*> : copies of String* stored!
14
15     the operations add and insert actually delegate the work to List class.
16  */
17 template<class T>
18 class Cursor 
19 {
20  public:
21     /** create cursor, set at top. The const part isn't true, actually, #list#
22       surely isn't const, but I get tired of the warning messages.  */
23     Cursor( const List<T>& list, Link<T>* pointer = 0 );
24     
25     Cursor( const Cursor<T>& cursor );
26
27     T& thing();
28
29     /// return current T
30     T& operator *() { return thing(); }
31     operator T() { return thing(); }
32     Cursor<T> operator =( const Cursor<T>& c );
33
34     /// make cursor with #no# items back
35     Cursor<T> operator -( int no) const;
36
37     /// make cursor with #no# items further
38     Cursor<T> operator +( int no) const;
39     int operator -(Cursor<T> op) const;
40     Cursor<T> operator -=(int);
41     Cursor<T> operator +=(int);
42     
43     /// return current and move one down
44     Cursor<T> operator ++( int );
45     
46     /// return current and move one up
47     Cursor<T> operator --( int ); 
48
49     /// point to link?
50     bool ok();                  
51
52     /// ++ items left?
53     bool forward();             
54
55     /// -- items left?
56     bool backward();
57
58     /**  put (copy) after me in List. 
59       analogously to editor. ok() interpreted as at end
60       of line.
61
62       PRE: !ok, POST: added to bottom()
63
64       PRE: ok, POST: added after me
65
66       cursor points to same object, cursor.next() is newly added
67       object.
68       */
69     void add( const T& thing );
70
71     /**  put (copy) before me in List. 
72       analogously to editor. ok() interpreted as at begin of
73       line.
74       
75       PRE: !ok, POST: add to top()
76
77       PRE: ok, POST: add before me
78
79       cursor points to same object, cursor.previous()
80       is newly inserted object.
81       */
82     
83     void insert( const T& thing );
84     ///
85     void backspace();
86
87     /// 
88     void del();
89     
90     /// access the list this came from
91     List<T>& list() const ;
92     Link<T>* pointer();
93     static   int compare(Cursor<T> a,Cursor<T>b) { return a-b; }
94 private:
95     List<T>& list_;
96     Link<T>* pointer_;
97 };
98
99
100 /*
101   comparisons.
102   */
103 #include "compare.hh"
104
105
106 template_instantiate_compare(Cursor<T>, Cursor<T>::compare, template<class T>);
107
108 #include "pcursor.hh"
109 #include "list.hh"
110 #include "cursor.inl"
111 #include "iterate.hh"
112
113 #endif // CURSOR_HH