Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimuNotMoe committed Mar 18, 2020
1 parent 5a05fc5 commit f38b2d4
Show file tree
Hide file tree
Showing 8 changed files with 589 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
image: ubuntu:19.10

stages:
- build
- test

before_script:
- apt-get update && apt-get -y install git build-essential cmake lcov

build:
stage: build
artifacts:
untracked: true
script:
- mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS='-O0 -g -pg -fprofile-arcs -ftest-coverage' -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg .. && make

test:
stage: test
dependencies:
- build
artifacts:
untracked: true
script:
- cd build
- sh -c './cpp-base64X-Test'
- lcov -d . -c --output-file app-raw.info
- lcov --remove app-raw.info ../3rdParty '/usr/include/*' -o app.info
- lcov -l app.info
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rdParty/base64"]
path = 3rdParty/base64
url = https://github.com/aklomp/base64
1 change: 1 addition & 0 deletions 3rdParty/base64
Submodule base64 added at e8f610
43 changes: 43 additions & 0 deletions 3rdParty/base64_default_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifdef __SSSE3__
#define HAVE_SSSE3 1
#else
#define HAVE_SSSE3 0
#endif

#ifdef __SSE4_1__
#define HAVE_SSE41 1
#else
#define HAVE_SSE41 0
#endif

#ifdef __SSE4_2__
#define HAVE_SSE42 1
#else
#define HAVE_SSE42 0
#endif

#ifdef __AVX__
#define HAVE_AVX 1
#else
#define HAVE_AVX 0
#endif

#ifdef __AVX2__
#define HAVE_AVX2 1
#else
#define HAVE_AVX2 0
#endif

#ifdef __ARM_NEON
#define HAVE_NEON32 1
#else
#define HAVE_NEON32 0
#endif

#ifndef HAVE_NEON64
#define HAVE_NEON64 0
#endif

#ifndef HAVE_FAST_UNALIGNED_ACCESS
#define HAVE_FAST_UNALIGNED_ACCESS 0
#endif
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.2)
project(cpp-base64X)

set(CMAKE_CXX_STANDARD 17)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/base64_default_config.h ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/base64/lib/config.h COPYONLY)

set(SOURCE_FILES_BASE64
3rdParty/base64/lib/arch/avx2/codec.c 3rdParty/base64/lib/arch/generic/codec.c
3rdParty/base64/lib/arch/neon32/codec.c 3rdParty/base64/lib/arch/neon64/codec.c
3rdParty/base64/lib/arch/ssse3/codec.c 3rdParty/base64/lib/arch/sse41/codec.c
3rdParty/base64/lib/arch/sse42/codec.c 3rdParty/base64/lib/arch/avx/codec.c
3rdParty/base64/lib/tables/tables.c
3rdParty/base64/lib/lib.c 3rdParty/base64/lib/codec_choose.c)
add_library(cpp-base64X ${SOURCE_FILES_BASE64})
SET_TARGET_PROPERTIES(cpp-base64X PROPERTIES COMPILE_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")

add_executable(cpp-base64X-Test test.cpp)
target_link_libraries(cpp-base64X-Test cpp-base64X)
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,100 @@
# cpp-base64
# cpp-base64X
Probably the most convenient & powerful C++ base64 library.

## Features
- Elegant & intuitive API
- Converts from/to different types
- Streamed operation
- Hardware accelerated

## Requirements
Reasonably new versions of:
- C++17 compatible compiler
- CMake

## Install
Use of the [CPM](https://github.com/TheLartians/CPM.cmake) package manager is recommended:

```cmake
include(cmake/CPM.cmake)
CPMAddPackage(
NAME cpp-base64X
GITHUB_REPOSITORY YukiWorkshop/cpp-base64X
VERSION 0.0.1
)
target_include_directories(your_project PUBLIC ${cpp-base64X_SOURCE_DIR})
target_link_libraries(your_project cpp-base64X)
```

Or manually clone & add:
```shell script
mkdir cpp_modules && cd cpp_modules
git clone --recursive https://github.com/YukiWorkshop/cpp-base64X
```

```cmake
add_subdirectory(cpp_modules/cpp-base64X)
target_include_directories(your_project PUBLIC cpp_modules/cpp-base64X)
target_link_libraries(your_project cpp-base64X)
```

## Usage
```cpp
#include <cpp-base64X.hpp>

using namespace YukiWorkshop;
```

One-time conversion:
```cpp
std::string s = Base64X::encode("Hello");
std::string s2 = Base64X::decode(s);
```

You can use different input/output types. But the return type is limited to `std::string` and `std::vector<uint8_t>`.

Note that you can only decode vectors which element size is 1 (`uint8_t`, `char`, etc).

From vectors instead of strings:
```cpp
std::vector<uint8_t> v = {0xaa, 0x55, 0x01, 0x02, 0x03};
std::vector<uint8_t> s = Base64X::encode(v);
std::string v2 = Base64X::decode(s);
```
And even vectors with doubles inside:
```cpp
std::vector<double> v = {3.14159265357, 42.42, 233.233, 666.666};
std::vector<uint8_t> s = Base64X::encode(v);
std::vector<uint8_t> v2 = Base64X::decode(s);
for (size_t i=0; i<4; i++) {
std::cout << ((double *)v2.data())[i] << " ";
}
```

Stream operators:
```cpp
std::string out;
Base64X::Encoder<std::string> e;
e >> out; // Set output target
e << "Hey guys, "
<< "this is Austin!"
<< nullptr; // Use nullptr for EOF
```

The classic equivalent of above:
```cpp
std::string out;
Base64X::Encoder<std::string> e;
out += e.encode("Hey guys, ");
out += e.encode("this is Austin!");
out += e.finalize();
```

## License
MIT

## Acknowledgements
This library makes use of [aklomp/base64](https://github.com/aklomp/base64), which is a great C base64 library.
Loading

0 comments on commit f38b2d4

Please sign in to comment.