destroy container along with the builders
This commit is contained in:
parent
a44b890d43
commit
4b3ed383d8
@ -118,8 +118,8 @@ namespace Ha {
|
||||
}
|
||||
|
||||
static void deleteAll() {
|
||||
List<AbstractBuilder>::exec(builders, [](AbstractBuilder* builder)
|
||||
{ delete builder; });
|
||||
builders.forEach([](AbstractBuilder* builder) { delete builder; });
|
||||
builders.empty();
|
||||
}
|
||||
};
|
||||
List<AbstractBuilder> AbstractBuilder::builders;
|
||||
|
||||
@ -51,15 +51,13 @@ namespace Mqtt {
|
||||
|
||||
void publishInit() {
|
||||
Ha::publisher = publish;
|
||||
List<Component>::exec(Component::components, [](Component* c)
|
||||
{ c->publishConfig(); });
|
||||
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
||||
AbstractBuilder::deleteAll();
|
||||
ts.deleteTask(tPublishInit);
|
||||
}
|
||||
|
||||
void publishCleanupConfig() {
|
||||
List<Component>::exec(Component::components, [](Component* c)
|
||||
{ c->publishCleanupConfig(); });
|
||||
Component::components.forEach([](Component* c) { c->publishCleanupConfig(); });
|
||||
}
|
||||
|
||||
void onMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||
|
||||
@ -4,12 +4,12 @@ template <class T>
|
||||
struct List {
|
||||
struct Container {
|
||||
T* t;
|
||||
Container* next;
|
||||
Container* next = nullptr;
|
||||
Container(T* t) : t(t) {}
|
||||
};
|
||||
|
||||
Container* first;
|
||||
Container* last;
|
||||
Container* first = nullptr;
|
||||
Container* last = nullptr;
|
||||
|
||||
void add(T* t) {
|
||||
Container* c = new Container{t};
|
||||
@ -17,10 +17,19 @@ struct List {
|
||||
last = c;
|
||||
}
|
||||
|
||||
static void exec(List list, void(*f)(T*)) {
|
||||
for (List::Container *c = list.first; c; c = c->next) {
|
||||
void forEach(void(*f)(T*)) {
|
||||
for (Container *c = first; c; c = c->next) {
|
||||
f(c->t);
|
||||
}
|
||||
}
|
||||
|
||||
void empty() {
|
||||
Container *c = first;
|
||||
while (c) {
|
||||
auto n = c->next;
|
||||
delete c;
|
||||
c = n;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user