#ifndef CURSOR_CC #define CURSOR_CC #include "cursor.hh" #include template void Cursor::backspace() { Cursor c(*this); if ( c.ok() ) c--; list_.remove( *this ); } template void Cursor::del() { Cursor c(*this); if ( c.ok() ) 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