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