KiCad PCB EDA Suite
intrusive_list.h
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KICAD, a free EDA CAD application.
3
*
4
* Copyright (C) 2017 CERN
5
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8
*
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, you may find one here:
21
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
* or you may search the http://www.gnu.org website for the version 2 license,
23
* or you may write to the Free Software Foundation, Inc.,
24
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25
*/
26
27
#ifndef INTRUSIVE_LIST_H
28
#define INTRUSIVE_LIST_H
29
31
template
<
class
T>
32
class
INTRUSIVE_LIST
33
{
34
public
:
35
INTRUSIVE_LIST<T>
()
36
{
37
ListClear
();
38
}
39
40
void
ListClear
()
41
{
42
m_prev
=
nullptr
;
43
m_next
=
nullptr
;
44
m_root
= (T*)
this
;
45
m_count
= 1;
46
}
47
48
T*
ListRemove
()
49
{
50
if
(
m_prev
)
51
m_prev
->m_next =
m_next
;
52
53
if
(
m_next
)
54
m_next
->m_prev =
m_prev
;
55
56
m_root
->m_count--;
57
58
T* rv =
nullptr
;
59
60
if
(
m_prev
)
61
rv =
m_prev
;
62
else
if
(
m_next
)
63
rv =
m_next
;
64
65
m_root
=
nullptr
;
66
m_prev
=
nullptr
;
67
m_next
=
nullptr
;
68
return
rv;
69
}
70
71
int
ListSize
()
const
72
{
73
return
m_root
?
m_root
->m_count : 0;
74
}
75
76
void
ListInsert
( T* item )
77
{
78
if
( !
m_root
)
79
m_root
= item;
80
81
if
(
m_next
)
82
m_next
->m_prev = item;
83
84
item->m_prev = (T*)
this
;
85
item->m_next =
m_next
;
86
item->m_root =
m_root
;
87
m_root
->m_count++;
88
89
m_next
= item;
90
}
91
92
T*
ListNext
()
const
{
return
m_next
; };
93
T*
ListPrev
()
const
{
return
m_prev
; };
94
95
private
:
96
int
m_count
;
97
T*
m_prev
;
98
T*
m_next
;
99
T*
m_root
;
100
};
101
102
#endif
/* INTRUSIVE_LIST_H */
INTRUSIVE_LIST::ListInsert
void ListInsert(T *item)
Definition:
intrusive_list.h:76
INTRUSIVE_LIST::ListPrev
T * ListPrev() const
Definition:
intrusive_list.h:93
INTRUSIVE_LIST::ListRemove
T * ListRemove()
Definition:
intrusive_list.h:48
INTRUSIVE_LIST
< A lightweight intrusive list container
Definition:
intrusive_list.h:32
INTRUSIVE_LIST::m_root
T * m_root
Definition:
intrusive_list.h:99
INTRUSIVE_LIST::m_next
T * m_next
Definition:
intrusive_list.h:98
INTRUSIVE_LIST::ListClear
void ListClear()
Definition:
intrusive_list.h:40
INTRUSIVE_LIST::ListSize
int ListSize() const
Definition:
intrusive_list.h:71
INTRUSIVE_LIST::ListNext
T * ListNext() const
Definition:
intrusive_list.h:92
INTRUSIVE_LIST::m_count
int m_count
Definition:
intrusive_list.h:93
INTRUSIVE_LIST::m_prev
T * m_prev
Definition:
intrusive_list.h:97
include
intrusive_list.h
Generated on Thu Mar 4 2021 04:14:23 for KiCad PCB EDA Suite by
1.8.15