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