File tree Expand file tree Collapse file tree 8 files changed +139
-96
lines changed
Expand file tree Collapse file tree 8 files changed +139
-96
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ endif()
2222set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} " )
2323
2424# add where to find the source files
25- list (APPEND SOURCE ${PROJECT_SOURCE_DIR} /src/util/utils.cpp)
25+ list (APPEND SOURCE ${PROJECT_SOURCE_DIR} /src/utils.cpp
26+ ${PROJECT_SOURCE_DIR} /src/dbc.cpp)
2627
2728include_directories (src)
2829include_directories (include )
Original file line number Diff line number Diff line change 1+
2+ #ifndef __DBC_HPP__
3+ #define __DBC_HPP__
4+
5+ #include " exceptions/error.hpp"
6+ #include " utils/utils.hpp"
7+
8+ #include < regex>
9+
10+ namespace libdbc {
11+
12+ class Parser {
13+ public:
14+ virtual ~Parser () = default ;
15+
16+ virtual void parse_file (const std::string& file) = 0;
17+
18+ protected:
19+
20+
21+ };
22+
23+ class DbcParser : public Parser {
24+ public:
25+ DbcParser ();
26+
27+ virtual ~DbcParser () = default ;
28+
29+ virtual void parse_file (const std::string& file) final override ;
30+
31+ std::string get_version () const ;
32+
33+ private:
34+ std::string version;
35+
36+ const std::regex version_re;
37+ const std::regex bit_timing_re;
38+ const std::regex name_space_re;
39+
40+ void parse_dbc_header (std::istream& file_stream);
41+
42+ };
43+
44+
45+ struct Message {
46+
47+ };
48+
49+ }
50+
51+ #endif // __DBC_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __ERROR_HPP__
2+ #define __ERROR_HPP__
3+
14#include < sstream>
25
36namespace libdbc {
@@ -31,4 +34,6 @@ namespace libdbc {
3134 const char * file;
3235 };
3336
34- } // libdbc
37+ } // libdbc
38+
39+ #endif // __ERROR_HPP__
Original file line number Diff line number Diff line change 1+
2+ #ifndef __UTILS_HPP__
3+ #define __UTILS_HPP__
4+
15#include < string>
26#include < fstream>
37#include < iostream>
@@ -24,4 +28,13 @@ namespace utils {
2428
2529 };
2630
27- }
31+ class String {
32+ public:
33+
34+ static std::string trim (const std::string& line);
35+
36+ };
37+
38+ }
39+
40+ #endif // __UTILS_HPP__
Original file line number Diff line number Diff line change 1+ #include " exceptions/error.hpp"
2+ #include " utils/utils.hpp"
3+ #include " dbc.hpp"
4+
5+ #include < regex>
6+
7+ namespace libdbc {
8+
9+ DbcParser::DbcParser () : version(" " ), version_re(" ^(VERSION)\\ s\" (.*)\" " ),
10+ bit_timing_re (" ^(BS_:)" ), name_space_re(" ^(NS_)\\ s\\ :" ) {
11+
12+ }
13+
14+ void DbcParser::parse_file (const std::string& file) {
15+ std::ifstream s (file.c_str ());
16+ std::string line;
17+
18+ parse_dbc_header (s);
19+
20+ while (!s.eof ()) {
21+ utils::StreamHandler::get_line (s, line);
22+
23+ }
24+
25+ }
26+
27+ std::string DbcParser::get_version () const {
28+ return version;
29+ }
30+
31+ void DbcParser::parse_dbc_header (std::istream& file_stream) {
32+ std::string line;
33+ std::smatch match;
34+ bool is_blank = true ;
35+ bool not_blank = true ;
36+
37+ utils::StreamHandler::get_line (file_stream, line);
38+
39+ if (!std::regex_search (line, match, version_re)) {
40+ throw validity_error ();
41+ }
42+
43+ version = match.str (2 );
44+
45+ utils::StreamHandler::get_next_non_blank_line ( file_stream, line );
46+
47+ utils::StreamHandler::skip_to_next_blank_line ( file_stream, line );
48+
49+ utils::StreamHandler::get_next_non_blank_line ( file_stream, line );
50+
51+ if (!std::regex_search (line, match, bit_timing_re))
52+ throw validity_error ();
53+
54+ }
55+
56+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- #include " util /utils.hpp"
1+ #include " utils /utils.hpp"
22
33#include < regex>
44
@@ -64,4 +64,12 @@ namespace utils {
6464 }
6565
6666
67+
68+ std::string String::trim (const std::string& line) {
69+ const char * WhiteSpace = " \t\v\r\n " ;
70+ std::size_t start = line.find_first_not_of (WhiteSpace);
71+ std::size_t end = line.find_last_not_of (WhiteSpace);
72+ return start == end ? std::string () : line.substr (start, end - start + 1 );
73+ }
74+
6775} // Namespace Utils
Original file line number Diff line number Diff line change 11#include < catch2/catch.hpp>
22#include " defines.hpp"
3- #include " util /utils.hpp"
3+ #include " utils /utils.hpp"
44
55#include < sstream>
66
You can’t perform that action at this time.
0 commit comments