DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
dbc_parser.cpp
Go to the documentation of this file.
1
12#include "dbc_parser.h"
13#include "dbc_statement_handler.h"
14
15#include "text_utils.h"
16#include <fstream>
17#include <stdexcept>
18
19DbcDatabase DbcParser::ParseFile(const std::string &filePath) const {
20 std::ifstream input(filePath.c_str());
21 if (!input.is_open())
22 throw std::runtime_error("Failed to open DBC file: " + filePath);
23
24 DbcDatabase database;
25 DbcParseContext context{database, nullptr};
26 const DbcStatementDispatcher dispatcher;
27
28 std::size_t lineNumber = 0U;
29 std::string line;
30 while (std::getline(input, line)) {
31 ++lineNumber;
32 line = dbc_detail::TrimText(line);
33 if (line.empty())
34 continue;
35
36 try {
37 context.lineNumber = lineNumber;
38 dispatcher.Dispatch(line, context);
39 } catch (const std::exception &error) {
40 throw std::runtime_error(filePath + ":" + std::to_string(lineNumber) +
41 ": " + error.what());
42 }
43 }
44
45 context.ResolveValueDescriptions(filePath);
46 context.ValidateMultiplexing(filePath);
47 return database;
48}
DbcDatabase ParseFile(const std::string &filePath) const
Parse DBC file.
bool Dispatch(const std::string &line, DbcParseContext &context) const
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Parsed DBC content stored in a simple internal form.