lilypond-1.4.3
[lilypond.git] / flower / include / cursor.icc
blob90e64a608f0a2cac93d898899361c2fe90f9af1e
1 /*
2   cursor.icc -- implement Cursor
4   source file of the Flower Library
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
11 #ifndef CURSOR_ICC
12 #define CURSOR_ICC
16 #include <assert.h>
18 /**
19    Initialisation of Cursor.. Set pointer and list fields.  
20  */
21 template<class T>
22 inline
23 Cursor<T>::Cursor (const List<T> & list, Link<T>* p )
25   list_l_ =  (List<T> *) &list; // damn const
26   if (list.size())
27       pointer_ = p ? p : list.top_;
28   else
29       pointer_ = p;
34 template<class T>
35 inline
36 Cursor<T>::Cursor (const Cursor<T>& cursor) 
38   list_l_= cursor.list_l_;
39   pointer_ = cursor.pointer_;
42 template<class T>
43 inline T&
44 Cursor<T>::thing()
46   assert (pointer_);
47   return pointer_->thing();
50 template<class T>
51 Cursor<T>
52 Cursor<T>::operator =(const Cursor<T>& c)
53 {   
54   assert (list_l_ == c.list_l_);
55   pointer_ = c.pointer_;
56   return *this;
59 template<class T>
60 inline void
61 Cursor<T>::add (const T& th)
63   list_l_->add (th, *this);
66 template<class T>
67 inline void
68 Cursor<T>::insert (const T& th)
70   list_l_->insert (th, *this);
73 template<class T>
74 inline List<T> *
75 Cursor<T>::list_l() const
77   return list_l_;               // ugh!
80 template<class T>
81 inline Link<T>*
82 Cursor<T>::pointer()
84   return pointer_;
87 template<class T>
88 inline bool
89 Cursor<T>::backward() const
91   return (pointer_ != 0);
94 template<class T>
95 inline bool
96 Cursor<T>::forward() const
98   return (pointer_ != 0);
101 template<class T>
102 inline bool
103 Cursor<T>::ok() const
105   return (pointer_ != 0);
107 template<class T>
108 inline void
109 Cursor<T>::next() 
111   assert (pointer_);
112   pointer_ = pointer_->next();
115 template<class T>
116 inline Cursor<T> 
117 Cursor<T>::operator ++(int)    
119   Cursor<T> r (*this);
120   next();
121   return r;
124 template<class T>
125 inline void
126 Cursor<T>::previous() 
128   assert (pointer_);
129   pointer_ = pointer_->previous();
132 template<class T>
133 inline Cursor<T>
134 Cursor<T>::operator --(int)
136   Cursor<T> r (*this);
137   previous();
138   return r;
142 #endif // CURSOR_ICC