NEURON
htlist.cpp
Go to the documentation of this file.
1
#ifdef HAVE_CONFIG_H
2
#include <../../nrnconf.h>
3
#endif
4
/*
5
Based on Unidraw UList but UList changed to HTList (head tail list)
6
for fast insertion, deletion, iteration
7
*/
8
9
/*
10
* Copyright (c) 1990, 1991 Stanford University
11
*
12
* Permission to use, copy, modify, distribute, and sell this software and its
13
* documentation for any purpose is hereby granted without fee, provided
14
* that the above copyright notice appear in all copies and that both that
15
* copyright notice and this permission notice appear in supporting
16
* documentation, and that the name of Stanford not be used in advertising or
17
* publicity pertaining to distribution of the software without specific,
18
* written prior permission. Stanford makes no representations about
19
* the suitability of this software for any purpose. It is provided "as is"
20
* without express or implied warranty.
21
*
22
* STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
23
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
24
* IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
25
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
26
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
28
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29
*/
30
31
/*
32
* HTList implementation.
33
*/
34
35
#include <stdio.h>
36
#include <
OS/enter-scope.h
>
37
#include <
htlist.h
>
38
39
/*****************************************************************************/
40
41
HTList::HTList
(
void
*
p
) {
_next
=
this
;
_prev
=
this
;
_object
=
p
; }
42
43
HTList::~HTList
() {
44
HTList
*
next
=
_next
;
45
if
(next !=
this
&& next !=
NULL
) {
46
Remove
(
this
);
47
delete
next
;
48
}
49
}
50
51
void
HTList::Append
(
HTList
*
e
) {
52
_prev
->
_next
=
e
;
53
e->
_prev
=
_prev
;
54
e->
_next
=
this
;
55
_prev
=
e
;
56
}
57
58
void
HTList::Prepend
(
HTList
*
e
) {
59
_next
->
_prev
=
e
;
60
e->
_prev
=
this
;
61
e->
_next
=
_next
;
62
_next
=
e
;
63
}
64
65
void
HTList::Remove
(
HTList
*
e
) {
66
e->
_prev
->
_next
= e->
_next
;
67
e->
_next
->
_prev
= e->
_prev
;
68
e->
_prev
= e->
_next
=
NULL
;
69
}
70
71
void
HTList::Remove
() {
72
if
(
_prev
) {
_prev
->
_next
=
_next
; }
73
if
(
_next
) {
_next
->
_prev
=
_prev
; }
74
_prev
=
_next
=
NULL
;
75
}
76
void
HTList::RemoveAll
() {
77
while
(!
IsEmpty
()) {
78
Remove
(
First
());
79
}
80
}
81
void
HTList::Delete
(
void
*
p
) {
82
HTList
*
e
;
83
84
e =
Find
(p);
85
if
(e !=
NULL
) {
86
Remove
(e);
87
delete
e
;
88
}
89
}
90
91
HTList
*
HTList::Find
(
void
*
p
) {
92
HTList
*
e
;
93
94
for
(e =
_next
; e !=
this
; e = e->
_next
) {
95
if
(e->
_object
== p) {
96
return
e
;
97
}
98
}
99
return
NULL
;
100
}
101
102
HTList
*
HTList::operator[]
(
int
count) {
103
HTList
* pos =
First
();
104
int
i
;
105
106
for
(i = 1; i < count && pos !=
End
(); ++
i
) {
107
pos = pos->
Next
();
108
}
109
if
(i == count) {
110
return
pos;
111
}
112
return
NULL
;
113
}
HTList::Next
HTList * Next()
Definition:
htlist.h:67
HTList::End
HTList * End()
Definition:
htlist.h:66
HTList::HTList
HTList(void *=NULL)
Definition:
htlist.cpp:41
HTList::Delete
void Delete(void *)
Definition:
htlist.cpp:81
p
size_t p
Definition:
nrngsl_hc_radix2.cpp:60
htlist.h
HTList::Find
HTList * Find(void *)
Definition:
htlist.cpp:91
next
Item * next(Item *item)
Definition:
list.cpp:95
e
#define e
Definition:
passive0.cpp:24
HTList::First
HTList * First()
Definition:
htlist.h:64
HTList::_next
HTList * _next
Definition:
htlist.h:59
HTList::~HTList
virtual ~HTList()
Definition:
htlist.cpp:43
HTList::Remove
void Remove()
Definition:
htlist.cpp:71
enter-scope.h
HTList::_prev
HTList * _prev
Definition:
htlist.h:60
HTList::_object
void * _object
Definition:
htlist.h:58
HTList::operator[]
HTList * operator[](int count)
Definition:
htlist.cpp:102
HTList
Definition:
htlist.h:35
HTList::IsEmpty
bool IsEmpty()
Definition:
htlist.h:63
i
#define i
Definition:
md1redef.h:12
HTList::Append
void Append(HTList *)
Definition:
htlist.cpp:51
HTList::Prepend
void Prepend(HTList *)
Definition:
htlist.cpp:58
NULL
return NULL
Definition:
cabcode.cpp:461
HTList::RemoveAll
void RemoveAll()
Definition:
htlist.cpp:76
src
ivoc
htlist.cpp