DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
definition_key.h
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 Dim Himro
3
4#ifndef DEFINITION_KEY_H
5#define DEFINITION_KEY_H
6
7#include <cstdint>
8#include <functional>
9#include <string>
10#include <utility>
11
15struct FrameKey {
16 std::uint32_t canId = 0U;
17 bool isExtended = false;
19 FrameKey() = default;
20
22 FrameKey(std::uint32_t id, bool extended)
23 : canId(id), isExtended(extended) {
24 }
25
27 bool operator==(const FrameKey &other) const {
28 return (canId == other.canId) && (isExtended == other.isExtended);
29 }
30};
31
37 std::size_t operator()(const FrameKey &key) const {
38 const std::size_t a = static_cast<std::size_t>(key.canId);
39 const std::size_t b = key.isExtended ? 1U : 0U;
40 return (a * 1315423911U) ^ b;
41 }
42};
43
45struct SignalKey {
47 std::string name;
49 SignalKey() = default;
51 SignalKey(FrameKey frameKey, std::string signalName)
52 : frame(frameKey), name(std::move(signalName)) {
53 }
54
56 bool operator==(const SignalKey &other) const {
57 return frame == other.frame && name == other.name;
58 }
59};
60
64 std::size_t operator()(const SignalKey &key) const {
65 return FrameKeyHasher()(key.frame) ^ (std::hash<std::string>()(key.name) << 1U);
66 }
67};
68
69#endif /* DEFINITION_KEY_H */
Hasher for frame key.
std::size_t operator()(const FrameKey &key) const
Hash the logical identity fields.
Stable frame identifier: normalized CAN ID and frame type.
std::uint32_t canId
FrameKey(std::uint32_t id, bool extended)
Create a key from a normalized identifier and frame type.
bool isExtended
bool operator==(const FrameKey &other) const
Compare all logical identity fields.
Hasher for stable signal keys.
std::size_t operator()(const SignalKey &key) const
Hash the logical identity fields.
bool operator==(const SignalKey &other) const
Compare all logical identity fields.
FrameKey frame
SignalKey(FrameKey frameKey, std::string signalName)
Create a signal key from its frame identity and name.
std::string name