Closes
This commit is contained in:
1 parent
65142fdfe3
commit
e5d818d9b2
14 files changed
+393
-39
No files matched your search
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#ifndef VALUE_DESCRIPTIONS_H
|
||||
#define VALUE_DESCRIPTIONS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
using RawSignalValue = std::variant<std::int64_t, std::uint64_t>;
|
||||
|
||||
/** Canonical keys: negative int64_t, nonnegative uint64_t. */
|
||||
inline RawSignalValue NormalizeValueKey(const RawSignalValue &value) {
|
||||
if (const auto *number = std::get_if<std::int64_t>(&value)) {
|
||||
if (*number >= 0)
|
||||
return static_cast<std::uint64_t>(*number);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
using ValueDescriptions = std::map<RawSignalValue, std::string>;
|
||||
|
||||
/** Returns a borrowed string, or nullptr; never converts integers to double. */
|
||||
inline const std::string *FindValueDescription(const ValueDescriptions &descriptions,
|
||||
const RawSignalValue &rawValue) {
|
||||
const auto found = descriptions.find(NormalizeValueKey(rawValue));
|
||||
return found == descriptions.end() ? nullptr : &found->second;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user