destroy builders

This commit is contained in:
Nicu Hodos 2024-05-15 10:19:55 +02:00
parent 6cc142fa1d
commit 5ffe88ee82
2 changed files with 20 additions and 5 deletions

View File

@ -96,13 +96,27 @@ namespace Ha {
List<Component> Component::components;
template <class T>
struct Builder {
struct AbstractBuilder {
static List<AbstractBuilder> builders;
AbstractBuilder() {
builders.add(this);
}
static void deleteAll() {
List<AbstractBuilder>::exec(builders, [](AbstractBuilder* builder)
{ delete builder; });
}
};
List<AbstractBuilder> AbstractBuilder::builders;
template <class T = Component>
struct Builder : AbstractBuilder {
T* cmp;
Builder() {}
Builder(T* cmp) : cmp(cmp) {}
Builder(const char* id) {
Builder() : AbstractBuilder() {}
Builder(T* cmp) : AbstractBuilder(), cmp(cmp) {}
Builder(const char* id) : AbstractBuilder() {
cmp = new T{id};
}

View File

@ -68,6 +68,7 @@ namespace Mqtt {
Ha::publisher = publish;
List<Component>::exec(Component::components, [](Component* c)
{ publishComponentConfig(*c); });
AbstractBuilder::deleteAll();
ts.deleteTask(tPublishInit);
}