Skip to content

Commit 284110b

Browse files
authored
Merge pull request #15 from LinuxDevon/clang-format-check
Clang format checks
2 parents 676da12 + 60514d7 commit 284110b

File tree

18 files changed

+747
-599
lines changed

18 files changed

+747
-599
lines changed

.clang-format

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <cullmann@kde.org>
3+
# SPDX-FileCopyrightText: 2019 Gernot Gebhard <gebhard@absint.com>
4+
#
5+
# SPDX-License-Identifier: MIT
6+
7+
# This file got automatically created by ECM, do not edit
8+
# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the config options
9+
# and https://community.kde.org/Policies/Frameworks_Coding_Style#Clang-format_automatic_code_formatting
10+
# for clang-format tips & tricks
11+
---
12+
Language: JavaScript
13+
DisableFormat: true
14+
---
15+
16+
# Style for C++
17+
Language: Cpp
18+
19+
# base is WebKit coding style: https://webkit.org/code-style-guidelines/
20+
# below are only things set that diverge from this style!
21+
BasedOnStyle: WebKit
22+
23+
# enforce C++11 (e.g. for std::vector<std::vector<lala>>
24+
Standard: Cpp11
25+
26+
# 4 spaces indent
27+
TabWidth: 4
28+
IndentWidth: 4
29+
UseTab: Always
30+
31+
SpacesInLineCommentPrefix:
32+
Minimum: 1
33+
Maximum: 1
34+
35+
# 2 * 80 wide lines
36+
ColumnLimit: 160
37+
38+
# sort includes inside line separated groups
39+
SortIncludes: true
40+
41+
# break before braces on function, namespace and class definitions.
42+
BreakBeforeBraces: Custom
43+
BraceWrapping:
44+
AfterClass: false
45+
AfterCaseLabel: false
46+
47+
# CrlInstruction *a;
48+
DerivePointerAlignment: false
49+
PointerAlignment: Left
50+
ReferenceAlignment: Left
51+
52+
# only clang format 14
53+
# RemoveBracesLLVM: true
54+
55+
#QualifierAlignment: Left
56+
57+
# horizontally aligns arguments after an open bracket.
58+
AlignAfterOpenBracket: Align
59+
60+
# don't move all parameters to new line
61+
AllowAllParametersOfDeclarationOnNextLine: false
62+
63+
# no single line functions
64+
AllowShortFunctionsOnASingleLine: None
65+
66+
# always break before you encounter multi line strings
67+
AlwaysBreakBeforeMultilineStrings: true
68+
69+
# don't move arguments to own lines if they are not all on the same
70+
BinPackArguments: false
71+
72+
# don't move parameters to own lines if they are not all on the same
73+
BinPackParameters: false
74+
75+
# In case we have an if statement with multiple lines the operator should be at the beginning of the line
76+
# but we do not want to break assignments
77+
BreakBeforeBinaryOperators: NonAssignment
78+
79+
# format C++11 braced lists like function calls
80+
Cpp11BracedListStyle: true
81+
82+
# do not put a space before C++11 braced lists
83+
SpaceBeforeCpp11BracedList: false
84+
85+
# remove empty lines
86+
KeepEmptyLinesAtTheStartOfBlocks: false
87+
88+
# no namespace indentation to keep indent level low
89+
NamespaceIndentation: None
90+
91+
# we use template< without space.
92+
SpaceAfterTemplateKeyword: false
93+
94+
# Always break after template declaration
95+
AlwaysBreakTemplateDeclarations: true
96+
97+
# macros for which the opening brace stays attached.
98+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE , wl_resource_for_each, wl_resource_for_each_safe ]
99+
100+
# keep lambda formatting multi-line if not empty
101+
AllowShortLambdasOnASingleLine: Empty
102+
103+
# We do not want clang-format to put all arguments on a new line
104+
AllowAllArgumentsOnNextLine: false

