mirs_esp_pio
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
Registry.hpp
[詳解]
1
#pragma once
2
#include <stddef.h>
3
#include <stdint.h>
4
13
template
<
typename
Plugin,
typename
Data,
size_t
Capacity>
14
class
Registry
{
15
public
:
21
bool
add
(Plugin *plugin, uint32_t divider = 1) {
22
if
(plugin ==
nullptr
|| count_ >= Capacity || divider == 0) {
23
return
false
;
24
}
25
entries_[count_] = Entry{plugin, divider, 0,
false
};
26
++count_;
27
return
true
;
28
}
29
31
size_t
size
()
const
{
return
count_; }
32
35
const
char
*
name
(
size_t
index)
const
{
36
return
index < count_ ? entries_[index].plugin->name() :
""
;
37
}
38
41
bool
isEnabled
(
size_t
index)
const
{
42
return
index < count_ && entries_[index].enabled;
43
}
44
49
bool
beginPlugin
(
size_t
index) {
50
if
(index >= count_) {
51
return
false
;
52
}
53
Entry &entry = entries_[index];
54
entry.enabled = entry.plugin->begin();
55
return
entry.enabled;
56
}
57
61
void
updateAll
(Data &data) {
62
for
(
size_t
i = 0; i < count_; ++i) {
63
Entry &entry = entries_[i];
64
if
(!entry.enabled) {
65
continue
;
66
}
67
if
(++entry.counter < entry.divider) {
68
continue
;
69
}
70
entry.counter = 0;
71
entry.plugin->update(data);
72
}
73
}
74
75
private
:
76
struct
Entry {
77
Plugin *plugin =
nullptr
;
78
uint32_t divider = 1;
79
uint32_t counter = 0;
80
bool
enabled =
false
;
81
};
82
Entry entries_[Capacity] = {};
83
size_t
count_ = 0;
84
};
Registry
固定容量のタスク内プラグインレジストリ。ヒープ不使用。
定義
Registry.hpp:14
Registry::size
size_t size() const
定義
Registry.hpp:31
Registry::beginPlugin
bool beginPlugin(size_t index)
プラグインを開始する。失敗時は無効化される。
定義
Registry.hpp:49
Registry::name
const char * name(size_t index) const
定義
Registry.hpp:35
Registry::updateAll
void updateAll(Data &data)
有効なプラグインのうち周期到来分を更新する。
定義
Registry.hpp:61
Registry::isEnabled
bool isEnabled(size_t index) const
定義
Registry.hpp:41
Registry::add
bool add(Plugin *plugin, uint32_t divider=1)
プラグインを登録する。
定義
Registry.hpp:21
lib
Registry
Registry.hpp
構築:
1.18.0