flower-1.1.5
[lilypond.git] / flower / cursor.hh
blob0ea99037f9d4d8b48c2277c2fe81cdc492e570ea
1 // cursor.hh
3 #ifndef __CURSOR_HH
4 #define __CURSOR_HH
6 #include "link.hh"
7 template<class T> class List;
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!
15 the operations add and insert actually delegate the work to List class.
17 template<class T>
18 class Cursor
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 );
25 Cursor( const Cursor<T>& cursor );
27 T& thing();
29 /// return current T
30 T& operator *() { return thing(); }
31 operator T() { return thing(); }
32 Cursor<T> operator =( const Cursor<T>& c );
34 /// make cursor with #no# items back
35 Cursor<T> operator -( int no) const;
37 /// make cursor with #no# items further
38 Cursor<T> operator +( int no) const;
39 int operator -(Cursor<T> op) const;
40 Cursor<T> operator -=(int);
41 Cursor<T> operator +=(int);
43 /// return current and move one down
44 Cursor<T> operator ++( int );
46 /// return current and move one up
47 Cursor<T> operator --( int );
49 /// point to link?
50 bool ok();
52 /// ++ items left?
53 bool forward();
55 /// -- items left?
56 bool backward();
58 /** put (copy) after me in List.
59 analogously to editor. ok() interpreted as at end
60 of line.
62 PRE: !ok, POST: added to bottom()
64 PRE: ok, POST: added after me
66 cursor points to same object, cursor.next() is newly added
67 object.
69 void add( const T& thing );
71 /** put (copy) before me in List.
72 analogously to editor. ok() interpreted as at begin of
73 line.
75 PRE: !ok, POST: add to top()
77 PRE: ok, POST: add before me
79 cursor points to same object, cursor.previous()
80 is newly inserted object.
83 void insert( const T& thing );
84 ///
85 void backspace();
87 ///
88 void del();
90 /// access the list this came from
91 List<T>& list() const ;
92 Link<T>* pointer();
93 static int compare(Cursor<T> a,Cursor<T>b) { return a-b; }
94 private:
95 List<T>& list_;
96 Link<T>* pointer_;
101 comparisons.
103 #include "compare.hh"
106 template_instantiate_compare(Cursor<T>, Cursor<T>::compare, template<class T>);
108 #include "pcursor.hh"
109 #include "list.hh"
110 #include "cursor.inl"
111 #include "iterate.hh"
113 #endif // CURSOR_HH