From: fred Date: Sat, 5 Oct 1996 14:23:56 +0000 (+0000) Subject: Import of flower-1.0.0 X-Git-Tag: release/1.5.59~7159^2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ef802aa90c375b6a5f5aaab5937a6cfcc18d7435;p=lilypond.git Import of flower-1.0.0 --- diff --git a/flower/cursor.hh b/flower/cursor.hh new file mode 100644 index 0000000000..b053591dd4 --- /dev/null +++ b/flower/cursor.hh @@ -0,0 +1,125 @@ +// cursor.hh + +#ifndef __CURSOR_HH +#define __CURSOR_HH + +#include "link.hh" +template class List; + +/// +template +class Cursor +{ + public: + Cursor( List& list, Link* pointer = 0 ); + Cursor( const Cursor& cursor ); + + /// return current T + T& operator *(); + operator T() { return *(*this); } + Cursor operator =( const Cursor& c ); + + /// make cursor with #no# items back + Cursor operator -( int no) const; + + /// make cursor with #no# items further + Cursor operator +( int no) const; + + Cursor operator -=(int); + Cursor operator +=(int); + + /// return current and move one down + Cursor operator ++( int ); + + /// return current and move one up + Cursor operator --( int ); + + /// point to link? + bool ok(); + + /// ++ items left? + bool forward(); + + /// -- items left? + bool backward(); + + /// put (copy) after me in List + void add( const T& thing ); + /** + analogously to editor. ok() interpreted as at end + of line. + + PRE: !ok, POST: added to bottom() + + PRE: ok, POST: added after me + + cursor points to same object, cursor.next() is newly added + object. + */ + + /// put (copy) before me in List + void insert( const T& thing ); + /** + analogously to editor. ok() interpreted as at begin of + line. + + PRE: !ok, POST: add to top() + + PRE: ok, POST: add before me + + cursor points to same object, cursor.previous() + is newly inserted object. + */ + /// remove and cleanup Link // HWN: backspace or del? + void remove(); + + /// access the list this came from + const List& list() const ; + Link* pointer(); + +private: + List& list_; + Link* pointer_; +}; + + +/** + add and insert extend the list + items are always stored as copies in List, but: + List : copies of String stored + List : copies of String* stored! + + the operations add and insert actually delegate the work to List class. + */ + + + +/// cursor which feels like a pointer +template +struct PCursor : public Cursor { + + /// make cursor with #no# items back + PCursor operator -( int no) const { + return PCursor (Cursor::operator-(no)); + } + + /// make cursor with #no# items further + PCursor operator +( int no) const { + return PCursor (Cursor::operator+(no)); + } + PCursor(List & l) : Cursor (l) {} + + PCursor( const Cursor& cursor ) : Cursor(cursor) { } + T operator ->() { return *(*this); } + +}; +/** + HWN: I'd like an operator->(), so here it is. + + Cursor to go with pointer list. + */ + +#include "list.hh" +#include "cursor.inl" + +#endif // __CURSOR_HH //