My Project  debian-1:4.1.1-p2+ds-4build2
LinkedList.cpp
Go to the documentation of this file.
1 #ifndef __cxxtest__LinkedList_cpp__
2 #define __cxxtest__LinkedList_cpp__
3 
4 #include <cxxtest/LinkedList.h>
5 
6 namespace 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 
145  void Link::attach( List &l )
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 
158  void Link::detach( List &l )
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__
CxxTest::List::_head
Link * _head
Definition: LinkedList.h:13
CxxTest::List::tail
Link * tail()
Definition: LinkedList.cpp:32
CxxTest::List
Definition: LinkedList.h:11
CxxTest::List::size
unsigned size() const
Definition: LinkedList.cpp:53
CxxTest::GlobalFixture::_list
static List _list
Definition: GlobalFixture.h:25
CxxTest::List::activateAll
void activateAll()
Definition: LinkedList.cpp:69
CxxTest::List::nth
Link * nth(unsigned n)
Definition: LinkedList.cpp:61
CxxTest::List::leaveOnly
void leaveOnly(const Link &link)
Definition: LinkedList.cpp:75
CxxTest::List::_tail
Link * _tail
Definition: LinkedList.h:14
CxxTest::List::head
Link * head()
Definition: LinkedList.cpp:16
l
int l
Definition: cfEzgcd.cc:93
CxxTest::List::initialize
void initialize()
Definition: LinkedList.cpp:11
List
Definition: ftmpl_list.h:20
CxxTest::List::empty
bool empty() const
Definition: LinkedList.cpp:48
CxxTest::RealSuiteDescription::_suites
static List _suites
Definition: RealDescriptions.h:78
count
int status int void size_t count
Definition: si_signals.h:59
CxxTest
Definition: Descriptions.cpp:6
LinkedList.h