69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#ifndef DBC_ATTRIBUTES_H
|
|
#define DBC_ATTRIBUTES_H
|
|
|
|
#include <cstdint>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
/**
|
|
* @brief Target scope of an attribute definition or assignment.
|
|
*/
|
|
enum class AttributeScope {
|
|
Database,
|
|
Node,
|
|
Frame,
|
|
Signal,
|
|
Environment
|
|
};
|
|
|
|
/**
|
|
* @brief DBC attribute storage type. HEX values use decimal integer syntax.
|
|
*/
|
|
enum class AttributeType {
|
|
Integer,
|
|
Hex,
|
|
Float,
|
|
String,
|
|
Enum
|
|
};
|
|
|
|
/** @brief Typed attribute value; ENUM uses a zero-based integer index. */
|
|
using AttributeValue = std::variant<std::int64_t, double, std::string>;
|
|
/** @brief Effective attribute values indexed by definition name. */
|
|
using AttributeMap = std::map<std::string, AttributeValue>;
|
|
|
|
/**
|
|
* @brief Attribute type, permitted range, and optional default.
|
|
*/
|
|
struct AttributeDefinition {
|
|
AttributeScope scope = AttributeScope::Database; /**< Target scope; database when no scope marker is present. */
|
|
AttributeType type = AttributeType::String; /**< Type used to validate values. */
|
|
std::int64_t integerMinimum = 0; /**< Inclusive INT, HEX, or ENUM lower bound. */
|
|
std::int64_t integerMaximum = 0; /**< Inclusive INT, HEX, or ENUM upper bound. */
|
|
double minimum = 0.0; /**< Inclusive FLOAT lower bound. */
|
|
double maximum = 0.0; /**< Inclusive FLOAT upper bound. */
|
|
std::vector<std::string> enumValues; /**< ENUM labels in index order. */
|
|
std::optional<AttributeValue> defaultValue; /**< Validated default; empty when not declared. */
|
|
};
|
|
|
|
/**
|
|
* @brief Explicit assignment; defaults remain on definitions.
|
|
*
|
|
* Named nodes/environment variables are retained without validating declarations,
|
|
* which are not parsed.
|
|
*/
|
|
struct AttributeAssignment {
|
|
std::string name; /**< Attribute definition name. */
|
|
AttributeScope scope = AttributeScope::Database; /**< Target scope; database when no scope marker is present. */
|
|
std::uint32_t canId = 0U; /**< Normalized frame ID for frame/signal assignments. */
|
|
bool isExtended = false; /**< Frame type for frame/signal assignments. */
|
|
std::string targetName; /**< Signal, node, or environment variable name. */
|
|
AttributeValue value; /**< Validated explicit value. */
|
|
};
|
|
|
|
#endif
|