// SPDX-License-Identifier: MIT #ifndef VALUE_DESCRIPTIONS_H #define VALUE_DESCRIPTIONS_H #include #include #include #include using RawSignalValue = std::variant; /** Canonical keys: negative int64_t, nonnegative uint64_t. */ inline RawSignalValue NormalizeValueKey(const RawSignalValue &value) { if (const std::int64_t *number = std::get_if(&value)) { if (*number >= 0) return static_cast(*number); } return value; } using ValueDescriptions = std::map; /** Returns a borrowed string, or nullptr; never converts integers to double. */ inline const std::string *FindValueDescription(const ValueDescriptions &descriptions, const RawSignalValue &rawValue) { const ValueDescriptions::const_iterator found = descriptions.find(NormalizeValueKey(rawValue)); return found == descriptions.end() ? nullptr : &found->second; } #endif