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