Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
mia
mesh
clist.hh
Go to the documentation of this file.
1
/* -*- mia-c++ -*-
2
*
3
* This file is part of MIA - a toolbox for medical image analysis
4
* Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
5
*
6
* MIA is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
#ifndef CLIST_HH
22
#define CLIST_HH
23
24
#include <cassert>
25
26
NS_MIA_BEGIN
27
28
template
<
class
T>
29
class
clist
{
30
31
public
:
32
typedef
T
value_type
;
33
34
35
struct
node
{
36
T
value
;
37
node
*
prev
;
38
node
*
succ
;
39
node
(T v,
node
*p,
node
*s):
40
value
(v),
prev
(p),
succ
(s)
41
{
42
}
43
44
T&
operator *
() {
45
return
value
;
46
}
47
const
T&
operator *
()
const
{
48
return
value
;
49
}
50
51
52
};
53
54
typedef
node
*
iterator
;
55
typedef
const
node
*
const_iterator
;
56
57
58
clist
(): m_head(NULL){
59
60
}
61
~clist
() {
62
if
(m_head != NULL) {
63
node
*head = m_head;
64
while
(head != head->
succ
)
65
remove
(head->
succ
);
66
delete
m_head;
67
}
68
}
69
70
iterator
begin
() {
71
return
m_head;
72
}
73
74
iterator
end
() {
75
return
m_head;
76
}
77
78
const_iterator
begin
()
const
{
79
return
m_head;
80
}
81
82
const_iterator
end
()
const
{
83
return
m_head;
84
}
85
86
87
void
remove
(
node
*n){
88
if
(n->prev != n) {
89
n->
succ
->
prev
= n->
prev
;
90
n->
prev
->
succ
= n->
succ
;
91
if
(n == m_head) {
92
m_head = n->
prev
;
93
}
94
delete
n;
95
}
else
{
// only head left
96
assert(n == m_head);
97
delete
n;
98
m_head = NULL;
99
}
100
}
101
void
push_back
(T val)
102
{
103
if
(m_head) {
104
node
*nn =
new
node
(val, m_head, m_head->
succ
);
105
nn->
prev
->
succ
= nn;
106
nn->
succ
->
prev
= nn;
107
}
else
{
108
assert (m_head == NULL);
109
m_head =
new
node
(val,NULL,NULL);
110
m_head->
prev
= m_head->
succ
= m_head;
111
}
112
}
113
int
size
() {
114
int
s = 0;
115
if
(m_head) {
116
node
*n = m_head;
117
while
(n->
succ
!= m_head) {
118
n = n->
succ
;
119
++s;
120
}
121
}
122
return
s;
123
}
124
private
:
125
node *m_head;
126
};
127
128
NS_MIA_END
129
130
#endif
131
132
/*
133
$Log$
134
Revision 1.3 2005/06/29 13:22:20 wollny
135
switch to version 0.7
136
137
Revision 1.1.1.1 2005/03/17 13:44:20 gerddie
138
initial import
139
140
Revision 1.2 2004/10/15 14:05:37 wollny
141
log entrys
142
143
*/
Generated on Tue Oct 15 2013 13:56:37 by
1.8.4