CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
client
detail
CallbackList.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include "
carla/AtomicList.h
"
10
#include "
carla/NonCopyable.h
"
11
12
#include <atomic>
13
#include <functional>
14
15
namespace
carla
{
16
namespace
client
{
17
namespace
detail
{
18
19
template
<
typename
... InputsT>
20
class
CallbackList
:
private
NonCopyable
{
21
public
:
22
23
using
CallbackType
= std::function<void(InputsT...)>;
24
25
void
Call
(InputsT... args)
const
{
26
auto
list =
_list
.Load();
27
for
(
auto
&item : *list) {
28
item.callback(args...);
29
}
30
}
31
32
size_t
Push
(
CallbackType
&&callback) {
33
auto
id
= ++
_counter
;
34
DEBUG_ASSERT
(
id
!= 0u);
35
_list
.Push(
Item
{id, std::move(callback)});
36
return
id;
37
}
38
39
void
Remove
(
size_t
id
) {
40
_list
.DeleteByValue(
id
);
41
}
42
43
void
Clear
() {
44
_list
.Clear();
45
}
46
47
private
:
48
49
struct
Item
{
50
size_t
id
;
51
CallbackType
callback
;
52
53
friend
bool
operator==
(
const
Item
&lhs,
const
Item
&rhs) {
54
return
lhs.
id
== rhs.
id
;
55
}
56
57
friend
bool
operator==
(
const
Item
&lhs,
size_t
rhs) {
58
return
lhs.
id
== rhs;
59
}
60
61
friend
bool
operator==
(
size_t
lhs,
const
Item
&rhs) {
62
return
lhs == rhs.
id
;
63
}
64
};
65
66
std::atomic_size_t
_counter
{0u};
67
68
AtomicList<Item>
_list
;
69
};
70
71
}
// namespace detail
72
}
// namespace client
73
}
// namespace carla
AtomicList.h
DEBUG_ASSERT
#define DEBUG_ASSERT(predicate)
Definition
Debug.h:66
NonCopyable.h
carla::NonCopyable::NonCopyable
NonCopyable()=default
carla::client::detail::AtomicList
Holds an atomic pointer to a list.
Definition
AtomicList.h:25
carla::client::detail::CallbackList
Definition
CallbackList.h:20
carla::client::detail::CallbackList::Remove
void Remove(size_t id)
Definition
CallbackList.h:39
carla::client::detail::CallbackList::Clear
void Clear()
Definition
CallbackList.h:43
carla::client::detail::CallbackList::Call
void Call(InputsT... args) const
Definition
CallbackList.h:25
carla::client::detail::CallbackList::_list
AtomicList< Item > _list
Definition
CallbackList.h:68
carla::client::detail::CallbackList::Push
size_t Push(CallbackType &&callback)
Definition
CallbackList.h:32
carla::client::detail::CallbackList::_counter
std::atomic_size_t _counter
Definition
CallbackList.h:66
carla::client::detail::CallbackList::CallbackType
std::function< void(InputsT...)> CallbackType
Definition
CallbackList.h:23
carla::client::detail
Definition
AtomicList.h:18
carla::client
Definition
BasicAgent.h:24
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::client::detail::CallbackList::Item
Definition
CallbackList.h:49
carla::client::detail::CallbackList::Item::callback
CallbackType callback
Definition
CallbackList.h:51
carla::client::detail::CallbackList::Item::operator==
friend bool operator==(size_t lhs, const Item &rhs)
Definition
CallbackList.h:61
carla::client::detail::CallbackList::Item::id
size_t id
Definition
CallbackList.h:50
carla::client::detail::CallbackList::Item::operator==
friend bool operator==(const Item &lhs, size_t rhs)
Definition
CallbackList.h:57
carla::client::detail::CallbackList::Item::operator==
friend bool operator==(const Item &lhs, const Item &rhs)
Definition
CallbackList.h:53
Generated by
1.18.0