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