.github/workflows/tests.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,40 @@ name: Libdbc Tests
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches:
6+
- "master"
67
pull_request:
78

89
env:
910
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1011
BUILD_TYPE: Release
1112

1213
jobs:
13-
build:
14+
build-and-test:
1415
runs-on: ubuntu-latest
1516

1617
steps:
1718
- uses: actions/checkout@v3
1819

19-
- name: install fast_float dependency
20-
run: |
21-
cd ${{github.workspace}}
22-
git clone https://github.com/fastfloat/fast_float.git
23-
mkdir fast_float/build
24-
cd fast_float/build
25-
cmake -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/installation" ..
26-
make install
27-
2820
- name: Configure CMake
29-
run: |
30-
mkdir build
31-
cd build
32-
cmake -DFastFloat_DIR="${{github.workspace}}/installation/share/cmake/FastFloat" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ..
21+
run: cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Bbuild -H.
3322

34-
- name: Build
23+
- name: Build the library
3524
run: |
3625
cd build
37-
make
26+
make -j$(nproc)
3827
39-
- name: Test
28+
- name: Run unit tests
4029
run: |
4130
cd build
4231
ctest --output-on-failure
4332
33+
format-check:
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Test format with clang format
40+
run: ./scripts/fmt.sh
41+

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)
22

33
project(dbc VERSION 0.1.1 DESCRIPTION "C++ DBC Parser")
44

5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
57
# package
68
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
79
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})

include/libdbc/dbc.hpp

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,53 @@
33
#define __DBC_HPP__
44

55
#include <libdbc/exceptions/error.hpp>
6-
#include <libdbc/utils/utils.hpp>
7-
#include <libdbc/signal.hpp>
86
#include <libdbc/message.hpp>
7+
#include <libdbc/signal.hpp>
8+
#include <libdbc/utils/utils.hpp>
99

1010
#include <regex>
1111

1212
namespace libdbc {
1313

14-
class Parser {
15-
public:
16-
virtual ~Parser() = default;
17-
18-
virtual void parse_file(const std::string& file) = 0;
19-
20-
protected:
21-
14+
class Parser {
15+
public:
16+
virtual ~Parser() = default;
2217

23-
};
18+
virtual void parse_file(const std::string& file) = 0;
2419

25-
class DbcParser : public Parser {
26-
public:
27-
DbcParser();
20+
protected:
21+
};
2822

29-
virtual ~DbcParser() = default;
23+
class DbcParser : public Parser {
24+
public:
25+
DbcParser();
3026

31-
virtual void parse_file(const std::string& file) final override;
27+
virtual ~DbcParser() = default;
3228

33-
std::string get_version() const;
34-
std::vector<std::string> get_nodes() const;
35-
std::vector<libdbc::Message> get_messages() const;
29+
virtual void parse_file(const std::string& file) final override;
3630

37-
Message::ParseSignalsStatus parseMessage(const uint32_t id, const std::vector<uint8_t>& data, std::vector<double>& out_values);
31+
std::string get_version() const;
32+
std::vector<std::string> get_nodes() const;
33+
std::vector<libdbc::Message> get_messages() const;
3834

39-
private:
40-
std::string version;
41-
std::vector<std::string> nodes;
42-
std::vector<libdbc::Message> messages;
35+
Message::ParseSignalsStatus parseMessage(const uint32_t id, const std::vector<uint8_t>& data, std::vector<double>& out_values);
4336

44-
const std::regex version_re;
45-
const std::regex bit_timing_re;
46-
const std::regex name_space_re;
47-
const std::regex node_re;
48-
const std::regex message_re;
49-
const std::regex signal_re;
37+
private:
38+
std::string version;
39+
std::vector<std::string> nodes;
40+
std::vector<libdbc::Message> messages;
5041

51-
void parse_dbc_header(std::istream& file_stream);
52-
void parse_dbc_nodes(std::istream& file_stream);
53-
void parse_dbc_messages(const std::vector<std::string>& lines);
42+
const std::regex version_re;
43+
const std::regex bit_timing_re;
44+
const std::regex name_space_re;
45+
const std::regex node_re;
46+
const std::regex message_re;
47+
const std::regex signal_re;
5448

55-
};
49+
void parse_dbc_header(std::istream& file_stream);
50+
void parse_dbc_nodes(std::istream& file_stream);
51+
void parse_dbc_messages(const std::vector<std::string>& lines);
52+
};
5653

5754
}
5855

