]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.cc
release: 0.0.3
[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 Cursor<T> 
9 Cursor<T>::operator ++( int )    
10 {
11     Cursor<T> r = *this;
12     assert( pointer_ );
13     pointer_ = pointer_->next();
14     return r;
15 }
16 template<class T>
17 Cursor<T> 
18 Cursor<T>::operator -=( int j )    
19 {
20     while (j--)
21         (*this)--;
22     return *this;
23 }
24 template<class T>
25 Cursor<T> 
26 Cursor<T>::operator +=( int j )    
27 {
28     while (j++)
29         (*this)++;
30     return *this;
31 }
32
33 template<class T>
34 Cursor<T>
35 Cursor<T>::operator --( int )
36 {
37     Cursor<T> r = *this;
38     assert( pointer_ );
39     pointer_ = pointer_->previous();
40     return r;
41 }
42
43 template<class T>
44 Cursor<T> 
45 Cursor<T>::operator +( int i ) const    
46 {
47     Cursor<T> r = *this;
48
49     if (i<0)
50         return r -(-i);
51
52     while (i--)
53         r++;
54
55     return r;
56 }
57
58 template<class T>
59 Cursor<T>
60 Cursor<T>::operator -( int i ) const
61 {
62     Cursor<T> r = *this;
63     if (i<0)
64         return r +(-i);
65
66     while (i--)
67         r--;
68     
69     return r;
70 }
71
72 template<class T>
73 int
74 Cursor<T>::operator-(Cursor<T> c) const
75 {
76     assert(c.list == list);
77     int dif = 0;
78     Cursor<T> upward(c);
79     while (upward.ok() && upward.pointer_ != pointer_) {
80         upward++;
81         dif++;
82     }
83     
84     if (upward.ok())
85         return dif;
86     dif =0;
87     while (c.ok()&& c.pointer_ != pointer_) {
88         dif --;
89         c--;
90     }
91     assert(c.ok());
92     return dif;
93 }
94
95 #endif