Skip to content

Library Type Change, New Beta Adaptor CLI11 #54

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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4c500ab
update unittest
injae Apr 17, 2022
0fa1824
serdepp library type change
injae Apr 19, 2022
aec546e
dev dependencies rule update
injae Apr 19, 2022
31632ff
cmake script bugfix
injae Apr 19, 2022
17213ea
unittest file path change
injae Apr 19, 2022
9bc1c53
cov github action bugfix
injae Apr 19, 2022
81528af
code-cov bugfix
injae Apr 19, 2022
beeb873
codeCov github action update
injae Apr 19, 2022
5a44b83
codeCov github action update
injae Apr 19, 2022
7cac421
new adaptor [beta] cli11
injae Apr 20, 2022
782c826
cppkg thirdparty bugfix
injae Apr 20, 2022
8984ffa
yaml-cpp version down
injae Apr 20, 2022
18478bc
github action unused flag remove
injae Apr 20, 2022
a88a044
cppkg cli11 bugfix
injae Apr 20, 2022
ac0fc0c
cli11 folder bug
injae Apr 20, 2022
a940d22
cli11 import bugtest
injae Apr 20, 2022
3fdd877
cppkg cli11 update
injae Apr 20, 2022
873397c
cli11 disable
injae Apr 20, 2022
2a14017
new adaptor library cli11
injae Apr 22, 2022
7feff96
cli11 find bugfix
injae Apr 23, 2022
22a8574
git bug fix
injae Apr 23, 2022
419c423
CLI11 git bugfix
injae Apr 23, 2022
0c5f539
new alias type cli11_t
injae Apr 23, 2022
3a0e342
new attributes utility macro function
injae Apr 23, 2022
2760979
cli11 adaptor update and new syntax sugar function attrs()
injae Apr 23, 2022
02b02f0
cli11 example update and readme update
injae Apr 24, 2022
57c7a4d
add cli_parser function
injae Apr 24, 2022
9aff7ea
new attributes skip_if_not_adaptor or skip_if_adatpor
injae Apr 24, 2022
e8d1350
unittest update
injae Apr 24, 2022
5ee267a
github action code-cov update
injae Apr 24, 2022
e287ff4
unittest update
injae Apr 24, 2022
b7bb508
unittest update
injae Apr 24, 2022
0322464
add annotation [[maybe_unused]]
injae May 7, 2022
2a63036
new helper is_adaptor_v
injae May 15, 2022
2295513
cli11 adaptor support update
injae May 15, 2022
7c63e85
remove example/reflection.cpp unused waring
injae May 15, 2022
9e5113a
formatting
injae Sep 17, 2022
78d99de
readme update
injae Sep 17, 2022
8d05448
readme update
injae Sep 17, 2022
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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: none
IndentWidth: 4
10 changes: 5 additions & 5 deletions .github/workflows/code-cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
ubuntu-bionic-llvm-code-cov:
runs-on: ubuntu-18.04
env:
CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
CMAKE_FLAGS: '-DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
strategy:
matrix:
build-type: ['Debug']
Expand Down Expand Up @@ -37,14 +37,14 @@ jobs:
cmake --build . --config ${{matrix.build-type}}
- name: Generate Coverage Report
run: |
cd build/${{matrix.build-type}}
./unittest
cd build
./${{matrix.build-type}}/unittest
llvm-profdata-${{matrix.clang-version}} merge -sparse default.profraw -o default.profdata
llvm-cov-${{matrix.clang-version}} export ./unittest --instr-profile default.profdata -format=lcov >> lcov.info
llvm-cov-${{matrix.clang-version}} export ${{matrix.build-type}}/unittest --instr-profile default.profdata -format=lcov >> lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
directory: ./build/${{matrix.build-type}}
directory: ./build
files: lcov.info
flags: unittest
fail_ci_if_error: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
ubuntu-bionic-gcc:
runs-on: ubuntu-18.04
env:
CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
CMAKE_FLAGS: '-DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
strategy:
matrix:
build-type: ['Release', 'Debug']
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
ubuntu-bionic-llvm:
runs-on: ubuntu-18.04
env:
CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
CMAKE_FLAGS: '-DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON'
strategy:
matrix:
build-type: ['Release', 'Debug']
Expand Down
41 changes: 31 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ set(CPPM_VERSION 0.0.13)
include(cmake/cppm_loader.cmake)
cppm_project()

project(serdepp VERSION 0.1.4 LANGUAGES C CXX)
project(serdepp VERSION 0.1.5 LANGUAGES C CXX)
cppm_setting()
cppm_cxx_standard(17)
cppm_compiler_option(
DEBUG
CLANG "-fprofile-instr-generate -fcoverage-mapping"
)

