Closes #14
This commit is contained in:
1 parent
51fcdb88ac
commit
0708316a37
155 files changed
+5190
-2691
No files matched your search
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2026 Dim Himro
|
||||
|
||||
#ifndef DEFINITION_KEY_H
|
||||
#define DEFINITION_KEY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* @brief Stable frame identifier: normalized CAN ID and frame type.
|
||||
*/
|
||||
struct FrameKey {
|
||||
std::uint32_t canId = 0U;
|
||||
bool isExtended = false;
|
||||
|
||||
FrameKey() = default;
|
||||
|
||||
FrameKey(std::uint32_t id, bool extended)
|
||||
: canId(id), isExtended(extended) {
|
||||
}
|
||||
|
||||
bool operator==(const FrameKey &other) const {
|
||||
return (canId == other.canId) && (isExtended == other.isExtended);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Hasher for frame key.
|
||||
*/
|
||||
struct FrameKeyHasher {
|
||||
std::size_t operator()(const FrameKey &key) const {
|
||||
const std::size_t a = static_cast<std::size_t>(key.canId);
|
||||
const std::size_t b = key.isExtended ? 1U : 0U;
|
||||
return (a * 1315423911U) ^ b;
|
||||
}
|
||||
};
|
||||
|
||||
/** Stable signal identifier within one logical DBC database. */
|
||||
struct SignalKey {
|
||||
FrameKey frame;
|
||||
std::string name;
|
||||
|
||||
SignalKey() = default;
|
||||
SignalKey(FrameKey frameKey, std::string signalName)
|
||||
: frame(frameKey), name(std::move(signalName)) {
|
||||
}
|
||||
|
||||
bool operator==(const SignalKey &other) const {
|
||||
return frame == other.frame && name == other.name;
|
||||
}
|
||||
};
|
||||
|
||||
struct SignalKeyHasher {
|
||||
std::size_t operator()(const SignalKey &key) const {
|
||||
return FrameKeyHasher()(key.frame) ^ (std::hash<std::string>()(key.name) << 1U);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* DEFINITION_KEY_H */
|
||||
Reference in new issue
Block a user