My Project
Loading...
Searching...
No Matches
LinkedList.cpp
Go to the documentation of this file.
1#ifndef __cxxtest__LinkedList_cpp__
2#define __cxxtest__LinkedList_cpp__
3
5
6namespace CxxTest
7{
8 List GlobalFixture::_list = { 0, 0 };
10
12 {
13 _head = _tail = 0;
14 }
15
17 {
18 Link *l = _head;
19 while ( l && !l->active() )
20 l = l->next();
21 return l;
22 }
23
24 const Link *List::head() const
25 {
26 Link *l = _head;
27 while ( l && !l->active() )
28 l = l->next();
29 return l;
30 }
31
33 {
34 Link *l = _tail;
35 while ( l && !l->active() )
36 l = l->prev();
37 return l;
38 }
39
40 const Link *List::tail() const
41 {
42 Link *l = _tail;
43 while ( l && !l->active() )
44 l = l->prev();
45 return l;
46 }
47
48 bool List::empty() const
49 {
50 return (_head == 0);
51 }
52
53 unsigned List::size() const
54 {
55 unsigned count = 0;
56 for ( const Link *l = head(); l != 0; l = l->next() )
57 ++ count;
58 return count;
59 }
60
61 Link *List::nth( unsigned n )
62 {
63 Link *l = head();
64 while ( n -- )
65 l = l->next();
66 return l;
67 }
68
70 {
71 for ( Link *l = _head; l != 0; l = l->justNext() )
72 l->setActive( true );
73 }
74
75 void List::leaveOnly( const Link &link )
76 {
77 for ( Link *l = head(); l != 0; l = l->next() )
78 if ( l != &link )
79 l->setActive( false );
80 }
81
83 _next( 0 ),
84 _prev( 0 ),
85 _active( true )
86 {
87 }
88
90 {
91 }
92
93 bool Link::active() const
94 {
95 return _active;
96 }
97
98 void Link::setActive( bool value )
99 {
100 _active = value;
101 }
102
104 {
105 return _next;
106 }
107
109 {
110 return _prev;
111 }
112
114 {
115 Link *l = _next;
116 while ( l && !l->_active )
117 l = l->_next;
118 return l;
119 }
120
122 {
123 Link *l = _prev;
124 while ( l && !l->_active )
125 l = l->_prev;
126 return l;
127 }
128
129 const Link * Link::next() const
130 {
131 Link *l = _next;
132 while ( l && !l->_active )
133 l = l->_next;
134 return l;
135 }
136
137 const Link * Link::prev() const
138 {
139 Link *l = _prev;
140 while ( l && !l->_active )
141 l = l->_prev;
142 return l;
143 }
144
146 {
147 if ( l._tail )
148 l._tail->_next = this;
149
150 _prev = l._tail;
151 _next = 0;
152
153 if ( l._head == 0 )
154 l._head = this;
155 l._tail = this;
156 }
157
159 {
160 if ( _prev )
161 _prev->_next = _next;
162 else
163 l._head = _next;
164
165 if ( _next )
166 _next->_prev = _prev;
167 else
168 l._tail = _prev;
169 }
170};
171
172#endif // __cxxtest__LinkedList_cpp__
int l
Definition: cfEzgcd.cc:100
STATIC_INST_VAR List _suites
int status int void size_t count
Definition: si_signals.h:59
Link * head()
Definition: LinkedList.cpp:16
unsigned size() const
Definition: LinkedList.cpp:53
void leaveOnly(const Link &link)
Definition: LinkedList.cpp:75
bool empty() const
Definition: LinkedList.cpp:48
void initialize()
Definition: LinkedList.cpp:11
void activateAll()
Definition: LinkedList.cpp:69
Link * _head
Definition: LinkedList.h:13
Link * nth(unsigned n)
Definition: LinkedList.cpp:61
Link * _tail
Definition: LinkedList.h:14
Link * tail()
Definition: LinkedList.cpp:32