DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
value_descriptions.h
1// SPDX-License-Identifier: MIT
2#ifndef VALUE_DESCRIPTIONS_H
3#define VALUE_DESCRIPTIONS_H
4
5#include <cstdint>
6#include <map>
7#include <string>
8#include <variant>
9
10using RawSignalValue = std::variant<std::int64_t, std::uint64_t>;
11
13inline RawSignalValue NormalizeValueKey(const RawSignalValue &value) {
14 if (const std::int64_t *number = std::get_if<std::int64_t>(&value)) {
15 if (*number >= 0)
16 return static_cast<std::uint64_t>(*number);
17 }
18 return value;
19}
20
21using ValueDescriptions = std::map<RawSignalValue, std::string>;
22
24inline const std::string *FindValueDescription(const ValueDescriptions &descriptions,
25 const RawSignalValue &rawValue) {
26 const ValueDescriptions::const_iterator found = descriptions.find(NormalizeValueKey(rawValue));
27 return found == descriptions.end() ? nullptr : &found->second;
28}
29
30#endif