Skip to content

Commit 9121e4f

Browse files
committed
Separating class into separate file
1 parent b0574e2 commit 9121e4f

File tree

7 files changed

+115
-84
lines changed

7 files changed

+115
-84
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ endif()
2222
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
2323

2424
# add where to find the source files
25+
# file(GLOB_RECURSE SOURCE ${PROJECT_SOURCE_DIR}/src/ *.cpp)
2526
list(APPEND SOURCE ${PROJECT_SOURCE_DIR}/src/utils.cpp
27+
${PROJECT_SOURCE_DIR}/src/message.cpp
28+
${PROJECT_SOURCE_DIR}/src/signal.cpp
2629
${PROJECT_SOURCE_DIR}/src/dbc.cpp)
2730

2831
include_directories(src)

include/libdbc/dbc.hpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,13 @@
44

55
#include <libdbc/exceptions/error.hpp>
66
#include <libdbc/utils/utils.hpp>
7+
#include <libdbc/signal.hpp>
8+
#include <libdbc/message.hpp>
79

810
#include <regex>
9-
#include <iostream>
1011

1112
namespace libdbc {
1213

13-
struct Signal {
14-
std::string name;
15-
bool is_multiplexed;
16-
uint32_t start_bit;
17-
uint32_t size;
18-
bool is_bigendian;
19-
bool is_signed;
20-
double factor;
21-
double offset;
22-
double min;
23-
double max;
24-
std::string unit;
25-
std::vector<std::string> receivers;
26-
27-
Signal() = delete;
28-
explicit Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> recievers);
29-
30-
virtual bool operator==(const Signal& rhs) const;
31-
};
32-
33-
struct Message {
34-
uint32_t id;
35-
std::string name;
36-
uint8_t size;
37-
std::string node;
38-
std::vector<Signal> signals;
39-
40-
Message() = delete;
41-
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
42-
43-
virtual bool operator==(const Message& rhs) const;
44-
};
45-
46-
47-
std::ostream& operator<< (std::ostream &out, const Message& msg);
48-
std::ostream& operator<< (std::ostream &out, const Signal& sig);
49-
50-
5114
class Parser {
5215
public:
5316
virtual ~Parser() = default;

include/libdbc/message.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __MESSAGE_HPP__
2+
#define __MESSAGE_HPP__
3+
4+
#include <string>
5+
#include <vector>
6+
#include <iostream>
7+
#include <libdbc/signal.hpp>
8+
9+
namespace libdbc {
10+
struct Message {
11+
uint32_t id;
12+
std::string name;
13+
uint8_t size;
14+
std::string node;
15+
std::vector<Signal> signals;
16+
17+
Message() = delete;
18+
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
19+
20+
virtual bool operator==(const Message& rhs) const;
21+
};
22+
23+
std::ostream& operator<< (std::ostream &out, const Message& msg);
24+
25+
}
26+
27+
#endif // __MESSAGE_HPP__

include/libdbc/signal.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
#ifndef __SIGNAL_HPP__
3+
#define __SIGNAL_HPP__
4+
5+
#include <string>
6+
#include <vector>
7+
#include <iostream>
8+
9+
namespace libdbc {
10+
struct Signal {
11+
std::string name;
12+
bool is_multiplexed;
13+
uint32_t start_bit;
14+
uint32_t size;
15+
bool is_bigendian;
16+
bool is_signed;
17+
double factor;
18+
double offset;
19+
double min;
20+
double max;
21+
std::string unit;
22+
std::vector<std::string> receivers;
23+
24+
Signal() = delete;
25+
explicit Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> recievers);
26+
27+
virtual bool operator==(const Signal& rhs) const;
28+
};
29+
30+
std::ostream& operator<< (std::ostream &out, const Signal& sig);
31+
32+
}
33+
34+
#endif // __SIGNAL_HPP__

src/dbc.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,6 @@
66

