Communication Library for Autonomous Systems
v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1
#ifndef LIST_H
2
#define LIST_H
3
4
#include <list>
5
#include <mutex>
6
7
// Simple List implementation
8
template
<
typename
T>
9
class
List
{
10
public
:
11
List
() =
default
;
12
~List
() =
default
;
13
14
void
insert
(
T
*
item
);
15
T
*
remove
();
16
bool
empty
()
const
;
17
18
private
:
19
std::list<T*> _list;
20
mutable
std::mutex _mutex;
21
};
22
23
// Simple Ordered List implementation
24
template
<
typename
T,
typename
R>
25
class
Ordered_List
{
26
public
:
27
typedef
typename
std::list<T*>::iterator
Iterator
;
28
29
Ordered_List
() =
default
;
30
~Ordered_List
() =
default
;
31
32
void
insert
(
T
*
item
);
33
void
remove
(
T
*
item
);
34
Iterator
begin
();
35
Iterator
end
();
36
bool
empty
()
const
;
37
38
private
:
39
std::list<T*> _list;
40
mutable
std::mutex _mutex;
41
};
42
43
// List implementations
44
template
<
typename
T>
45
void
List<T>::insert
(
T
*
item
) {
46
std::lock_guard<std::mutex>
lock
(_mutex);
47
_list.push_back(
item
);
48
}
49
50
template
<
typename
T>
51
T
*
List<T>::remove
() {
52
std::lock_guard<std::mutex>
lock
(_mutex);
53
if
(_list.empty()) {
54
return
nullptr
;
55
}
56
T
*
item
= _list.front();
57
_list.pop_front();
58
return
item
;
59
}
60
61
template
<
typename
T>
62
bool
List<T>::empty
()
const
{
63
std::lock_guard<std::mutex>
lock
(_mutex);
64
return
_list.empty();
65
}
66
67
// Ordered_List implementations
68
template
<
typename
T,
typename
R>
69
void
Ordered_List<T, R>::insert
(
T
*
item
) {
70
std::lock_guard<std::mutex>
lock
(_mutex);
71
_list.push_back(
item
);
72
}
73
74
template
<
typename
T,
typename
R>
75
void
Ordered_List<T, R>::remove
(
T
*
item
) {
76
std::lock_guard<std::mutex>
lock
(_mutex);
77
_list.remove(
item
);
78
}
79
80
template
<
typename
T,
typename
R>
81
typename
Ordered_List<T, R>::Iterator
Ordered_List<T, R>::begin
() {
82
return
_list.begin();
83
}
84
85
template
<
typename
T,
typename
R>
86
typename
Ordered_List<T, R>::Iterator
Ordered_List<T, R>::end
() {
87
return
_list.end();
88
}
89
90
template
<
typename
T,
typename
R>
91
bool
Ordered_List<T, R>::empty
()
const
{
92
std::lock_guard<std::mutex>
lock
(_mutex);
93
return
_list.empty();
94
}
95
96
#endif
// LIST_H
List
Definition
list.h:9
List::insert
void insert(T *item)
Definition
list.h:45
List::empty
bool empty() const
Definition
list.h:62
List::List
List()=default
List::remove
T * remove()
Definition
list.h:51
List::~List
~List()=default
Ordered_List
Definition
list.h:25
Ordered_List::begin
Iterator begin()
Definition
list.h:81
Ordered_List::insert
void insert(T *item)
Definition
list.h:69
Ordered_List::end
Iterator end()
Definition
list.h:86
Ordered_List::Ordered_List
Ordered_List()=default
Ordered_List::empty
bool empty() const
Definition
list.h:91
Ordered_List::Iterator
std::list< T * >::iterator Iterator
Definition
list.h:27
Ordered_List::remove
void remove(T *item)
Definition
list.h:75
Ordered_List::~Ordered_List
~Ordered_List()=default
db
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition
debug.h:166
Generated on Sat Jul 12 2025 20:47:36 for Communication Library for Autonomous Systems by
Doxygen
1.9.8
📁 View Source Code on GitHub
|
🐛 Report Issues
|
📖 Project Documentation