]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.inl
release: 0.0.1
[lilypond.git] / flower / cursor.inl
1  // cursor.inl
2 #ifndef CURSOR_INL
3 #define CURSOR_INL
4 #include <assert.h>
5 //#include "list.hh"
6
7 template<class T>
8 inline
9 Cursor<T>::Cursor( List<T>& list, Link<T>* pointer ) : 
10     list_( list )
11 {
12     if ( list.size() )
13         pointer_ = pointer ? pointer : list.top().pointer_;
14     else
15         pointer_ = pointer;
16 }
17
18 template<class T>
19 inline
20 Cursor<T>::Cursor( const Cursor<T>& cursor ) :
21     list_( cursor.list_ )
22 {
23     pointer_ = cursor.pointer_;
24 }
25
26 template<class T>
27 inline T&
28 Cursor<T>::operator *()
29 {
30     assert( pointer_ );
31     return pointer_->thing();
32 }
33
34 template<class T>
35 Cursor<T>
36 Cursor<T>::operator =( const Cursor<T>& c )
37 {   
38     assert( &list_ == &c.list_ );
39     pointer_ = c.pointer_;
40     return *this;
41 }
42
43 template<class T>
44 inline void
45 Cursor<T>::add( const T& thing )
46 {
47     list_.add( thing, *this );
48 }
49
50 template<class T>
51 inline void
52 Cursor<T>::insert( const T& thing )
53 {
54     list_.insert( thing, *this );
55 }
56
57 template<class T>
58 inline void
59 Cursor<T>::remove()
60 {
61     assert( pointer_ );
62     list_.remove( *this );
63 }
64
65 template<class T>
66 inline const List<T>&
67 Cursor<T>::list() const
68 {
69     return list_;
70 }
71
72 template<class T>
73 inline Link<T>*
74 Cursor<T>::pointer()
75 {
76     return pointer_;
77 }
78
79 template<class T>
80 inline bool
81 Cursor<T>::backward()
82 {
83     return ( pointer_ != 0 );
84 }
85
86 template<class T>
87 inline bool
88 Cursor<T>::forward()
89 {
90     return ( pointer_ != 0 );
91 }
92
93 template<class T>
94 inline bool
95 Cursor<T>::ok()
96 {
97     return ( pointer_ != 0 );
98 }
99
100 #endif