Files
dbc/core/dbc_diagnostic.h
T
2026-10-20 13:38:21 -04:00

53 lines
1.6 KiB
C++

// SPDX-License-Identifier: MIT
#ifndef DBC_DIAGNOSTIC_H
#define DBC_DIAGNOSTIC_H
#include "dbc_database.h"
#include <cstddef>
#include <string>
#include <vector>
/** @brief Warning or fatal parse error. */
enum class DbcDiagnosticSeverity {
Warning,
Error
};
/** Stable categories; messages provide the details. */
enum class DbcDiagnosticCode {
FileOpenError,
FileReadError,
InvalidStatement,
InvalidValueDescription,
InvalidMultiplexing,
UnsupportedStatement,
InvalidAttribute,
UnsupportedAttribute
};
/** @brief Diagnostic message and physical source location. */
struct DbcDiagnostic {
DbcDiagnosticSeverity severity; /**< Message severity. */
DbcDiagnosticCode code; /**< Stable diagnostic category. */
std::string filePath; /**< Input file path. */
std::size_t lineNumber; /**< One-based physical line; zero for file-level errors. */
std::string message; /**< Human-readable diagnostic details. */
};
/** @brief Parsed database and diagnostics; the database is empty on error. */
struct DbcParseResult {
DbcDatabase database; /**< Parsed content, published only on success. */
std::vector<DbcDiagnostic> diagnostics; /**< Warnings and the first error, if any. */
/** @brief Return whether any diagnostic has error severity. */
bool HasErrors() const {
for (const DbcDiagnostic &diagnostic: diagnostics) {
if (diagnostic.severity == DbcDiagnosticSeverity::Error)
return true;
}
return false;
}
};
#endif /* DBC_DIAGNOSTIC_H */