destroy container along with the builders
This commit is contained in:
parent
4b4f543117
commit
26b11129a8
@ -118,8 +118,8 @@ namespace Ha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void deleteAll() {
|
static void deleteAll() {
|
||||||
List<AbstractBuilder>::exec(builders, [](AbstractBuilder* builder)
|
builders.forEach([](AbstractBuilder* builder) { delete builder; });
|
||||||
{ delete builder; });
|
builders.empty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
List<AbstractBuilder> AbstractBuilder::builders;
|
List<AbstractBuilder> AbstractBuilder::builders;
|
||||||
|
|||||||
@ -51,15 +51,13 @@ namespace Mqtt {
|
|||||||
|
|
||||||
void publishInit() {
|
void publishInit() {
|
||||||
Ha::publisher = publish;
|
Ha::publisher = publish;
|
||||||
List<Component>::exec(Component::components, [](Component* c)
|
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
||||||
{ c->publishConfig(); });
|
|
||||||
AbstractBuilder::deleteAll();
|
AbstractBuilder::deleteAll();
|
||||||
ts.deleteTask(tPublishInit);
|
ts.deleteTask(tPublishInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishCleanupConfig() {
|
void publishCleanupConfig() {
|
||||||
List<Component>::exec(Component::components, [](Component* c)
|
Component::components.forEach([](Component* c) { c->publishCleanupConfig(); });
|
||||||
{ c->publishCleanupConfig(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
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 List {
|
||||||
struct Container {
|
struct Container {
|
||||||
T* t;
|
T* t;
|
||||||
Container* next;
|
Container* next = nullptr;
|
||||||
Container(T* t) : t(t) {}
|
Container(T* t) : t(t) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Container* first;
|
Container* first = nullptr;
|
||||||
Container* last;
|
Container* last = nullptr;
|
||||||
|
|
||||||
void add(T* t) {
|
void add(T* t) {
|
||||||
Container* c = new Container{t};
|
Container* c = new Container{t};
|
||||||
@ -17,10 +17,19 @@ struct List {
|
|||||||
last = c;
|
last = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exec(List list, void(*f)(T*)) {
|
void forEach(void(*f)(T*)) {
|
||||||
for (List::Container *c = list.first; c; c = c->next) {
|
for (Container *c = first; c; c = c->next) {
|
||||||
f(c->t);
|
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