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