Skip to content

Commit 98b180c

Browse files
committed
Updating some comments and starting to make the library.
I am starting with a static library and then have some scripts to pull together a header only maybe. Currently working on getting the base library interface figured out through some TDD. I am mirroring libxml interface and using that as a guide.
1 parent 72226f3 commit 98b180c

File tree

9 files changed

+89
-15
lines changed

9 files changed

+89
-15
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
project(DBC)
3+
project(dbc)
44

55
# specify the C++ standard
66
set(CMAKE_CXX_STANDARD 11)
77
set(CMAKE_CXX_STANDARD_REQUIRED True)
88

9-
# Add in the debug flag
9+
# Add in the debug flag0.
1010
set(GCC_COVERAGE_COMPILE_FLAGS "-g")
1111
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
1212

@@ -19,3 +19,4 @@ include_directories(include)
1919
add_subdirectory(test)
2020
add_subdirectory(doc)
2121

22+
add_library(${PROJECT_NAME} STATIC ${SOURCE})

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# C++ DBC Header Only File Parser
1+
# C++ DBC Parser
22

33
This is to provide a library header only file to read in DBC files. I was looking around and couldn't
44
find a simple library that didn't have dependencies. So here we are making one. I got some inspiration

src/dbc.hpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
#include "exceptions/error.hpp"
12

2-
namespace dbc {
3+
namespace libdbc {
34

4-
class parser {
5+
class Parser {
6+
public:
7+
virtual ~Parser() = default;
58

6-
};
9+
virtual void parse_file(const std::string& file) = 0;
10+
};
11+
12+
class DbcParser : public Parser {
13+
public:
14+
virtual ~DbcParser() = default;
15+
16+
virtual void parse_file(const std::string& file) final override {
17+
throw validity_error();
18+
}
19+
20+
};
721

822
}

src/exceptions/error.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
namespace libdbc {
3+
4+
class exception : public std::exception {
5+
const char * what() const throw() {
6+
return "libdbc exception occurred";
7+
}
8+
};
9+
10+
class validity_error : public exception {
11+
const char * what() const throw() {
12+
return "invalid file issue";
13+
}
14+
};
15+
16+
} // libdbc

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(tests VERSION 0.1.0)
22

33
list(APPEND TEST_SOURCES main.cpp
4-
test_file_loading.cpp
4+
test_dbc.cpp
55
test_utils.cpp)
66

77
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party/Catch2/single_include)

test/dbcs/Sample2.dbc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
VERSION ""
2+
3+
NS_ :
4+
BA_
5+
BA_DEF_
6+
BA_DEF_DEF_
7+
BA_DEF_DEF_REL_
8+
BA_DEF_REL_
9+
BA_DEF_SGTYPE_
10+
BA_REL_
11+
BA_SGTYPE_
12+
BO_TX_BU_
13+
BU_BO_REL_
14+
BU_EV_REL_
15+
BU_SG_REL_
16+
CAT_
17+
CAT_DEF_
18+
CM_
19+
ENVVAR_DATA_
20+
EV_DATA_
21+
FILTER
22+
NS_DESC_
23+
SGTYPE_
24+
SGTYPE_VAL_
25+
SG_MUL_VAL_
26+
SIGTYPE_VALTYPE_
27+
SIG_GROUP_
28+
SIG_TYPE_REF_
29+
SIG_VALTYPE_
30+
VAL_
31+
VAL_TABLE_
32+
33+
BS_:
34+
35+
BU_: DBG DRIVER IO MOTOR SENSOR
36+
37+
BO_ 500 IO_DEBUG: 4 IO
38+
SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG

test/defines.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include <string>
22

3-
static const std::string TEXT_FILE = "./dbcs/TextFile.txt";
3+
static const std::string TEXT_FILE = "./dbcs/TextFile.txt";
4+
static const std::string DBC_FILE_1 = "./dbcs/Sample1.dbc";
5+
static const std::string DBC_FILE_2 = "./dbcs/Sample2.dbc";

test/test_dbc.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <catch2/catch.hpp>
2+
#include "defines.hpp"
3+
#include "dbc.hpp"
4+
5+
TEST_CASE("Load a simple 1 line message dbc", "[fileio]") {
6+
auto parser = std::unique_ptr<libdbc::DbcParser>(new libdbc::DbcParser());
7+
8+
REQUIRE_THROWS_AS(parser->parse_file(DBC_FILE_2), libdbc::validity_error);
9+
10+
}

test/test_file_loading.cpp

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)