]> git.donarmstrong.com Git - lilypond.git/blob - flower/cursor.inl
release: 0.0.4
[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( const List<T>& list, Link<T>* pointer ) : 
10     list_((List<T>&) list )
11 {
12     if ( list.size() )
13         pointer_ = pointer ? pointer : list.top_;
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>::backspace()
60 {
61     Cursor<T> c(*this);
62     c--;        
63     list_.remove( *this );
64 }
65
66 template<class T>
67 inline void
68 Cursor<T>::del()
69 {
70     Cursor<T> c(*this);
71     c++;
72     list_.remove( *this );    
73     *this = c;
74 }
75
76 template<class T>
77 inline const List<T>&
78 Cursor<T>::list() const
79 {
80     return list_;
81 }
82
83 template<class T>
84 inline Link<T>*
85 Cursor<T>::pointer()
86 {
87     return pointer_;
88 }
89
90 template<class T>
91 inline bool
92 Cursor<T>::backward()
93 {
94     return ( pointer_ != 0 );
95 }
96
97 template<class T>
98 inline bool
99 Cursor<T>::forward()
100 {
101     return ( pointer_ != 0 );
102 }
103
104 template<class T>
105 inline bool
106 Cursor<T>::ok()
107 {
108     return ( pointer_ != 0 );
109 }
110
111 #endif