find_cppkg(benchmark 1.5.2 MODULE benchmark::benchmark TYPE lib OPTIONAL OFF)
find_cppkg(RapidJSON 1.1.1 MODULE rapidjson TYPE lib OPTIONAL OFF)
find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json TYPE lib OPTIONAL OFF)
find_cppkg(Catch2 2.9.1 MODULE Catch2::Catch2 TYPE lib OPTIONAL OFF)
find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib OPTIONAL OFF)
find_cppkg(yaml-cpp 0.7.0 MODULE yaml-cpp TYPE lib OPTIONAL OFF)
find_cppkg(fmt 8.0.1 MODULE fmt::fmt-header-only TYPE lib OPTIONAL OFF)
find_cppkg(benchmark 1.5.2 MODULE benchmark::benchmark TYPE lib OPTIONAL OFF)
find_cppkg(magic_enum 0.7.3 MODULE magic_enum::magic_enum TYPE lib)
find_cppkg(nameof 0.10.0 MODULE nameof::nameof TYPE lib)

if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR (SERDEPP_BUILD_EXAMPLES OR (SERDEPP_BUILD_TESTING)))
find_cppkg(CLI11 2.2.0 MODULE CLI11::CLI11 TYPE lib)
find_cppkg(RapidJSON 1.1.1 MODULE rapidjson TYPE lib)
find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json TYPE lib)
find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib)
find_cppkg(yaml-cpp 0.6.3 MODULE yaml-cpp TYPE lib)
find_cppkg(fmt 8.0.1 MODULE fmt::fmt-header-only TYPE lib)
endif()


cppm_target_define(serdepp STATIC
cppm_target_define(serdepp INTERFACE
SOURCES
src/to_static.cpp
)
Expand Down Expand Up @@ -86,6 +90,11 @@ SOURCES
examples/pointer.cpp
)

cppm_target_define(cli11 BINARY
SOURCES
examples/cli11.cpp
)

endif()

cppm_unit_test_area()
Expand All @@ -95,10 +104,14 @@ cppm_target_define(unittest BINARY
SOURCES
tests/rapid_json.cpp
tests/catch_main.cpp
tests/test.yaml
tests/test.json
tests/yaml_cpp.cpp
tests/attribute.cpp
tests/toml11.cpp
tests/reflection.cpp
tests/nlohmann_json.cpp
tests/test.toml
tests/test_struct.hpp
)

Expand All @@ -124,8 +137,11 @@ SOURCES

endif()

set(serdepp_global_deps PRIVATE benchmark Catch2
PUBLIC RapidJSON nlohmann_json toml11 yaml-cpp fmt magic_enum nameof)
set(serdepp_global_deps PRIVATE Catch2 benchmark
PUBLIC magic_enum nameof)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR (SERDEPP_BUILD_EXAMPLES OR (SERDEPP_BUILD_TESTING)))
list(APPEND serdepp_global_deps PRIVATE CLI11 RapidJSON nlohmann_json toml11 yaml-cpp fmt)
endif()
cppm_target_dependencies(serdepp
${serdepp_global_deps})

Expand Down Expand Up @@ -173,6 +189,10 @@ cppm_target_dependencies(pointer
${serdepp_global_deps}
serdepp)

cppm_target_dependencies(cli11
${serdepp_global_deps}
serdepp)

cppm_target_dependencies(unittest
${serdepp_global_deps}
serdepp)
Expand Down Expand Up @@ -203,4 +223,5 @@ cppm_target_install(sugar)
cppm_target_install(reflection)
cppm_target_install(print)
cppm_target_install(pointer)
cppm_target_install(cli11)

