]> git.donarmstrong.com Git - lilypond.git/blob - flower/lib/include/link.inl
partial: 0.0.42.pre3.hanjan
[lilypond.git] / flower / lib / include / link.inl
1 // link.inl -*-c++-*-
2 #ifndef LINK_INL
3 #define LINK_INL
4 #include <assert.h>
5 template<class T>
6 inline
7 void
8 Link<T>::OK() const
9 {
10 #ifndef NDEBUG
11     if (previous_) {
12         assert(previous_->next_ == this);
13     }
14     if (next_) {
15         assert(next_->previous_ == this);
16     }
17 #endif    
18 }
19
20 template<class T>
21 inline
22 Link<T>::Link( const T& thing ) : 
23     thing_( thing )
24 {
25     previous_ = next_ = 0;
26 }
27
28 template<class T>
29 inline
30 Link<T>::Link( Link<T>* previous, Link<T>* next, const T& thing ) : 
31     thing_( thing )
32 {
33     previous_ = previous;
34     next_ = next;
35 }
36
37 template<class T>
38 inline
39 Link<T>*
40 Link<T>::next()
41 {
42     return next_;
43 }
44
45 template<class T>
46 inline
47 Link<T>*
48 Link<T>::previous()
49 {
50     return previous_;
51 }
52
53 template<class T>
54 inline
55 void
56 Link<T>::add( const T& thing )
57 {
58     
59     Link<T>* l = new Link<T>( this, next_, thing );
60     if ( next_ )
61         next_->previous_ = l;
62     next_ = l;
63 }
64
65 template<class T>
66 inline void
67 Link<T>::insert( const T& thing )
68 {
69     //    Link<T>* l = new Link<T>( next_, this, thing );
70                                 // bugfix hwn 16/9/96
71     Link<T>* l = new Link<T>( previous_, this, thing );
72     if ( previous_ )
73         previous_->next_ = l;
74     previous_ = l;
75 }
76
77 /*
78     don't forget to adjust #l#'s top_ and bottom_.
79     */
80 template<class T>
81 inline void
82 Link<T>::remove(List<T> &l)
83 {
84     if ( previous_ ) 
85         previous_->next_ = next_;
86     else 
87         l.top_ = next_;
88
89     if ( next_ )
90         next_->previous_ = previous_;
91     else
92         l.bottom_ = previous_;
93 }
94
95 template<class T>
96 inline
97 T&
98 Link<T>::thing()
99 {
100     return thing_;
101 }
102 #endif