105 std::ifstream input(filePath.c_str());
106 if (!input.is_open()) {
107 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
108 DbcDiagnosticCode::FileOpenError, filePath, 0U,
109 "Failed to open DBC file: " + filePath});
117 bool inNamespace =
false;
118 std::size_t lineNumber = 0U;
120 while (std::getline(input, line)) {
122 if (!line.empty() && line.back() ==
'\r')
124 const std::string rawLine = line;
125 const std::size_t statementLine = lineNumber;
126 line = dbc_detail::TrimText(line);
130 std::istringstream tokens(line);
132 std::string argument;
134 const bool hasArgument =
static_cast<bool>(tokens >> argument);
135 if (inNamespace && !hasArgument && keyword !=
"BO_" && keyword !=
"SG_" &&
136 keyword !=
"BS_" && keyword !=
"BS_:" &&
137 keyword !=
"BU_" && keyword !=
"BU_:")
139 inNamespace = keyword ==
"NS_" || keyword ==
"NS_:";
141 if (keyword ==
"CM_") {
143 ReadCommentLines(input, line, lineNumber);
144 }
else if (keyword ==
"BA_DEF_" || keyword ==
"BA_DEF_DEF_" || keyword ==
"BA_") {
145 line = rawLine.substr(rawLine.find(keyword));
146 ReadAttributeLines(input, line, lineNumber);
150 context.lineNumber = statementLine;
151 if (!dispatcher.
Dispatch(line, context)) {
152 result.
diagnostics.push_back({DbcDiagnosticSeverity::Warning,
153 DbcDiagnosticCode::UnsupportedStatement,
154 filePath, statementLine,
155 "Unsupported statement '" + keyword +
156 "' is ignored; decoding or metadata may be incomplete."});
158 }
catch (
const std::exception &error) {
159 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
160 StatementErrorCode(keyword), filePath,
161 statementLine, error.what()});
166 if (input.bad() || !input.eof()) {
167 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
168 DbcDiagnosticCode::FileReadError, filePath, 0U,
169 "Failed to read DBC file: " + filePath});
174 context.ResolveComments(filePath);
175 context.ResolveValueDescriptions(filePath);
176 context.ResolveMultiplexing(filePath);
177 context.ValidateMultiplexing(filePath);
178 context.ResolveAttributes(filePath, result.
diagnostics);
183 result.
database = std::move(database);