]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/cursor.icc
release: 1.0.15
[lilypond.git] / flower / include / cursor.icc
index e103c88e43a8fa5e5386b1c837b6ff4cc46bb3c9..ee1f23f2bb044272ae189eda8a21db9e1d070d0b 100644 (file)
- // cursor.icc -*-c++-*-
-#ifndef CURSOR_INL
-#define CURSOR_INL
-#include <assert.h>
+/*
+  cursor.icc -- implement Cursor
+
+  source file of the Flower Library
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+
+#ifndef CURSOR_ICC
+#define CURSOR_ICC
+
 
 
+#include <assert.h>
+
+/**
+   Initialisation of Cursor.. Set pointer and list fields.  
+ */
 template<class T>
 inline
-Cursor<T>::Cursor( const List<T>& list, Link<T>* pointer ) : 
-    list_((List<T>&) list )
+Cursor<T>::Cursor (const List<T> & list, Link<T>* p )
 {
-    if ( list.size() )
-        pointer_ = pointer ? pointer : list.top_;
-    else
-        pointer_ = pointer;
+  list_l_ =  (List<T> *) &list;        // damn const
+  if (list.size())
+      pointer_ = p ? p : list.top_;
+  else
+      pointer_ = p;
 }
 
+
+
 template<class T>
 inline
-Cursor<T>::Cursor( const Cursor<T>& cursor ) :
-    list_( cursor.list_ )
+Cursor<T>::Cursor (const Cursor<T>& cursor) 
 {
-    pointer_ = cursor.pointer_;
+  list_l_= cursor.list_l_;
+  pointer_ = cursor.pointer_;
 }
 
 template<class T>
 inline T&
 Cursor<T>::thing()
 {
-    assert( pointer_ );
-    return pointer_->thing();
+  assert (pointer_);
+  return pointer_->thing();
 }
 
 template<class T>
 Cursor<T>
-Cursor<T>::operator =( const Cursor<T>& c )
+Cursor<T>::operator =(const Cursor<T>& c)
 {   
-    assert( &list_ == &c.list_ );
-    pointer_ = c.pointer_;
-    return *this;
+  assert (list_l_ == c.list_l_);
+  pointer_ = c.pointer_;
+  return *this;
 }
 
 template<class T>
 inline void
-Cursor<T>::add( const T& th )
+Cursor<T>::add (const T& th)
 {
-    list_.add( th, *this );
+  list_l_->add (th, *this);
 }
 
 template<class T>
 inline void
-Cursor<T>::insert( const T& th )
+Cursor<T>::insert (const T& th)
 {
-    list_.insert( th, *this );
+  list_l_->insert (th, *this);
 }
 
 template<class T>
-inline  List<T>&
-Cursor<T>::list() const
+inline List<T> *
+Cursor<T>::list_l() const
 {
-    return list_;
+  return list_l_;              // ugh!
 }
 
 template<class T>
 inline Link<T>*
 Cursor<T>::pointer()
 {
-    return pointer_;
+  return pointer_;
 }
 
 template<class T>
 inline bool
-Cursor<T>::backward()
+Cursor<T>::backward() const
 {
-    return ( pointer_ != 0 );
+  return (pointer_ != 0);
 }
 
 template<class T>
 inline bool
-Cursor<T>::forward()
+Cursor<T>::forward() const
 {
-    return ( pointer_ != 0 );
+  return (pointer_ != 0);
 }
 
 template<class T>
 inline bool
-Cursor<T>::ok()
+Cursor<T>::ok() const
 {
-    return ( pointer_ != 0 );
+  return (pointer_ != 0);
+}
+template<class T>
+inline void
+Cursor<T>::next() 
+{
+  assert (pointer_);
+  pointer_ = pointer_->next();
 }
-
 
 template<class T>
 inline Cursor<T> 
-Cursor<T>::operator ++( int )    
+Cursor<T>::operator ++(int)    
+{
+  Cursor<T> r (*this);
+  next();
+  return r;
+}
+
+template<class T>
+inline void
+Cursor<T>::previous() 
 {
-    Cursor<T> r (*this);
-    assert( pointer_ );
-    pointer_ = pointer_->next();
-    return r;
+  assert (pointer_);
+  pointer_ = pointer_->previous();
 }
 
 template<class T>
 inline Cursor<T>
-Cursor<T>::operator --( int )
+Cursor<T>::operator --(int)
 {
-    Cursor<T> r (*this);
-    assert( pointer_ );
-    pointer_ = pointer_->previous();
-    return r;
+  Cursor<T> r (*this);
+  previous();
+  return r;
 }
 
-#endif
+
+#endif // CURSOR_ICC