150 changes: 46 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Serdepp [![Linux](https://github.com/injae/serdepp/actions/workflows/linux.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/linux.yml) [![Windows](https://github.com/injae/serdepp/actions/workflows/window.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/window.yml) [![MacOS](https://github.com/injae/serdepp/actions/workflows/macos.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/macos.yml)[![codecov](https://codecov.io/gh/injae/serdepp/branch/main/graph/badge.svg?token=2L217GF77B)](https://codecov.io/gh/injae/serdepp)
# Serdepp
[![Vcpkg package](https://img.shields.io/badge/Vcpkg-package-blueviolet)](https://github.com/microsoft/vcpkg/tree/master/ports/serdepp)
[![Conan package](https://img.shields.io/badge/Conan-package-blueviolet)](https://conan.io/center/serdepp?os&tab=overview)
[![Linux](https://github.com/injae/serdepp/actions/workflows/linux.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/linux.yml)
[![Windows](https://github.com/injae/serdepp/actions/workflows/window.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/window.yml)
[![MacOS](https://github.com/injae/serdepp/actions/workflows/macos.yml/badge.svg)](https://github.com/injae/serdepp/actions/workflows/macos.yml)
[![codecov](https://codecov.io/gh/injae/serdepp/branch/main/graph/badge.svg?token=2L217GF77B)](https://codecov.io/gh/injae/serdepp)
c++17 low cost serialize deserialize adaptor library like rust serde.rs
- [Features](#Features)
- [Get Started](#Get-Started)
Expand All @@ -22,11 +28,11 @@ c++17 low cost serialize deserialize adaptor library like rust serde.rs

## Features
- [x] low cost serializer, deserializer adaptor
- [x] json serialize, deserialize (with [rapidjson](https://github.com/Tencent/rapidjson))
- [x] json serialize, deserialize (with [nlohmann_json](https://github.com/nlohmann/json))
- [x] json serialize, deserialize (with [rapidjson](https://github.com/Tencent/rapidjson), with [nlohmann_json](https://github.com/nlohmann/json))
- [x] toml serialize, deserialize (with [toml11](https://github.com/ToruNiina/toml11))
- [x] yaml serialize, deserialize (with [yaml-cpp](https://github.com/jbeder/yaml-cpp))
- [x] [fmt](https://github.com/fmtlib/fmt) support
- [x] cli parser serialize (with [CLI11](https://github.com/CLIUtils/CLI11))
- [x] string formatter [fmt](https://github.com/fmtlib/fmt) support
- [x] std::cout(ostream) support
- [x] struct, class support
- [x] nested struct, class support
Expand All @@ -44,6 +50,7 @@ c++17 low cost serialize deserialize adaptor library like rust serde.rs
## Get Started
```cpp
#include <serdepp/serde.hpp>

#include <serdepp/adaptor/nlohmann_json.hpp>

enum class t_enum { A, B };
Expand All @@ -60,14 +67,15 @@ struct example {
int number_;
std::vector<std::string> vec_;
std::optional<std::vector<std::string>> opt_vec_;

t_enum tenum_;
};
};


int main() {
example ex;
ex.number_ = 1024;

ex.vec_ = {"a", "b", "c"};
ex.vec_ = {"a", "b", "c"};
ex.tenum_ = t_enum::B;
//std::cout << ex << "\n";

Expand All @@ -94,30 +102,40 @@ fmt:{"vec: {"a", "b", "c"}", "t_enum: B"}
## Dependencies
- [nameof](https://github.com/Neargye/nameof) (Auto Install)
- [magic_enum](https://github.com/Neargye/magic_enum) (Auto Install)
- [fmt](https://github.com/fmtlib/fmt) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_FMT=ON)
- [nlohmann_json](https://github.com/nlohmann/json) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_NLOHMANN_JSON=ON)
- [rapidjson](https://github.com/Tencent/rapidjson) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_RAPIDJSON=ON)
- [toml11](https://github.com/ToruNiina/toml11) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_TOML11=ON)
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) (optional) (Install CMAKE FLAG: -DSERDEPP_USE_YAML-CPP=ON)


## Adaptor Libraries
- [fmt](https://github.com/fmtlib/fmt) with [fmt.hpp](./include/serdepp/adaptor/fmt.hpp)
- [nlohmann_json](https://github.com/nlohmann/json) with [nlohmann_json.hpp](./include/serdepp/adaptor/nlohmann_json.hpp)
- [rapidjson](https://github.com/Tencent/rapidjson) with [rapidjson.hpp](./include/serdepp/adaptor/rapidjson.hpp)
- [toml11](https://github.com/ToruNiina/toml11) with [toml11.hpp](./include/serdepp/adaptor/toml11.hpp)
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) with [yaml-cpp.hpp](./include/serdepp/adaptor/yaml-cpp.hpp)
- [CLI11](https://github.com/CLIUtils/CLI11) with [cli11.hpp](./include/serdepp/adaptor/cli11.hpp), [attribute/cli11.hpp](./include/serdepp/attribute/cli11.hpp)

## Install With Vcpkg
```console
vcpkg install serdepp
# with other adaptors <nlohmann-json|toml11|yaml-cpp|fmt|rapidjson>
# with other adaptors <nlohmann-json|toml11|yaml-cpp|fmt|rapidjson,cli11>
vcpkg install ${adaptor}
```

## CMake With Vcpkg
```cmake
find_package(serdepp CONFIG)
target_link_libraries(${target name} PRIVATE serdepp::serdepp)
# with adaptors
# names (nlohmann_json, yaml-cpp, toml11, RapidJson, fmt)
# targets (nlohmann_json::nlohmann_json, yaml-cpp, toml11::toml11, rapidjson, fmt::fmt-header-only)
find_package(${adaptor name} CONFIG)
target_link_libraries(${target name} PRIVATE ${adaptor cmake target})
```
# with nlohmann-json adaptor
vcpkg install nlohmann-json

# with toml11 adaptor
vcpkg install toml11

# with yaml-cpp adaptor
vcpkg install yaml-cpp

# with fmt adaptor
vcpkg install fmt

# with rapidjson adaptor
vcpkg install rapidjson

# with cli11 adaptor
vcpkg install cli11
```
## Install
```console
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release .
Expand Down Expand Up @@ -198,6 +216,8 @@ private:
class test {
public:
DERIVE_SERDE(test, (&Self::str, "str")(&Self::i, "i")(&Self::vec, "vec"))
// Macro Version
// DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec))
private:
std::string str;
int i;
Expand Down Expand Up @@ -248,7 +268,8 @@ struct A {
};

int main(int argc, char* argv[]) {
constexpr auto info = serde::type_info<A>;
constexpr auto info = serde::type_info<A>
;
static_assert(serde::type_info<A>.size == 5);
static_assert(serde::tuple_size_v<A> == 5);
static_assert(std::is_same_v<serde::to_tuple_t<A>, std::tuple<int, std::string, double, std::vector<int>, int>>);
Expand Down Expand Up @@ -277,73 +298,6 @@ int main(int argc, char* argv[]) {
return 0;
}
```

## [Simple Example](./examples/simple_example.cpp)
```cpp
#include <serdepp/serializer.hpp>
#include <serdepp/adaptor/nlohmann_json.hpp>
#include <serdepp/adaptor/toml11.hpp>
#include <serdepp/adaptor/yaml-cpp.hpp>
#include <serdepp/adaptor/fmt.hpp>

using namespace serde::ostream;

enum class tenum {
INPUT,
OUTPUT,
};

class test {
public:
template<class Context>
constexpr static auto serde(Context& context, test& value) {
using Self = test;
serde::serde_struct(context, value)
.field(&Self::str, "str") // or (&test::str, "str")
.field(&Self::i, "i")
.field(&Self::vec, "vec")
.field(&Self::io, "io")
.field(&Self::pri, "pri")
.field(&Self::m , "m");
}
std::optional<std::string> str;
int i;
std::optional<std::vector<std::string>> vec;
tenum io;
std::map<std::string, std::string> m;
private:
std::string pri;
};

int main()
{
nlohmann::json v = R"({
"i": 10,
"vec": [ "one", "two", "three" ],
"io": "INPUT",
"pri" : "pri",
"m" : { "a" : "1",
"b" : "2",
"c" : "3" }
})"_json;

test t = serde::deserialize<test>(v);

auto v_to_json = serde::serialize<nlohmann::json>(t);
auto v_to_toml = serde::serialize<serde::toml_v>(t);
auto v_to_yaml = serde::serialize<serde::yaml>(t);

test t_from_toml = serde::deserialize<test>(v_to_toml);
test t_from_yaml = serde::deserialize<test>(v_to_yaml);

fmt::print("{}\n", t);
std::cout << t << '\n';

return 0;
}
```


### [Nested Class Example](./examples/example.cpp)
```cpp
#include <serdepp/serializer.hpp>
Expand All @@ -352,11 +306,6 @@ int main()
#include <serdepp/adaptor/fmt.hpp>
#include <serdepp/attributes.hpp>

/// optional beta feature (for std::cout)
#include <serdepp/ostream.hpp>
using namespace serde::ostream;
///

enum class tenum {
INPUT = 1,
OUTPUT = 2,
Expand Down Expand Up @@ -451,9 +400,6 @@ int main()
// class(test) -> string
fmt::print("{}\n", t);

// beta feature
// need: #include <erdepp/ostream.hpp>
// need: using namespace serdepp::ostream;
// class(test) -> string
std:cout << t << '\n';
//
Expand Down Expand Up @@ -738,7 +684,3 @@ yaml_get_tl_bench 30182 ns 30155 ns 23070
rapid_json_set_se_bench 398 ns 397 ns 1743184
rapid_json_get_se_bench 2099 ns 2096 ns 331971
```

## Projects using this library
- [cppm](https://github.com/injae/cppm): cross platform c++ package manager
- [cpcli](https://github.com/injae/cpcli): c++ command line parser
3 changes: 1 addition & 2 deletions cmake/cppm-tools-0.0.12/cppm/target_define.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ function(cppm_target_define)
endfunction()

macro(cppm_unit_test_area)
#cmake_parse_arguments(ARG "Catch2" "" "" ${ARGN})
string(TOUPPER ${CMAKE_PROJECT_NAME} upper_name)
cmake_dependent_option(${upper_name}_BUILD_TESTING "${CMAKE_PROJECT_NAME} build test" ON "cppm_is_debug" OFF)
option(${upper_name}_BUILD_TESTING "${CMAKE_PROJECT_NAME} build test" OFF)
if(${${upper_name}_BUILD_TESTING})
include(CTest)
set(__cppm_unit_test_area__ ON)
Expand Down
Loading