Skip to content

Clang format checks #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
# SPDX-FileCopyrightText: 2019 Christoph Cullmann <[email protected]>
# SPDX-FileCopyrightText: 2019 Gernot Gebhard <[email protected]>
#
# SPDX-License-Identifier: MIT

# This file got automatically created by ECM, do not edit
# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html for the config options
# and https://community.kde.org/Policies/Frameworks_Coding_Style#Clang-format_automatic_code_formatting
# for clang-format tips & tricks
---
Language: JavaScript
DisableFormat: true
---

# Style for C++
Language: Cpp

# base is WebKit coding style: https://webkit.org/code-style-guidelines/
# below are only things set that diverge from this style!
BasedOnStyle: WebKit

# enforce C++11 (e.g. for std::vector<std::vector<lala>>
Standard: Cpp11

# 4 spaces indent
TabWidth: 4
IndentWidth: 4
UseTab: Always

SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1

# 2 * 80 wide lines
ColumnLimit: 160

# sort includes inside line separated groups
SortIncludes: true

# break before braces on function, namespace and class definitions.
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterCaseLabel: false

# CrlInstruction *a;
DerivePointerAlignment: false
PointerAlignment: Left
ReferenceAlignment: Left

# only clang format 14
# RemoveBracesLLVM: true

#QualifierAlignment: Left

# horizontally aligns arguments after an open bracket.
AlignAfterOpenBracket: Align

# don't move all parameters to new line
AllowAllParametersOfDeclarationOnNextLine: false

# no single line functions
AllowShortFunctionsOnASingleLine: None

# always break before you encounter multi line strings
AlwaysBreakBeforeMultilineStrings: true

# don't move arguments to own lines if they are not all on the same
BinPackArguments: false

# don't move parameters to own lines if they are not all on the same
BinPackParameters: false

# In case we have an if statement with multiple lines the operator should be at the beginning of the line
# but we do not want to break assignments
BreakBeforeBinaryOperators: NonAssignment

# format C++11 braced lists like function calls
Cpp11BracedListStyle: true

# do not put a space before C++11 braced lists
SpaceBeforeCpp11BracedList: false

# remove empty lines
KeepEmptyLinesAtTheStartOfBlocks: false

# no namespace indentation to keep indent level low
NamespaceIndentation: None

# we use template< without space.
SpaceAfterTemplateKeyword: false

# Always break after template declaration
AlwaysBreakTemplateDeclarations: true

# macros for which the opening brace stays attached.
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE , wl_resource_for_each, wl_resource_for_each_safe ]

# keep lambda formatting multi-line if not empty
AllowShortLambdasOnASingleLine: Empty

# We do not want clang-format to put all arguments on a new line
AllowAllArgumentsOnNextLine: false
34 changes: 16 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,40 @@ name: Libdbc Tests

on:
push:
branches: [ "master" ]
branches:
- "master"
pull_request:

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

jobs:
build:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: install fast_float dependency
run: |
cd ${{github.workspace}}
git clone https://github.com/fastfloat/fast_float.git
mkdir fast_float/build
cd fast_float/build
cmake -DCMAKE_INSTALL_PREFIX="${{github.workspace}}/installation" ..
make install

- name: Configure CMake
run: |
mkdir build
cd build
cmake -DFastFloat_DIR="${{github.workspace}}/installation/share/cmake/FastFloat" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ..
run: cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Bbuild -H.

- name: Build
- name: Build the library
run: |
cd build
make
make -j$(nproc)

- name: Test
- name: Run unit tests
run: |
cd build
ctest --output-on-failure

format-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Test format with clang format
run: ./scripts/fmt.sh

2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)

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

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# package
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
Expand Down
65 changes: 31 additions & 34 deletions include/libdbc/dbc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,53 @@
#define __DBC_HPP__

#include <libdbc/exceptions/error.hpp>
#include <libdbc/utils/utils.hpp>
#include <libdbc/signal.hpp>
#include <libdbc/message.hpp>
#include <libdbc/signal.hpp>
#include <libdbc/utils/utils.hpp>

#include <regex>

