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