Skip to content

Commit

Permalink
Feat/error handler and fixed tests (xR3b0rn#59)
Browse files Browse the repository at this point in the history
* Introduced error handling

- Added error handling
- Fixed grammar in order to make all tests pass
  • Loading branch information
xR3b0rn committed May 24, 2021
1 parent 8562f00 commit 8ef59f6
Show file tree
Hide file tree
Showing 19 changed files with 1,083 additions and 206 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
*.dbc
/.vs
/build
/out/build/x64-Debug
Expand Down
11 changes: 10 additions & 1 deletion src/libdbcppp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

include(GNUInstallDirs)
include(TestBigEndian)

add_library(${PROJECT_NAME} SHARED "")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
Expand All @@ -13,6 +14,14 @@ include_directories(
${CMAKE_BINARY_DIR}/src
)

test_big_endian(is_big_endian)
if (is_big_endian)
set(BYTE_ORDER Big)
else ()
set(BYTE_ORDER Little)
endif ()
configure_file(EndianConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/EndianConfig.h @ONLY)

file(GLOB header
"*.h"
)
Expand All @@ -24,7 +33,7 @@ file(GLOB src
)

target_sources(${PROJECT_NAME}
PRIVATE ${header}
PRIVATE ${header}
PUBLIC ${header_interface}
PRIVATE ${src}
)
Expand Down
416 changes: 256 additions & 160 deletions src/libdbcppp/DBCX3.cpp

Large diffs are not rendered by default.

41 changes: 39 additions & 2 deletions src/libdbcppp/DBCX3.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <boost/variant.hpp>
#include <boost/optional.hpp>
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>

namespace dbcppp
{
Expand All @@ -13,36 +14,42 @@ namespace dbcppp
namespace AST
{
using variant_attr_value_t = boost::variant<int64_t, double, std::string>;

struct G_Version
: boost::spirit::x3::position_tagged
{
std::string version;
};
struct G_NewSymbols
: boost::spirit::x3::position_tagged
{
std::vector<std::string> new_symbols;
boost::optional<std::vector<std::string>> new_symbols;
};
struct G_BitTiming
: boost::spirit::x3::position_tagged
{
uint64_t baudrate;
uint64_t BTR1;
uint64_t BTR2;
};
struct G_Node
: boost::spirit::x3::position_tagged
{
std::string name;
};
struct G_ValueEncodingDescription
: boost::spirit::x3::position_tagged
{
int64_t value;
std::string description;
};
struct G_ValueTable
: boost::spirit::x3::position_tagged
{
std::string name;
std::vector<G_ValueEncodingDescription> value_encoding_descriptions;
};
struct G_Signal
: boost::spirit::x3::position_tagged
{
std::string name;
boost::optional<std::string> multiplexer_indicator;
Expand All @@ -58,6 +65,7 @@ namespace dbcppp
std::vector<std::string> receivers;
};
struct G_Message
: boost::spirit::x3::position_tagged
{
uint64_t id;
std::string name;
Expand All @@ -66,11 +74,13 @@ namespace dbcppp
std::vector<G_Signal> signals;
};
struct G_MessageTransmitter
: boost::spirit::x3::position_tagged
{
uint64_t id;
std::vector<std::string> transmitters;
};
struct G_EnvironmentVariable
: boost::spirit::x3::position_tagged
{
std::string name;
uint64_t var_type;
Expand All @@ -83,11 +93,13 @@ namespace dbcppp
std::vector<std::string> access_nodes;
};
struct G_EnvironmentVariableData
: boost::spirit::x3::position_tagged
{
std::string name;
uint64_t size;
};
struct G_SignalType
: boost::spirit::x3::position_tagged
{
std::string name;
uint64_t size;
Expand All @@ -102,54 +114,65 @@ namespace dbcppp
std::string value_table_name;
};
struct G_CommentNetwork
: boost::spirit::x3::position_tagged
{
std::string comment;
};
struct G_CommentNode
: boost::spirit::x3::position_tagged
{
std::string node_name;
std::string comment;
};
struct G_CommentMessage
: boost::spirit::x3::position_tagged
{
uint64_t message_id;
std::string comment;
};
struct G_CommentSignal
: boost::spirit::x3::position_tagged
{
uint64_t message_id;
std::string signal_name;
std::string comment;
};
struct G_CommentEnvVar
: boost::spirit::x3::position_tagged
{
std::string env_var_name;
std::string comment;
};
using variant_comment_t = boost::variant<G_CommentNetwork, G_CommentNode, G_CommentMessage, G_CommentSignal, G_CommentEnvVar>;
struct G_Comment
: boost::spirit::x3::position_tagged
{
variant_comment_t comment;
};
struct G_AttributeValueTypeInt
: boost::spirit::x3::position_tagged
{
int64_t minimum;
int64_t maximum;
};
struct G_AttributeValueTypeHex
: boost::spirit::x3::position_tagged
{
int64_t minimum;
int64_t maximum;
};
struct G_AttributeValueTypeFloat
: boost::spirit::x3::position_tagged
{
double minimum;
double maximum;
};
struct G_AttributeValueTypeString
: boost::spirit::x3::position_tagged
{
};
struct G_AttributeValueTypeEnum
: boost::spirit::x3::position_tagged
{
std::vector<std::string> values;
};
Expand All @@ -159,78 +182,92 @@ namespace dbcppp
G_AttributeValueTypeFloat, G_AttributeValueTypeString,
G_AttributeValueTypeEnum>;
struct G_AttributeValue
: boost::spirit::x3::position_tagged
{
variant_attribute_value_t value;
};
struct G_AttributeDefinition
: boost::spirit::x3::position_tagged
{
boost::optional<std::string> object_type;
std::string name;
G_AttributeValue value_type;
};
struct G_Attribute
: boost::spirit::x3::position_tagged
{
std::string name;
variant_attr_value_t value;
};
struct G_AttributeNetwork
: boost::spirit::x3::position_tagged
{
std::string attribute_name;
variant_attr_value_t value;
};
struct G_AttributeNode
: boost::spirit::x3::position_tagged
{
std::string attribute_name;
std::string node_name;
variant_attr_value_t value;
};
struct G_AttributeMessage
: boost::spirit::x3::position_tagged
{
std::string attribute_name;
uint64_t message_id;
variant_attr_value_t value;
};
struct G_AttributeSignal
: boost::spirit::x3::position_tagged
{
std::string attribute_name;
uint64_t message_id;
std::string signal_name;
variant_attr_value_t value;
};
struct G_AttributeEnvVar
: boost::spirit::x3::position_tagged
{
std::string attribute_name;
std::string env_var_name;
variant_attr_value_t value;
};
struct G_ValueDescription
: boost::spirit::x3::position_tagged
{
int64_t value;
std::string description;
};
using variant_attribute_t = boost::variant<G_AttributeNetwork, G_AttributeNode, G_AttributeMessage, G_AttributeSignal, G_AttributeEnvVar>;
struct G_ValueDescriptionSignal
: boost::spirit::x3::position_tagged
{
uint64_t message_id;
std::string signal_name;
std::vector<G_ValueDescription> value_descriptions;
};
struct G_ValueDescriptionEnvVar
: boost::spirit::x3::position_tagged
{;
std::string env_var_name;
std::vector<G_ValueDescription> value_descriptions;
};
struct G_ValueDescriptionSigEnvVar
: boost::spirit::x3::position_tagged
{
boost::variant<G_ValueDescriptionSignal, G_ValueDescriptionEnvVar> description;
};
struct G_SignalExtendedValueType
: boost::spirit::x3::position_tagged
{
uint64_t message_id;
std::string signal_name;
uint64_t value;
};
struct G_Network
: boost::spirit::x3::position_tagged
{
G_Version version;
std::vector<std::string> new_symbols;
Expand Down
11 changes: 11 additions & 0 deletions src/libdbcppp/EndianConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace dbcppp
{
enum class Endian
{
Little,
Big,
Native = Little,
};
}
11 changes: 11 additions & 0 deletions src/libdbcppp/EndianConfig.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace dbcppp
{
enum class Endian
{
Little,
Big,
Native = @BYTE_ORDER@,
};
}
63 changes: 44 additions & 19 deletions src/libdbcppp/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,62 @@

#include <string>
#include <memory>
#include <boost/endian/conversion.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/predef/hardware/simd.h>

#include "Export.h"

#include "EndianConfig.h"

#ifdef _MSC_VER
# include <stdlib.h>
# define bswap_32(x) _byteswap_ulong(x)
# define bswap_64(x) _byteswap_uint64(x)
#elif defined(__APPLE__)
// Mac OS X / Darwin features
# include <libkern/OSByteOrder.h>
# define bswap_32(x) OSSwapInt32(x)
# define bswap_64(x) OSSwapInt64(x)
#elif defined(__sun) || defined(sun)
# include <sys/byteorder.h>
# define bswap_32(x) BSWAP_32(x)
# define bswap_64(x) BSWAP_64(x)
#elif defined(__FreeBSD__)
# include <sys/endian.h>
# define bswap_32(x) bswap32(x)
# defiee bswap_64(x) bswap64(x)
#elif defined(__OpenBSD__)
# include <sys/types.h>
# define bswap_32(x) swap32(x)
# define bswap_64(x) swap64(x)
#elif defined(__NetBSD__)
# include <sys/types.h>
# include <machine/bswap.h>
# if defined(__BSWAP_RENAME) && !defined(__bswap_32)
# define bswap_32(x) bswap32(x)
# define bswap_64(x) bswap64(x)
# endif
#else
# include <byteswap.h>
#endif

namespace dbcppp
{
class NodeImpl;
struct DBCPPP_API SharedNodeCmp
{
bool operator()(const NodeImpl& lhs, const NodeImpl& rhs) const;
};
#if BOOST_ENDIAN_LITTLE_BYTE
inline void native_to_big_inplace(uint64_t& data) noexcept
{
boost::endian::native_to_big_inplace(data);
}
#else
inline void native_to_big_inplace(uint64_t& data) noexcept
{
}
#endif
#if BOOST_ENDIAN_BIG_BYTE
inline void native_to_little_inplace(uint64_t& data) noexcept
inline void native_to_big_inplace(uint64_t& value)
{
boost::endian::native_to_little_inplace(data);
if constexpr (dbcppp::Endian::Native == dbcppp::Endian::Little)
{
value = bswap_64(value);
}
}
#else
inline void native_to_little_inplace(uint64_t& data) noexcept
inline void native_to_little_inplace(uint64_t& value)
{
if constexpr (dbcppp::Endian::Native == dbcppp::Endian::Big)
{
value = bswap_64(value);
}
}
#endif
}
Loading

0 comments on commit 8ef59f6

Please sign in to comment.