From 633fa9d8bd081141e98290f83e8d8a15cad02f50 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 10 Mar 2014 19:33:06 +0400 Subject: [PATCH] Bitarray copy algorithm was moved to C++ source file, thus C compiler is no longer required --- libuavcan/CMakeLists.txt | 8 +------- .../include/uavcan/internal/marshal/bit_stream.hpp | 3 +-- .../marshal/{bit_array_copy.c => bit_array_copy.cpp} | 12 +++++++++--- 3 files changed, 11 insertions(+), 12 deletions(-) rename libuavcan/src/internal/marshal/{bit_array_copy.c => bit_array_copy.cpp} (97%) diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index 05a7c1ec26..dfe0d76b7d 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -15,19 +15,13 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O1 -DNDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-g3 -DUAVCAN_DEBUG=1 -DDEBUG=1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -Wall -Wextra -Werror -pedantic -Wno-variadic-macros") -set(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}) -set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}) -set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic") - include_directories(include) # # libuavcan # file(GLOB_RECURSE LIBUAVCAN_CXX_FILES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp") -file(GLOB_RECURSE LIBUAVCAN_C_FILES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c") -add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES} ${LIBUAVCAN_C_FILES}) +add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES}) # TODO installation rules diff --git a/libuavcan/include/uavcan/internal/marshal/bit_stream.hpp b/libuavcan/include/uavcan/internal/marshal/bit_stream.hpp index 7cf907dbe8..ea3b49b170 100644 --- a/libuavcan/include/uavcan/internal/marshal/bit_stream.hpp +++ b/libuavcan/include/uavcan/internal/marshal/bit_stream.hpp @@ -13,8 +13,7 @@ namespace uavcan { -extern "C" void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, - unsigned char *dst_org, int dst_offset); +void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, unsigned char *dst_org, int dst_offset); class BitStream { diff --git a/libuavcan/src/internal/marshal/bit_array_copy.c b/libuavcan/src/internal/marshal/bit_array_copy.cpp similarity index 97% rename from libuavcan/src/internal/marshal/bit_array_copy.c rename to libuavcan/src/internal/marshal/bit_array_copy.cpp index 15441a56d7..61671283d2 100644 --- a/libuavcan/src/internal/marshal/bit_array_copy.c +++ b/libuavcan/src/internal/marshal/bit_array_copy.cpp @@ -3,9 +3,9 @@ * Source: http://stackoverflow.com/questions/3534535/whats-a-time-efficient-algorithm-to-copy-unaligned-bit-arrays */ -#include -#include -#include +#include +#include +#include #define PREPARE_FIRST_COPY() \ do { \ @@ -19,11 +19,15 @@ src_len = 0; \ } } while (0) +namespace uavcan +{ void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, unsigned char *dst_org, int dst_offset) { + using namespace std; + static const unsigned char reverse_mask[] = { 0x55, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; static const unsigned char reverse_mask_xor[] = @@ -117,3 +121,5 @@ bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, } } } + +}