]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/cursor.icc
release: 1.1.42
[lilypond.git] / flower / include / cursor.icc
1 /*
2   cursor.icc -- implement Cursor
3
4   source file of the Flower Library
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10
11 #ifndef CURSOR_ICC
12 #define CURSOR_ICC
13
14
15
16 #include <assert.h>
17
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 )
24 {
25   list_l_ =  (List<T> *) &list; // damn const
26   if (list.size())
27       pointer_ = p ? p : list.top_;
28   else
29       pointer_ = p;
30 }
31
32
33
34 template<class T>
35 inline
36 Cursor<T>::Cursor (const Cursor<T>& cursor) 
37 {
38   list_l_= cursor.list_l_;
39   pointer_ = cursor.pointer_;
40 }
41
42 template<class T>
43 inline T&
44 Cursor<T>::thing()
45 {
46   assert (pointer_);
47   return pointer_->thing();
48 }
49
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;
57 }
58
59 template<class T>
60 inline void
61 Cursor<T>::add (const T& th)
62 {
63   list_l_->add (th, *this);
64 }
65
66 template<class T>
67 inline void
68 Cursor<T>::insert (const T& th)
69 {
70   list_l_->insert (th, *this);
71 }
72
73 template<class T>
74 inline List<T> *
75 Cursor<T>::list_l() const
76 {
77   return list_l_;               // ugh!
78 }
79
80 template<class T>
81 inline Link<T>*
82 Cursor<T>::pointer()
83 {
84   return pointer_;
85 }
86
87 template<class T>
88 inline bool
89 Cursor<T>::backward() const
90 {
91   return (pointer_ != 0);
92 }
93
94 template<class T>
95 inline bool
96 Cursor<T>::forward() const
97 {
98   return (pointer_ != 0);
99 }
100
101 template<class T>
102 inline bool
103 Cursor<T>::ok() const
104 {
105   return (pointer_ != 0);
106 }
107 template<class T>
108 inline void
109 Cursor<T>::next() 
110 {
111   assert (pointer_);
112   pointer_ = pointer_->next();
113 }
114
115 template<class T>
116 inline Cursor<T> 
117 Cursor<T>::operator ++(int)    
118 {
119   Cursor<T> r (*this);
120   next();
121   return r;
122 }
123
124 template<class T>
125 inline void
126 Cursor<T>::previous() 
127 {
128   assert (pointer_);
129   pointer_ = pointer_->previous();
130 }
131
132 template<class T>
133 inline Cursor<T>
134 Cursor<T>::operator --(int)
135 {
136   Cursor<T> r (*this);
137   previous();
138   return r;
139 }
140
141
142 #endif // CURSOR_ICC