From: fred Date: Fri, 6 Dec 1996 00:35:42 +0000 (+0000) Subject: flower-1.0.18 X-Git-Tag: release/1.5.59~6650 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=86ad00a43a0e13571766b5aa84557c2552be4546;p=lilypond.git flower-1.0.18 --- diff --git a/flower/cursor.tcc b/flower/cursor.tcc new file mode 100644 index 0000000000..3d2116c46f --- /dev/null +++ b/flower/cursor.tcc @@ -0,0 +1,107 @@ +#ifndef CURSOR_CC +#define CURSOR_CC + +#include "cursor.hh" +#include + +template + void +Cursor::backspace() +{ + Cursor c(*this); + c--; + list_.remove( *this ); +} + +template + void +Cursor::del() +{ + Cursor c(*this); + c++; + list_.remove( *this ); + *this = c; +} + + +template +Cursor +Cursor::operator -=( int j ) +{ + while (j--) + (*this)--; + return *this; +} +template +Cursor +Cursor::operator +=( int j ) +{ + while (j++) + (*this)++; + return *this; +} + +template +Cursor +Cursor::operator +( int i ) const +{ + Cursor r = *this; + + if (i<0) + return r -(-i); + + while (i--) + r++; + + return r; +} + +template +Cursor +Cursor::operator -( int i ) const +{ + Cursor 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 +int +Cursor::operator-(Cursor rhs) const +{ + assert(rhs.list == list); + int dif = 0; + + // search from *this on further up (positive difference) + Cursor 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