include/libdbc/exceptions/error.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55

66
namespace libdbc {
77

8-
class exception : public std::exception {
9-
public:
10-
const char * what() const throw() {
11-
return "libdbc exception occurred";
12-
}
13-
};
8+
class exception : public std::exception {
9+
public:
10+
const char* what() const throw() {
11+
return "libdbc exception occurred";
12+
}
13+
};
1414

15-
class validity_error : public exception {
16-
public:
17-
const char * what() const throw() {
18-
return "Invalid DBC file";
19-
}
20-
};
15+
class validity_error : public exception {
16+
public:
17+
const char* what() const throw() {
18+
return "Invalid DBC file";
19+
}
20+
};
2121

2222
} // libdbc
2323

include/libdbc/message.hpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
#ifndef __MESSAGE_HPP__
22
#define __MESSAGE_HPP__
33

4-
#include <string>
5-
#include <vector>
64
#include <array>
75
#include <iostream>
86
#include <libdbc/signal.hpp>
7+
#include <string>
8+
#include <vector>
99

1010
namespace libdbc {
11-
struct Message {
12-
Message() = delete;
13-
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
14-
15-
enum class ParseSignalsStatus {
16-
Success,
17-
ErrorMessageToLong,
18-
ErrorBigEndian,
19-
ErrorUnknownID,
20-
ErrorInvalidConversion,
21-
};
22-
23-
/*!
24-
* \brief parseSignals
25-
* \param data
26-
* \param values
27-
* \return
28-
*/
29-
ParseSignalsStatus parseSignals(const std::vector<uint8_t>& data, std::vector<double> &values) const;
30-
31-
void appendSignal(const Signal& signal);
32-
const std::vector<Signal> signals() const;
33-
uint32_t id() const;
34-
35-
virtual bool operator==(const Message& rhs) const;
36-
37-
private:
38-
uint32_t m_id;
39-
std::string m_name;
40-
uint8_t m_size;
41-
std::string m_node;
42-
std::vector<Signal> m_signals;
43-
44-
friend std::ostream& operator<<(std::ostream& os, const Message& dt);
11+
struct Message {
12+
Message() = delete;
13+
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
14+
15+
enum class ParseSignalsStatus {
16+
Success,
17+
ErrorMessageToLong,
18+
ErrorBigEndian,
19+
ErrorUnknownID,
20+
ErrorInvalidConversion,
4521
};
4622

47-
std::ostream& operator<< (std::ostream &out, const Message& msg);
23+
/*!
24+
* \brief parseSignals
25+
* \param data
26+
* \param values
27+
* \return
28+
*/
29+
ParseSignalsStatus parseSignals(const std::vector<uint8_t>& data, std::vector<double>& values) const;
30+
31+
void appendSignal(const Signal& signal);
32+
const std::vector<Signal> signals() const;
33+
uint32_t id() const;
34+
35+
virtual bool operator==(const Message& rhs) const;
36+
37+
private:
38+
uint32_t m_id;
39+
std::string m_name;
40+
uint8_t m_size;
41+
std::string m_node;
42+
std::vector<Signal> m_signals;
43+
44+
friend std::ostream& operator<<(std::ostream& os, const Message& dt);
45+
};
46+
47+
std::ostream& operator<<(std::ostream& out, const Message& msg);
4848

4949
}
5050

0 commit comments

Comments
 (0)