]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.inl
release: 0.0.2
[lilypond.git] / flower / cursor.inl
1  // cursor.inl -*-c++-*-
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_;
14     //list.top().pointer_; // ARGH! recursion.
15     else
16         pointer_ = pointer;
17 }
18
19 template<class T>
20 inline
21 Cursor<T>::Cursor( const Cursor<T>& cursor ) :
22     list_( cursor.list_ )
23 {
24     pointer_ = cursor.pointer_;
25 }
26
27 template<class T>
28 inline T&
29 Cursor<T>::operator *()
30 {
31     assert( pointer_ );
32     return pointer_->thing();
33 }
34
35 template<class T>
36 Cursor<T>
37 Cursor<T>::operator =( const Cursor<T>& c )
38 {   
39     assert( &list_ == &c.list_ );
40     pointer_ = c.pointer_;
41     return *this;
42 }
43
44 template<class T>
45 inline void
46 Cursor<T>::add( const T& thing )
47 {
48     list_.add( thing, *this );
49 }
50
51 template<class T>
52 inline void
53 Cursor<T>::insert( const T& thing )
54 {
55     list_.insert( thing, *this );
56 }
57
58 template<class T>
59 inline void
60 Cursor<T>::backspace()
61 {
62     Cursor<T> c(*this);
63     c--;        
64     list_.remove( *this );
65 }
66
67 template<class T>
68 inline void
69 Cursor<T>::del()
70 {
71     Cursor<T> c(*this);
72     c++;
73     list_.remove( *this );    
74     *this = c;
75 }
76
77 template<class T>
78 inline const 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()
94 {
95     return ( pointer_ != 0 );
96 }
97
98 template<class T>
99 inline bool
100 Cursor<T>::forward()
101 {
102     return ( pointer_ != 0 );
103 }
104
105 template<class T>
106 inline bool
107 Cursor<T>::ok()
108 {
109     return ( pointer_ != 0 );
110 }
111
112 #endif