use inline for static members - avoid declaring them outside of class

This commit is contained in:
Nicu Hodos 2025-01-10 13:33:58 +01:00
parent a3b8b8a65d
commit ab11cdacd8
2 changed files with 6 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "ha-mqtt",
"version": "1.4.1",
"version": "1.4.2",
"description": "Home Assistant classes for integration with MQTT auto discovery",
"repository": {
"type": "git",

View File

@ -78,7 +78,7 @@ namespace Ha {
const char* entityCategory = nullptr;
const char* deviceClass = nullptr;
DeviceConfig* mainDevice = nullptr;
static List<Component> components;
inline static List<Component> components;
bool multiValueComponent = false;
Component(const char* id, const char* name, const char* type) : id(id), type(type), name(name) {
@ -133,7 +133,7 @@ namespace Ha {
struct Command : Config {
bool retain = false;
static unordered_map<string, Command*> mapCommandTopics;
inline static unordered_map<string, Command*> mapCommandTopics;
Command(Component* cmp, onMessage f) : f(f), cmp(cmp) {
snprintf(commandTopic, sizeof(commandTopic), BASE_TOPIC"/set", cmp->type, MAIN_DEVICE_ID, cmp->id);
@ -185,7 +185,7 @@ namespace Ha {
};
struct StatefulCommand : Command, State {
static unordered_map<string, Command*> mapRestoreStateTopics;
inline static unordered_map<string, Command*> mapRestoreStateTopics;
StatefulCommand(Component* cmp, onMessage f) : Command(cmp, f), State(cmp) {}
@ -248,7 +248,7 @@ namespace Ha {
const char* unitMeasure = nullptr;
const char* valueTemplate = nullptr;
unsigned int precision = 2;
static unordered_map<string, Sensor*> mapSensors;
inline static unordered_map<string, Sensor*> mapSensors;
Sensor(const char* name, const char* id) : Component(id, name, "sensor"), State(this) {
withStateTopic();
@ -307,7 +307,7 @@ namespace Ha {
};
struct AbstractBuilder {
static List<AbstractBuilder> builders;
inline static List<AbstractBuilder> builders;
static void deleteAll() {
builders.forEach([](AbstractBuilder* builder) { delete builder; });
@ -422,10 +422,4 @@ namespace Ha {
return *this;
}
};
List<Component> Component::components;
List<AbstractBuilder> AbstractBuilder::builders;
unordered_map<string, Command*> Command::mapCommandTopics;
unordered_map<string, Sensor*> Sensor::mapSensors;
unordered_map<string, Command*> StatefulCommand::mapRestoreStateTopics;
}