-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e311683
commit 9074cd8
Showing
8 changed files
with
596 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "ax.core"] | ||
path = ax.core | ||
url = https://github.com/Mototroller/ax.core.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
sudo: required | ||
dist: precise | ||
language: cpp | ||
|
||
matrix: | ||
include: | ||
- compiler: gcc | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- g++-5 | ||
env: COMPILER=g++-5 | ||
- compiler: clang | ||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
- llvm-toolchain-precise-3.7 | ||
packages: | ||
- clang-3.7 | ||
env: COMPILER=clang++-3.7 | ||
|
||
before_install: | ||
- sudo apt-get update -qq | ||
|
||
script: | ||
- mkdir build | ||
- cd build | ||
- cmake -DCMAKE_CXX_COMPILER=$COMPILER .. && make | ||
- ./AX_PREFIX_TEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required (VERSION 2.8.7) | ||
project (AX_PREFIX_TEST) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic") | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native") | ||
|
||
set(SRC_LIST tests/tests.cpp) | ||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ax.core/include) | ||
include_directories(${PROJECT_NAME} include) | ||
|
||
add_executable(${PROJECT_NAME} ${SRC_LIST}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# preFIX | ||
# preFIX [](https://travis-ci.org/Mototroller/preFIX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cstdint> | ||
#include <cstring> | ||
#include <iomanip> | ||
#include <limits> | ||
#include <sstream> | ||
#include <string> | ||
#include <type_traits> | ||
|
||
#define LOG_HEAD "[preFIX]: " | ||
|
||
namespace preFIX { | ||
|
||
using size_t = std::size_t; | ||
|
||
enum : char { SOH = 0x1 }; | ||
|
||
/// Peplaces SOH inside string by given symbol ('|' by default) | ||
std::string replace_SOH(std::string str, char symbol = '|') { | ||
std::replace(str.begin(), str.end(), char(SOH), symbol); | ||
return str; | ||
} | ||
|
||
/*// Contains compile-time djb2 hash implementation | ||
namespace hash { | ||
constexpr size_t djb2_impl(char const* str, size_t hash) { | ||
return *str == char{0} ? hash : | ||
djb2_impl(str + 1, ((hash << 5) + hash) + *str); | ||
} | ||
constexpr size_t djb2(char const* str) { | ||
return djb2_impl(str, 5381); } | ||
/// some_tpl<H("string")> | ||
constexpr size_t H(char const* str) { | ||
return djb2(str); } | ||
/// some_tpl<"string"__> | ||
constexpr size_t operator ""__(char const* str, size_t) { | ||
return H(str); } | ||
} | ||
namespace meta { | ||
/// Concatenates two tuple-like classes | ||
template <class U, class V> | ||
struct tuple_concat; | ||
template < | ||
template <class...> class T, | ||
class... Alist, | ||
class... Blist | ||
> struct tuple_concat<T<Alist...>, T<Blist...>> { using type = T<Alist..., Blist...>; }; | ||
template <typename U, typename V> | ||
using tuple_concat_t = typename tuple_concat<U,V>::type; | ||
/// Pushes type to tuple-like class | ||
template <class Tuple, class T> | ||
struct tuple_push; | ||
template < | ||
template <class...> class Tuple, | ||
class... Args, | ||
class T | ||
> struct tuple_push<Tuple<Args...>,T> { using type = Tuple<Args..., T>; }; | ||
template <typename Tuple, typename T> | ||
using tuple_push_t = typename tuple_push<Tuple,T>::type; | ||
} | ||
//*/ | ||
|
||
/// Contains basic types arithmetics and mapping (FIX <=> native) | ||
namespace types { | ||
|
||
/// Default serializer: {ostringstream(dst) << value} | ||
template <typename T> | ||
struct sstream_serializer { | ||
template <typename U> | ||
static size_t serialize(char* dst, U&& value, char delimiter = SOH) { | ||
std::ostringstream ss; ss << std::forward<U>(value); | ||
std::string str = ss.str(); | ||
std::memcpy(dst, str.data(), str.size()); | ||
dst[str.size()] = delimiter; | ||
return str.size() + 1; | ||
} | ||
}; | ||
|
||
/// Default deserializer: {istringstream(src) >> value} | ||
template <typename T> | ||
struct sstream_deserializer { | ||
template <typename U> | ||
static size_t deserialize(char const* src, U& value, char delimiter = SOH) { | ||
std::string str(src, static_cast<char const*>(std::strchr(src, delimiter))); | ||
std::istringstream ss(str); ss >> value; | ||
return str.size() + 1; | ||
} | ||
}; | ||
|
||
/// Special serializer | ||
template <size_t Width> | ||
struct fixed_width_int_serializer { | ||
template <typename U> | ||
static size_t serialize(char* dst, U&& value, char delimiter = SOH) { | ||
std::ostringstream ss; | ||
ss << std::setfill('0') << std::setw(Width) << std::forward<U>(value); | ||
std::string str = ss.str(); | ||
std::memcpy(dst, str.data(), str.size()); | ||
dst[str.size()] = delimiter; | ||
return str.size() + 1; | ||
} | ||
}; | ||
|
||
template < | ||
typename T, | ||
class serializer = sstream_serializer<T>, | ||
class deserializer = sstream_deserializer<T> | ||
> | ||
struct base_t : serializer, deserializer { | ||
using underlying_type = T; | ||
underlying_type value; | ||
|
||
base_t() = default; | ||
explicit base_t(underlying_type const& v) : value(v) {} | ||
|
||
template <typename U> | ||
base_t& operator=(U&& v) { | ||
value = std::forward<U>(v); | ||
return *this; | ||
} | ||
|
||
using serializer::serialize; | ||
using deserializer::deserialize; | ||
|
||
size_t serialize(char* dst) const { | ||
return serialize(dst, value); } | ||
|
||
size_t deserialize(char const* src) { | ||
return deserialize(src, value); } | ||
}; | ||
|
||
using Int = base_t<size_t>; | ||
using Float = base_t<double>; | ||
using Char = base_t<char>; | ||
using String = base_t<std::string>; | ||
|
||
template <size_t Width> | ||
using Fixed = base_t<int, fixed_width_int_serializer<Width>>; | ||
|
||
/// Writes preamble: "TAG=", @returns populated size | ||
size_t serialize_tag(char* dst, int tag) { | ||
return types::Int::serialize(dst, tag, '='); } | ||
|
||
/// Parses preamble: "TAG=" => tag, @returns read size | ||
size_t deserialize_tag(char const* src, int& tag) { | ||
return types::Int::deserialize(src, tag, '='); } | ||
} | ||
|
||
|
||
|
||
} // preFIX | ||
|
||
#undef LOG_HEAD |
Oops, something went wrong.