]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.8
authorfred <fred>
Sun, 24 Nov 1996 23:14:16 +0000 (23:14 +0000)
committerfred <fred>
Sun, 24 Nov 1996 23:14:16 +0000 (23:14 +0000)
flower/cursor.cc

index 2a9f885689e57bdcfb3601bfd61603ba44abfc60..75f607dcaaefe86cfe8cbdaf5bc9b47035a38a03 100644 (file)
@@ -68,27 +68,38 @@ Cursor<T>::operator -( int i ) const
     
     return r;
 }
-
+/*
+  warning:  can't use Cursor::operator == (Cursor),
+  since it uses Cursor::operator-(Cursor)
+ */
 template<class T>
 int
-Cursor<T>::operator-(Cursor<T> c) const
+Cursor<T>::operator-(Cursor<T> rhs) const
 {
-    assert(c.list == list);
+    assert(rhs.list == list);
     int dif = 0;
-    Cursor<T> upward(c);
-    while (upward.ok() && upward.pointer_ != pointer_) {
-       upward++;
+
+    // search from *this on further up (positive difference)
+    Cursor<T> c(*this);
+    while (c.ok() && c.pointer_ != rhs.pointer_) {
+       c--;
        dif++;
     }
     
-    if (upward.ok())
-       return dif;
+    if (c.ok())
+       goto gotcha;            // so, sue me.
+
+    // search in direction of bottom. (negative diff)
     dif =0;
-    while (c.ok()&& c.pointer_ != pointer_) {
+    c=*this;    
+    while (c.ok() && c.pointer_ !=rhs.pointer_) {
        dif --;
-       c--;
+       c++;
     }
     assert(c.ok());
+
+gotcha:
+    assert((*this - dif).pointer_ == c.pointer_);
     return dif;
 }