]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.18
authorfred <fred>
Fri, 6 Dec 1996 00:35:42 +0000 (00:35 +0000)
committerfred <fred>
Fri, 6 Dec 1996 00:35:42 +0000 (00:35 +0000)
flower/cursor.tcc [new file with mode: 0644]

diff --git a/flower/cursor.tcc b/flower/cursor.tcc
new file mode 100644 (file)
index 0000000..3d2116c
--- /dev/null
@@ -0,0 +1,107 @@
+#ifndef CURSOR_CC
+#define CURSOR_CC
+
+#include "cursor.hh"
+#include <assert.h>
+
+template<class T>
+ void
+Cursor<T>::backspace()
+{
+    Cursor<T> c(*this);
+    c--;        
+    list_.remove( *this );
+}
+
+template<class T>
+ void
+Cursor<T>::del()
+{
+    Cursor<T> c(*this);
+    c++;
+    list_.remove( *this );    
+    *this = c;
+}
+
+
+template<class T>
+Cursor<T> 
+Cursor<T>::operator -=( int j )    
+{
+    while (j--)
+       (*this)--;
+    return *this;
+}
+template<class T>
+Cursor<T> 
+Cursor<T>::operator +=( int j )    
+{
+    while (j++)
+       (*this)++;
+    return *this;
+}
+
+template<class T>
+Cursor<T> 
+Cursor<T>::operator +( int i ) const    
+{
+    Cursor<T> r = *this;
+
+    if (i<0)
+       return r -(-i);
+
+    while (i--)
+       r++;
+
+    return r;
+}
+
+template<class T>
+Cursor<T>
+Cursor<T>::operator -( int i ) const
+{
+    Cursor<T> r = *this;
+    if (i<0)
+       return r +(-i);
+
+    while (i--)
+       r--;
+    
+    return r;
+}
+/*
+  warning:  can't use Cursor::operator == (Cursor),
+  since it uses Cursor::operator-(Cursor)
+ */
+template<class T>
+int
+Cursor<T>::operator-(Cursor<T> rhs) const
+{
+    assert(rhs.list == list);
+    int dif = 0;
+
+    // search from *this on further up (positive difference)
+    Cursor<T> c(*this);
+    while (c.ok() && c.pointer_ != rhs.pointer_) {
+       c--;
+       dif++;
+    }
+    
+    if (c.ok())
+       goto gotcha;            // so, sue me.
+
+    // search in direction of bottom. (negative diff)
+    dif =0;
+    c=*this;    
+    while (c.ok() && c.pointer_ !=rhs.pointer_) {
+       dif --;
+       c++;
+    }
+    assert(c.ok());
+
+gotcha:
+    assert((*this - dif).pointer_ == c.pointer_);
+    return dif;
+}
+
+#endif