]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.hh
release: 0.0.3
[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     int operator -(Cursor<T> op) const;
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   add and insert extend the list
90   items are always stored as copies in List, but:
91   List<String> :  copies of String stored 
92   List<String*> : copies of String* stored!
93
94     the operations add and insert actually delegate the work to List class.
95  */
96
97
98
99
100
101
102 /*
103   comparations.
104   */
105
106
107
108
109
110
111
112
113
114 #include "compare.hh"
115
116 template<class T>
117 inline  int cursor_compare(Cursor<T> a,Cursor<T>b)
118 {
119     return b-a;
120 }
121
122 template_instantiate_compare(Cursor<T>, cursor_compare, template<class T>);
123
124 #include "pcursor.hh"
125 #include "list.hh"
126 #include "cursor.inl"
127
128 #endif // __CURSOR_HH //