]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.cc
release: 0.0.17
[lilypond.git] / flower / cursor.cc
1 #ifndef CURSOR_CC
2 #define CURSOR_CC
3
4 #include "cursor.hh"
5 #include <assert.h>
6
7 template<class T>
8  void
9 Cursor<T>::backspace()
10 {
11     Cursor<T> c(*this);
12     c--;        
13     list_.remove( *this );
14 }
15
16 template<class T>
17  void
18 Cursor<T>::del()
19 {
20     Cursor<T> c(*this);
21     c++;
22     list_.remove( *this );    
23     *this = c;
24 }
25
26
27 template<class T>
28 Cursor<T> 
29 Cursor<T>::operator -=( int j )    
30 {
31     while (j--)
32         (*this)--;
33     return *this;
34 }
35 template<class T>
36 Cursor<T> 
37 Cursor<T>::operator +=( int j )    
38 {
39     while (j++)
40         (*this)++;
41     return *this;
42 }
43
44 template<class T>
45 Cursor<T> 
46 Cursor<T>::operator +( int i ) const    
47 {
48     Cursor<T> r = *this;
49
50     if (i<0)
51         return r -(-i);
52
53     while (i--)
54         r++;
55
56     return r;
57 }
58
59 template<class T>
60 Cursor<T>
61 Cursor<T>::operator -( int i ) const
62 {
63     Cursor<T> r = *this;
64     if (i<0)
65         return r +(-i);
66
67     while (i--)
68         r--;
69     
70     return r;
71 }
72 /*
73   warning:  can't use Cursor::operator == (Cursor),
74   since it uses Cursor::operator-(Cursor)
75  */
76 template<class T>
77 int
78 Cursor<T>::operator-(Cursor<T> rhs) const
79 {
80     assert(rhs.list == list);
81     int dif = 0;
82
83     // search from *this on further up (positive difference)
84     Cursor<T> c(*this);
85     while (c.ok() && c.pointer_ != rhs.pointer_) {
86         c--;
87         dif++;
88     }
89     
90     if (c.ok())
91         goto gotcha;            // so, sue me.
92
93     // search in direction of bottom. (negative diff)
94     dif =0;
95     c=*this;    
96     while (c.ok() && c.pointer_ !=rhs.pointer_) {
97         dif --;
98         c++;
99     }
100     assert(c.ok());
101
102 gotcha:
103     assert((*this - dif).pointer_ == c.pointer_);
104     return dif;
105 }
106
107 #endif