]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.hh
b053591dd4581291e26956f2d3e0ede866188ea6
[lilypond.git] / flower / 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 ///
10 template<class T>
11 class Cursor 
12 {
13  public:
14     Cursor( List<T>& list, Link<T>* pointer = 0 );
15     Cursor( const Cursor<T>& cursor );
16     
17     /// return current T
18     T& operator *();            
19     operator T() { return  *(*this); }
20     Cursor<T> operator =( const Cursor<T>& c );
21
22     /// make cursor with #no# items back
23     Cursor<T> operator -( int no) const;
24
25     /// make cursor with #no# items further
26     Cursor<T> operator +( int no) const;
27
28     Cursor<T> operator -=(int);
29     Cursor<T> operator +=(int);
30     
31     /// return current and move one down
32     Cursor<T> operator ++( int );
33     
34     /// return current and move one up
35     Cursor<T> operator --( int ); 
36
37     /// point to link?
38     bool ok();                  
39
40     /// ++ items left?
41     bool forward();             
42
43     /// -- items left?
44     bool backward();
45
46     /// put (copy) after me in List
47     void add( const T& thing );
48     /**
49       analogously to editor. ok() interpreted as at end
50       of line.
51
52       PRE: !ok, POST: added to bottom()
53
54       PRE: ok, POST: added after me
55
56       cursor points to same object, cursor.next() is newly added
57       object.
58       */
59
60     /// put (copy) before me in List
61     void insert( const T& thing );
62     /**
63       analogously to editor. ok() interpreted as at begin of
64       line.
65       
66       PRE: !ok, POST: add to top()
67
68       PRE: ok, POST: add before me
69
70       cursor points to same object, cursor.previous()
71       is newly inserted object.
72       */
73     /// remove and cleanup Link // HWN: backspace or del?
74     void remove();              
75
76     /// access the list this came from
77     const List<T>& list() const ;
78     Link<T>* pointer();
79     
80 private:
81     List<T>& list_;
82     Link<T>* pointer_;
83 };
84
85
86 /** 
87   add and insert extend the list
88   items are always stored as copies in List, but:
89   List<String> :  copies of String stored 
90   List<String*> : copies of String* stored!
91
92     the operations add and insert actually delegate the work to List class.
93  */
94
95
96
97 /// cursor which feels like a pointer
98 template<class T>
99 struct PCursor : public Cursor<T> {
100
101     /// make cursor with #no# items back
102     PCursor<T> operator -( int no) const {
103         return PCursor<T> (Cursor<T>::operator-(no));
104     }
105
106     /// make cursor with #no# items further
107     PCursor<T> operator +( int no) const {
108         return PCursor<T> (Cursor<T>::operator+(no));
109     }
110     PCursor(List<T> & l) : Cursor<T> (l) {}
111
112     PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { }
113     T operator ->() { return  *(*this); }
114
115 };
116 /**
117  HWN: I'd like an operator->(), so here it is.
118
119  Cursor to go with pointer list.
120  */
121
122 #include "list.hh"
123 #include "cursor.inl"
124
125 #endif // __CURSOR_HH //