]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.hh
release: 0.0.2
[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     
74     ///
75     void backspace();
76
77     /// 
78     void del();
79     
80     /// access the list this came from
81     const List<T>& list() const ;
82     Link<T>* pointer();
83     
84 private:
85     List<T>& list_;
86     Link<T>* pointer_;
87 };
88
89
90 /** 
91   add and insert extend the list
92   items are always stored as copies in List, but:
93   List<String> :  copies of String stored 
94   List<String*> : copies of String* stored!
95
96     the operations add and insert actually delegate the work to List class.
97  */
98
99
100
101 /// cursor which feels like a pointer
102 template<class T>
103 struct PCursor : public Cursor<T> {
104
105     /// make cursor with #no# items back
106     PCursor<T> operator -( int no) const {
107         return PCursor<T> (Cursor<T>::operator-(no));
108     }
109
110     /// make cursor with #no# items further
111     PCursor<T> operator +( int no) const {
112         return PCursor<T> (Cursor<T>::operator+(no));
113     }
114     PCursor(List<T> & l) : Cursor<T> (l) {}
115
116     PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { }
117     T operator ->() { return  *(*this); }
118
119 };
120 /**
121  HWN: I'd like an operator->(), so here it is.
122
123  Cursor to go with pointer list.
124  */
125
126 #include "list.hh"
127 #include "cursor.inl"
128
129 #endif // __CURSOR_HH //