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