]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/cursor.icc
release: 0.0.53
[lilypond.git] / flower / include / cursor.icc
1 /*
2   cursor.icc -- implement Cursor
3
4   source file of the Flower Library
5
6   (c) 1997 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
112
113 template<class T>
114 inline Cursor<T> 
115 Cursor<T>::operator ++( int )    
116 {
117     Cursor<T> r (*this);
118     assert( pointer_ );
119     pointer_ = pointer_->next();
120     return r;
121 }
122
123 template<class T>
124 inline Cursor<T>
125 Cursor<T>::operator --( int )
126 {
127     Cursor<T> r (*this);
128     assert( pointer_ );
129     pointer_ = pointer_->previous();
130     return r;
131 }
132
133
134 #endif // CURSOR_ICC