77
namespace libdbc {
88

9-
Message::Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node) :
10-
id(id), name(name), size(size), node(node) {}
11-
12-
bool Message::operator==(const Message& rhs) const {
13-
return (this->id == rhs.id) && (this->name == rhs.name) &&
14-
(this->size == rhs.size) && (this->node == rhs.node);
15-
}
16-
17-
std::ostream& operator<< (std::ostream &out, const Message& msg) {
18-
out << "Message: {id: " << msg.id << ", ";
19-
out << "name: " << msg.name << ", ";
20-
out << "size: " << msg.size << ", ";
21-
out << "node: " << msg.node << "}";
22-
return out;
23-
}
24-
25-
26-
Signal::Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> receivers) :
27-
name(name), is_multiplexed(is_multiplexed), start_bit(start_bit), size(size), is_bigendian(is_bigendian), is_signed(is_signed), offset(offset), min(min), max(max), unit(unit), receivers(receivers) {}
28-
29-
bool Signal::operator==(const Signal& rhs) const {
30-
return (this->name == rhs.name) && (this->is_multiplexed == rhs.is_multiplexed) &&
31-
(this->start_bit == rhs.start_bit) && (this->size == rhs.size) &&
32-
(this->is_bigendian == rhs.is_bigendian) && (this->is_signed == rhs.is_signed) &&
33-
(this->offset == rhs.offset) && (this->min == rhs.min) && (this->max == rhs.max) &&
34-
(this->unit == rhs.unit) && (this->receivers == rhs.receivers);
35-
}
36-
37-
38-
std::ostream& operator<< (std::ostream &out, const Signal& sig) {
39-
out << "Signal {name: " << sig.name << ", ";
40-
out << "Multiplexed: " << (sig.is_multiplexed ? "True" : "False") << ", ";
41-
out << "Start bit: " << sig.start_bit << ", ";
42-
out << "Size: " << sig.size << ", ";
43-
out << "Endianness: " << (sig.is_bigendian ? "Big endian" : "Little endian") << ", ";
44-
out << "Value Type: " << (sig.is_signed ? "Signed" : "Unsigned") << ", ";
45-
out << "Min: " << sig.min << ", Max: " << sig.max << ", ";
46-
out << "Unit: (" << sig.unit << "), ";
47-
out << "receivers: ";
48-
for(const auto &r : sig.receivers)
49-
out << r;
50-
return out << "}";
51-
}
52-
53-
549
DbcParser::DbcParser() : version(""), nodes(),
5510
version_re("^(VERSION)\\s\"(.*)\""), bit_timing_re("^(BS_:)"),
5611
name_space_re("^(NS_)\\s\\:"), node_re("^(BU_:)\\s((?:[\\w]+?\\s?)*)"),

src/message.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <libdbc/message.hpp>
2+
3+
namespace libdbc {
4+
Message::Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node) :
5+
id(id), name(name), size(size), node(node) {}
6+
7+
bool Message::operator==(const Message& rhs) const {
8+
return (this->id == rhs.id) && (this->name == rhs.name) &&
9+
(this->size == rhs.size) && (this->node == rhs.node);
10+
}
11+
12+
std::ostream& operator<< (std::ostream &out, const Message& msg) {
13+
out << "Message: {id: " << msg.id << ", ";
14+
out << "name: " << msg.name << ", ";
15+
out << "size: " << msg.size << ", ";
16+
out << "node: " << msg.node << "}";
17+
return out;
18+
}
19+
}

src/signal.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <libdbc/signal.hpp>
2+
3+
namespace libdbc {
4+
Signal::Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> receivers) :
5+
name(name), is_multiplexed(is_multiplexed), start_bit(start_bit), size(size), is_bigendian(is_bigendian), is_signed(is_signed), offset(offset), min(min), max(max), unit(unit), receivers(receivers) {}
6+
7+
bool Signal::operator==(const Signal& rhs) const {
8+
return (this->name == rhs.name) && (this->is_multiplexed == rhs.is_multiplexed) &&
9+
(this->start_bit == rhs.start_bit) && (this->size == rhs.size) &&
10+
(this->is_bigendian == rhs.is_bigendian) && (this->is_signed == rhs.is_signed) &&
11+
(this->offset == rhs.offset) && (this->min == rhs.min) && (this->max == rhs.max) &&
12+
(this->unit == rhs.unit) && (this->receivers == rhs.receivers);
13+
}
14+
15+
16+
std::ostream& operator<< (std::ostream &out, const Signal& sig) {
17+
out << "Signal {name: " << sig.name << ", ";
18+
out << "Multiplexed: " << (sig.is_multiplexed ? "True" : "False") << ", ";
19+
out << "Start bit: " << sig.start_bit << ", ";
20+
out << "Size: " << sig.size << ", ";
21+
out << "Endianness: " << (sig.is_bigendian ? "Big endian" : "Little endian") << ", ";
22+
out << "Value Type: " << (sig.is_signed ? "Signed" : "Unsigned") << ", ";
23+
out << "Min: " << sig.min << ", Max: " << sig.max << ", ";
24+
out << "Unit: (" << sig.unit << "), ";
25+
out << "receivers: ";
26+
for(const auto &r : sig.receivers)
27+
out << r;
28+
return out << "}";
29+
}
30+
}

0 commit comments

Comments
 (0)