namespace libdbc {

class Parser {
public:
virtual ~Parser() = default;

virtual void parse_file(const std::string& file) = 0;

protected:

class Parser {
public:
virtual ~Parser() = default;

};
virtual void parse_file(const std::string& file) = 0;

class DbcParser : public Parser {
public:
DbcParser();
protected:
};

virtual ~DbcParser() = default;
class DbcParser : public Parser {
public:
DbcParser();

virtual void parse_file(const std::string& file) final override;
virtual ~DbcParser() = default;

std::string get_version() const;
std::vector<std::string> get_nodes() const;
std::vector<libdbc::Message> get_messages() const;
virtual void parse_file(const std::string& file) final override;

Message::ParseSignalsStatus parseMessage(const uint32_t id, const std::vector<uint8_t>& data, std::vector<double>& out_values);
std::string get_version() const;
std::vector<std::string> get_nodes() const;
std::vector<libdbc::Message> get_messages() const;

private:
std::string version;
std::vector<std::string> nodes;
std::vector<libdbc::Message> messages;
Message::ParseSignalsStatus parseMessage(const uint32_t id, const std::vector<uint8_t>& data, std::vector<double>& out_values);

const std::regex version_re;
const std::regex bit_timing_re;
const std::regex name_space_re;
const std::regex node_re;
const std::regex message_re;
const std::regex signal_re;
private:
std::string version;
std::vector<std::string> nodes;
std::vector<libdbc::Message> messages;

void parse_dbc_header(std::istream& file_stream);
void parse_dbc_nodes(std::istream& file_stream);
void parse_dbc_messages(const std::vector<std::string>& lines);
const std::regex version_re;
const std::regex bit_timing_re;
const std::regex name_space_re;
const std::regex node_re;
const std::regex message_re;
const std::regex signal_re;

};
void parse_dbc_header(std::istream& file_stream);
void parse_dbc_nodes(std::istream& file_stream);
void parse_dbc_messages(const std::vector<std::string>& lines);
};

}

Expand Down
24 changes: 12 additions & 12 deletions include/libdbc/exceptions/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

namespace libdbc {

class exception : public std::exception {
public:
const char * what() const throw() {
return "libdbc exception occurred";
}
};
class exception : public std::exception {
public:
const char* what() const throw() {
return "libdbc exception occurred";
}
};

class validity_error : public exception {
public:
const char * what() const throw() {
return "Invalid DBC file";
}
};
class validity_error : public exception {
public:
const char* what() const throw() {
return "Invalid DBC file";
}
};

} // libdbc

Expand Down
74 changes: 37 additions & 37 deletions include/libdbc/message.hpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
#ifndef __MESSAGE_HPP__
#define __MESSAGE_HPP__

#include <string>
#include <vector>
#include <array>
#include <iostream>
#include <libdbc/signal.hpp>
#include <string>
#include <vector>

namespace libdbc {
struct Message {
Message() = delete;
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);

enum class ParseSignalsStatus {
Success,
ErrorMessageToLong,
ErrorBigEndian,
ErrorUnknownID,
ErrorInvalidConversion,
};

/*!
* \brief parseSignals
* \param data
* \param values
* \return
*/
ParseSignalsStatus parseSignals(const std::vector<uint8_t>& data, std::vector<double> &values) const;

void appendSignal(const Signal& signal);
const std::vector<Signal> signals() const;
uint32_t id() const;

virtual bool operator==(const Message& rhs) const;

private:
uint32_t m_id;
std::string m_name;
uint8_t m_size;
std::string m_node;
std::vector<Signal> m_signals;

friend std::ostream& operator<<(std::ostream& os, const Message& dt);
struct Message {
Message() = delete;
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);

enum class ParseSignalsStatus {
Success,
ErrorMessageToLong,
ErrorBigEndian,
ErrorUnknownID,
ErrorInvalidConversion,
};

std::ostream& operator<< (std::ostream &out, const Message& msg);
/*!
* \brief parseSignals
* \param data
* \param values
* \return
*/
ParseSignalsStatus parseSignals(const std::vector<uint8_t>& data, std::vector<double>& values) const;

void appendSignal(const Signal& signal);
const std::vector<Signal> signals() const;
uint32_t id() const;

virtual bool operator==(const Message& rhs) const;

private:
uint32_t m_id;
std::string m_name;
uint8_t m_size;
std::string m_node;
std::vector<Signal> m_signals;

friend std::ostream& operator<<(std::ostream& os, const Message& dt);
};

std::ostream& operator<<(std::ostream& out, const Message& msg);

}

Expand Down
Loading