CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
SlotTable.h
Go to the documentation of this file.
1
11
12
#pragma once
13
14
#include <array>
15
#include <cstddef>
16
17
namespace
cdc::plugin_manager
{
18
19
template
<
typename
T, std::
size_t
N>
20
struct
SlotTable
{
21
std::array<T, N>
slots
{};
22
23
static
constexpr
std::size_t
capacity
() {
return
N; }
24
26
T*
lookup
(
int
id
)
27
{
28
if
(
id
<= 0 ||
static_cast<
std::size_t
>
(
id
) > N)
return
nullptr
;
29
T* s = &
slots
[
static_cast<
std::size_t
>
(id) - 1];
30
return
s->used ? s :
nullptr
;
31
}
32
37
T*
allocate
(
int
& out_id)
38
{
39
for
(std::size_t i = 0; i < N; ++i) {
40
if
(!
slots
[i].used) {
41
out_id =
static_cast<
int
>
(i + 1);
42
return
&
slots
[i];
43
}
44
}
45
out_id = 0;
46
return
nullptr
;
47
}
48
};
49
50
}
// namespace cdc::plugin_manager
cdc::plugin_manager
Definition
CapabilityChecker.h:22
cdc::plugin_manager::SlotTable
Definition
SlotTable.h:20
cdc::plugin_manager::SlotTable::capacity
static constexpr std::size_t capacity()
Definition
SlotTable.h:23
cdc::plugin_manager::SlotTable::lookup
T * lookup(int id)
1-based lookup. Returns nullptr if id is out of range or slot unused.
Definition
SlotTable.h:26
cdc::plugin_manager::SlotTable::slots
std::array< T, N > slots
Definition
SlotTable.h:21
cdc::plugin_manager::SlotTable::allocate
T * allocate(int &out_id)
Definition
SlotTable.h:37
components
plugin_manager
include
plugin_manager
SlotTable.h
Generated by
1.16.1