From 4c500ab9ff52ae52481e0c69b23f03e125bd0412 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Mon, 18 Apr 2022 00:55:32 +0900 Subject: [PATCH 01/39] update unittest - add serde::parse_file --- tests/nlohmann_json.cpp | 14 ++------------ tests/rapid_json.cpp | 11 +---------- tests/test.json | 8 ++++++++ tests/test.toml | 11 +++++++++++ tests/test.yaml | 12 ++++++++++++ tests/test_struct.hpp | 19 +++++++++++++++++++ tests/toml11.cpp | 15 +-------------- tests/yaml_cpp.cpp | 19 ++----------------- 8 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 tests/test.json create mode 100644 tests/test.toml create mode 100644 tests/test.yaml diff --git a/tests/nlohmann_json.cpp b/tests/nlohmann_json.cpp index 5d6d722..04a32f8 100644 --- a/tests/nlohmann_json.cpp +++ b/tests/nlohmann_json.cpp @@ -4,20 +4,10 @@ #include -nlohmann::json json_v = R"({ -"str" : "hello", -"i": 10, -"vec": [ "one", "two", "three"], -"sm": { "one" : "tone", "two" : "ttwo"}, -"opt": "hello", -"sub" : { "str": "hello" } -})"_json; - using namespace serde; + TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") { + auto json_v = serde::parse_file("../../tests/test.json"); REQUIRE(json_v.dump() == serialize(deserialize(json_v)).dump()); } - - - diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 0998101..6b4bf9b 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -13,16 +13,7 @@ std::string str(rapidjson::Document& doc) { using namespace serde; TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { - rapidjson::Document json_v; - json_v.Parse(R"({ -"str" : "hello", -"i": 10, -"vec": [ "one", "two", "three"], -"opt": "hello", -"sm": { "one" : "tone", "two" : "ttwo"}, -"sub" : { "str": "hello" } -})"); + auto json_v = serde::parse_file("../../tests/test.json"); rapidjson::Document json_c = serialize(deserialize(json_v)); - REQUIRE(str(json_v) == str(json_c)); } diff --git a/tests/test.json b/tests/test.json new file mode 100644 index 0000000..9ed3d19 --- /dev/null +++ b/tests/test.json @@ -0,0 +1,8 @@ +{ +"str" : "hello", +"i": 10, +"vec": [ "one", "two", "three"], +"opt": "hello", +"sm": { "one" : "tone", "two" : "ttwo"}, +"sub" : { "str": "hello" } +} diff --git a/tests/test.toml b/tests/test.toml new file mode 100644 index 0000000..ae0a75c --- /dev/null +++ b/tests/test.toml @@ -0,0 +1,11 @@ +str = "hello" +i = 10 +vec = [ "one", "two", "three" ] +opt = "hello" + +[sm] +one = "tone" +two = "ttwo" + +[sub] +str = "hello" \ No newline at end of file diff --git a/tests/test.yaml b/tests/test.yaml new file mode 100644 index 0000000..c19ca96 --- /dev/null +++ b/tests/test.yaml @@ -0,0 +1,12 @@ +str: hello +i: 10 +vec: +- one +- two +- three +opt: hello +sm: + one: tone + two: ttwo +sub: + str: hello diff --git a/tests/test_struct.hpp b/tests/test_struct.hpp index 6945b1a..28b97bf 100644 --- a/tests/test_struct.hpp +++ b/tests/test_struct.hpp @@ -10,6 +10,18 @@ struct nested { std::string str; }; +struct Rect { + DERIVE_SERDE(Rect, (&Self::width, "width")(&Self::height, "height")) + int width; + int height; +}; + +struct Circle { + DERIVE_SERDE(Circle, (&Self::radius, "radius")) + int radius; +}; + + struct test { DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec)_SF_(opt)_SF_(none_opt)_SF_(sm)_SF_(sub)) std::string str; @@ -21,5 +33,12 @@ struct test { nested sub; }; +struct variant_test { + DERIVE_SERDE(variant_test, _SF_(opt_var)_SF_(var)) + std::variant opt_var; + std::variant var; +}; + + #endif diff --git a/tests/toml11.cpp b/tests/toml11.cpp index acc0f9a..61a33be 100644 --- a/tests/toml11.cpp +++ b/tests/toml11.cpp @@ -6,20 +6,7 @@ using namespace serde; using namespace toml::literals; -toml::value toml_vl = R"( -str = "hello" -i = 10 -vec = [ "one", "two", "three" ] -opt = "hello" - -[sm] -one = "tone" -two = "ttwo" - -[sub] -str = "hello" -)"_toml; - TEST_CASE("4: toml11 struct (pass)", "[multi-file:4]") { + auto toml_vl = serde::parse_file("../../tests/test.toml"); REQUIRE(toml_vl == serialize(deserialize(toml_vl))); } diff --git a/tests/yaml_cpp.cpp b/tests/yaml_cpp.cpp index 3772205..137e269 100644 --- a/tests/yaml_cpp.cpp +++ b/tests/yaml_cpp.cpp @@ -2,28 +2,13 @@ #include "test_struct.hpp" #include - -YAML::Node yaml_v = YAML::Load(R"( -str: hello -i: 10 -vec: -- one -- two -- three -opt: hello -sm: - one: tone - two: ttwo -sub: - str: hello -)"); - using namespace serde; TEST_CASE("5: yaml-cpp struct (pass)", "[multi-file:5]") { + std::ostringstream convert; + auto yaml_v = serde::parse_file("../../tests/test.yaml"); std::ostringstream origin; origin << yaml_v; - std::ostringstream convert; convert << serialize(deserialize(yaml_v)); REQUIRE(origin.str() == convert.str()); From 0fa1824983e477cdfae9e20e4c8f8441c98195f2 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 00:16:21 +0900 Subject: [PATCH 02/39] serdepp library type change static library -> header-only library optional dependencies install option removed --- CMakeLists.txt | 27 +++++++---- README.md | 46 ++++++++++--------- .../cppm/target_define.cmake | 3 +- cppm.toml | 32 ++++++++----- 4 files changed, 64 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d9944..3810ac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,18 +12,21 @@ cppm_compiler_option( 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") +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.7.0 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 ) @@ -95,10 +98,13 @@ 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/toml11.cpp tests/reflection.cpp tests/nlohmann_json.cpp + tests/test.toml tests/test_struct.hpp ) @@ -124,8 +130,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") + list(APPEND serdepp_global_deps PRIVATE RapidJSON nlohmann_json toml11 yaml-cpp fmt) +endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) diff --git a/README.md b/README.md index 71c5cbb..96b3728 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,10 @@ 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] string formatter [fmt](https://github.com/fmtlib/fmt) support - [x] std::cout(ostream) support - [x] struct, class support - [x] nested struct, class support @@ -66,8 +65,7 @@ struct example { 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"; @@ -94,30 +92,36 @@ 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) ## Install With Vcpkg ```console vcpkg install serdepp # with other adaptors 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 +``` ## Install ```console cmake -Bbuild -DCMAKE_BUILD_TYPE=Release . diff --git a/cmake/cppm-tools-0.0.12/cppm/target_define.cmake b/cmake/cppm-tools-0.0.12/cppm/target_define.cmake index 5afa39a..95edf79 100644 --- a/cmake/cppm-tools-0.0.12/cppm/target_define.cmake +++ b/cmake/cppm-tools-0.0.12/cppm/target_define.cmake @@ -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) diff --git a/cppm.toml b/cppm.toml index c47716b..3712208 100644 --- a/cppm.toml +++ b/cppm.toml @@ -11,11 +11,10 @@ clang = "-fprofile-instr-generate -fcoverage-mapping" [lib] - name = "serdepp" - type = "static" - #type = "header-only" - source= ["src/to_static.cpp"] - + name = "serdepp" + #type = "static" + type = "header-only" + source= ["src/to_static.cpp"] [[example]] name = "serde_example1" @@ -61,6 +60,10 @@ name = "pointer" source = ["examples/pointer.cpp"] +#[[example]] +# name = "protobuf" +# source = ["examples/protobuf.cpp", "examples/hello.pb.cc"] + #[[example]] # name = "tuple_sort" # source = ["examples/tuple_sort.cpp"] @@ -89,20 +92,25 @@ name = "unittest" source = ["tests/.*"] + [dependencies] nameof = { version="0.10.0", link="public"} magic_enum = { version= "0.7.3", link="public"} - fmt = {version="8.0.1", link="public", optional=true} - yaml-cpp = { version="0.7.0", link="public", optional=true} - toml11 = { version="3.7.0", link="public", optional=true} - nlohmann_json = { version="3.10.5", link="public", optional=true} - RapidJSON = { version="1.1.1", link="public", optional=true} benchmark = { version="1.5.2", optional=true} Catch2 = {version="2.9.1", optional=true} + +# example, benchmark, debug dependencies +[dev-dependencies] + fmt = "8.0.1" + yaml-cpp ="0.7.0" + toml11 ="3.7.0" + nlohmann_json = "3.10.5" + RapidJSON = "1.1.1" + #CLI11 = "2.2.0" #pybind11 = "2.9.0" + #Protobuf = "3.20.0" #hiredis = "git" #"redis++" = "1.3.2" #simdjson = {version="0.9.7", link="public"} #ryml = { version= "0.2.0", link="public", optional=true} - #sol2 = { version="3.2.2"} -#[dev-dependencies] + #sol2 = { version="3.2.2"} \ No newline at end of file From aec546ea241c77c1b8a707ddac51d96c1921996f Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 00:41:59 +0900 Subject: [PATCH 03/39] dev dependencies rule update --- .clang-format | 2 ++ CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..37d601a --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: none +IndentWidth: 4 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3810ac0..75de72b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ 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") +if(CMAKE_BUILD_TYPE STREQUAL "Debug" or (SERDEPP_BUILD_EXAMPLES or (SERDEPP_BUILD_TESTING))) 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) @@ -132,7 +132,7 @@ endif() set(serdepp_global_deps PRIVATE Catch2 benchmark PUBLIC magic_enum nameof) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") +if(CMAKE_BUILD_TYPE STREQUAL "Debug" or (SERDEPP_BUILD_EXAMPLES or (SERDEPP_BUILD_TESTING))) list(APPEND serdepp_global_deps PRIVATE RapidJSON nlohmann_json toml11 yaml-cpp fmt) endif() cppm_target_dependencies(serdepp From 31632ff6c3ed09b999d4187f0833f7f2d25e0bc0 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 00:48:40 +0900 Subject: [PATCH 04/39] cmake script bugfix --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75de72b..72aa117 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ 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))) +if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR (SERDEPP_BUILD_EXAMPLES OR (SERDEPP_BUILD_TESTING))) 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) @@ -132,7 +132,7 @@ endif() 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))) +if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR (SERDEPP_BUILD_EXAMPLES OR (SERDEPP_BUILD_TESTING))) list(APPEND serdepp_global_deps PRIVATE RapidJSON nlohmann_json toml11 yaml-cpp fmt) endif() cppm_target_dependencies(serdepp From 17213ea83c17b7cb15c942ef0a0028aa2b2aa4ef Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 01:00:03 +0900 Subject: [PATCH 05/39] unittest file path change --- tests/nlohmann_json.cpp | 3 +-- tests/rapid_json.cpp | 2 +- tests/toml11.cpp | 2 +- tests/yaml_cpp.cpp | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/nlohmann_json.cpp b/tests/nlohmann_json.cpp index 04a32f8..ed2ab57 100644 --- a/tests/nlohmann_json.cpp +++ b/tests/nlohmann_json.cpp @@ -6,8 +6,7 @@ using namespace serde; - TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") { - auto json_v = serde::parse_file("../../tests/test.json"); + auto json_v = serde::parse_file("../tests/test.json"); REQUIRE(json_v.dump() == serialize(deserialize(json_v)).dump()); } diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 6b4bf9b..2a69da8 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -13,7 +13,7 @@ std::string str(rapidjson::Document& doc) { using namespace serde; TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { - auto json_v = serde::parse_file("../../tests/test.json"); + auto json_v = serde::parse_file("../tests/test.json"); rapidjson::Document json_c = serialize(deserialize(json_v)); REQUIRE(str(json_v) == str(json_c)); } diff --git a/tests/toml11.cpp b/tests/toml11.cpp index 61a33be..c2eebc8 100644 --- a/tests/toml11.cpp +++ b/tests/toml11.cpp @@ -7,6 +7,6 @@ using namespace serde; using namespace toml::literals; TEST_CASE("4: toml11 struct (pass)", "[multi-file:4]") { - auto toml_vl = serde::parse_file("../../tests/test.toml"); + auto toml_vl = serde::parse_file("../tests/test.toml"); REQUIRE(toml_vl == serialize(deserialize(toml_vl))); } diff --git a/tests/yaml_cpp.cpp b/tests/yaml_cpp.cpp index 137e269..8343331 100644 --- a/tests/yaml_cpp.cpp +++ b/tests/yaml_cpp.cpp @@ -6,7 +6,7 @@ using namespace serde; TEST_CASE("5: yaml-cpp struct (pass)", "[multi-file:5]") { std::ostringstream convert; - auto yaml_v = serde::parse_file("../../tests/test.yaml"); + auto yaml_v = serde::parse_file("../tests/test.yaml"); std::ostringstream origin; origin << yaml_v; convert << serialize(deserialize(yaml_v)); From 9bc1c5362e8c3a00723ca8f7bfdb501fb68d9b0d Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 01:13:09 +0900 Subject: [PATCH 06/39] cov github action bugfix --- .github/workflows/code-cov.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 06d7ddc..492da59 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -37,8 +37,9 @@ jobs: cmake --build . --config ${{matrix.build-type}} - name: Generate Coverage Report run: | + cd build + ctest . 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 - name: Upload coverage to Codecov From 81528af1e487585b5383031849770e440a828b0d Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 01:16:48 +0900 Subject: [PATCH 07/39] code-cov bugfix --- .github/workflows/code-cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 492da59..a0419b9 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -39,7 +39,7 @@ jobs: run: | cd build ctest . - cd build/${{matrix.build-type}} + cd ${{matrix.build-type}} 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 - name: Upload coverage to Codecov From beeb8738b5f646a05f33a0894c32413a76c7be79 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 01:22:23 +0900 Subject: [PATCH 08/39] codeCov github action update --- .github/workflows/code-cov.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index a0419b9..1135a89 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -39,9 +39,8 @@ jobs: run: | cd build ctest . - cd ${{matrix.build-type}} 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: From 5a44b83e723efa37c1eef1ec4df4ca4aa130a6ba Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Wed, 20 Apr 2022 01:25:45 +0900 Subject: [PATCH 09/39] codeCov github action update --- .github/workflows/code-cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 1135a89..790a671 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -44,7 +44,7 @@ jobs: - 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 From 7cac421ac84db2c6ec03e6139d1156c837d57cbf Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 00:36:18 +0900 Subject: [PATCH 10/39] new adaptor [beta] cli11 --- CMakeLists.txt | 15 +++++- cppm.toml | 7 ++- examples/cli11.cpp | 39 ++++++++++++++ include/serdepp/adaptor/cli11.hpp | 53 +++++++++++++++++++ include/serdepp/attribute/cli11.hpp | 76 +++++++++++++++++++++++++++ tests/rapid_json.cpp | 2 +- thirdparty/cli11/2.2.0/cli11.cmake.in | 8 +++ thirdparty/cli11/2.2.0/cppkg.toml | 9 ++++ thirdparty/cli11/git/cppkg.toml | 8 +++ thirdparty/fmt/8.0.1/.cmake.in | 8 +++ thirdparty/magic_enum/0.7.3/.cmake.in | 8 +++ 11 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 examples/cli11.cpp create mode 100644 include/serdepp/adaptor/cli11.hpp create mode 100644 include/serdepp/attribute/cli11.hpp create mode 100644 thirdparty/cli11/2.2.0/cli11.cmake.in create mode 100644 thirdparty/cli11/2.2.0/cppkg.toml create mode 100644 thirdparty/cli11/git/cppkg.toml create mode 100644 thirdparty/fmt/8.0.1/.cmake.in create mode 100644 thirdparty/magic_enum/0.7.3/.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 72aa117..0fd7245 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,9 @@ 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(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(cli11 2.2.0 MODULE CLI11::CLI11 TYPE lib) +find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json TYPE lib) find_cppkg(yaml-cpp 0.7.0 MODULE yaml-cpp TYPE lib) find_cppkg(fmt 8.0.1 MODULE fmt::fmt-header-only TYPE lib) endif() @@ -89,6 +90,11 @@ SOURCES examples/pointer.cpp ) +cppm_target_define(cli11 BINARY +SOURCES + examples/cli11.cpp +) + endif() cppm_unit_test_area() @@ -133,7 +139,7 @@ endif() 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 RapidJSON nlohmann_json toml11 yaml-cpp fmt) + list(APPEND serdepp_global_deps PRIVATE RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) @@ -182,6 +188,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) @@ -212,4 +222,5 @@ cppm_target_install(sugar) cppm_target_install(reflection) cppm_target_install(print) cppm_target_install(pointer) +cppm_target_install(cli11) diff --git a/cppm.toml b/cppm.toml index 3712208..58a1863 100644 --- a/cppm.toml +++ b/cppm.toml @@ -60,6 +60,11 @@ name = "pointer" source = ["examples/pointer.cpp"] + +[[example]] + name = "cli11" + source = ["examples/cli11.cpp"] + #[[example]] # name = "protobuf" # source = ["examples/protobuf.cpp", "examples/hello.pb.cc"] @@ -106,7 +111,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - #CLI11 = "2.2.0" + cli11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" diff --git a/examples/cli11.cpp b/examples/cli11.cpp new file mode 100644 index 0000000..5d2bbc5 --- /dev/null +++ b/examples/cli11.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +struct Nested { + DERIVE_SERDE(Nested, .attributes(cli11::desc{"Nested Cmd"}) + [attrs(cli11::flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) + [attrs(cli11::option("--hello", "hello"))]_SF_(hello) + [attrs(cli11::option("first", "first"))]_SF_(first) + [attrs(cli11::option("second", "second"))]_SF_(second) + ) + bool check; + std::string hello; + std::string first; + std::string second; +}; + +struct Cmd { + DERIVE_SERDE(Cmd, .attributes(cli11::desc{"Cmd Test"}) + [attrs(cli11::flag("--check,-c", "on off"))]_SF_(check) + [attrs(cli11::option("--hello", "hello"))]_SF_(hello) + _SF_(nest) + ) + bool check; + std::string hello; + Nested nest; +}; + + +int main(int argc, char *argv[]) +{ + CLI::App app; + Cmd cmd; + serde::serialize_to(cmd, app); + CLI11_PARSE(app, argc, argv); + + std::cout << cmd << "\n"; + return 0; +} diff --git a/include/serdepp/adaptor/cli11.hpp b/include/serdepp/adaptor/cli11.hpp new file mode 100644 index 0000000..48872d2 --- /dev/null +++ b/include/serdepp/adaptor/cli11.hpp @@ -0,0 +1,53 @@ +#pragma once + +#ifndef __SERDEPP_ADAPTOR_CLI11_HPP__ +#define __SERDEPP_ADAPTOR_CLI11_HPP__ + +#include +#include + +namespace serde { + using cpcli_t = CLI::App; + template<> struct serde_type_checker { + using Format = cpcli_t; + static bool is_integer(Format& format) { return true; } + static bool is_sequence(Format& format){ return true; } + static bool is_map(Format& format) { return true; } + static bool is_float(Format& format) { return true; } + static bool is_string(Format& format) { return true; } + static bool is_bool(Format& format) { return true; } + static bool is_null(Format &format) { return true; } + static bool is_struct(Format& format) { return true; } + }; + + template<> struct serde_adaptor_helper : derive_serde_adaptor_helper { + inline constexpr static bool is_null(cpcli_t& adaptor, std::string_view key) { return true; } + inline constexpr static size_t size(cpcli_t& adaptor) { return 1; } + inline constexpr static bool is_struct(cpcli_t& adaptor) { return true; } + }; + + template struct serde_adaptor { + static void from(cpcli_t& s, std::string_view key, T& data) { + deserialize_to(s.get_subcommand(std::string{key}), data); + } + static void into(cpcli_t& s, std::string_view key, const T& data) { + serialize_to(data, *s.add_subcommand(std::string{key})); + } + }; + + template struct serde_adaptor { + static void from(cpcli_t& s, std::string_view key, T& data) { + //if(!s.get_arg(key).is_require() && !s.get_arg(key).visit()) return; + //data = s.get_arg(key).get(); + } + static void into(cpcli_t& s, std::string_view key, const T& data) { + //s.arg_after_init(std::string{key}); + } + }; +} + +#endif + + + + diff --git a/include/serdepp/attribute/cli11.hpp b/include/serdepp/attribute/cli11.hpp new file mode 100644 index 0000000..aa944af --- /dev/null +++ b/include/serdepp/attribute/cli11.hpp @@ -0,0 +1,76 @@ +#pragma once + +#ifndef __SERDEPP_ATTIRBUTE_CLI11_HPP__ +#define __SERDEPP_ATTIRBUTE_CLI11_HPP__ + +#include + +namespace serde::attribute::cli11 { + struct flag { + using Hook = std::function; + flag(const std::string& key, const std::string& desc, Hook&& hook = [](auto* o){}) + : key_(key), desc_(desc), hook_(std::move(hook)) {}; + const std::string& key_; + const std::string& desc_; + Hook&& hook_; + template + constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + next_attr.from(ctx, data, key, remains...); + } + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(std::is_same_v) { + hook_(ctx.adaptor.add_flag(key_, data, desc_)); + } + next_attr.into(ctx, data, key, remains...); + } + }; + + struct option { + using Hook = std::function; + option(const std::string& key, const std::string& desc, Hook&& hook = [](auto* o){}) + : key_(key), desc_(desc), hook_(std::move(hook)) {}; + const std::string& key_; + const std::string& desc_; + Hook&& hook_; + template + constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + next_attr.from(ctx, data, key, remains...); + } + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(std::is_same_v) { + hook_(ctx.adaptor.add_option(key_, data, desc_)); + } + next_attr.into(ctx, data, key, remains...); + } + }; + + struct desc { + using Hook = std::function; + desc(const std::string& desc) : desc_(desc) {}; + const std::string& desc_; + template + constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + next_attr.from(ctx, data, key, remains...); + } + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(std::is_same_v) { + ctx.adaptor.description(desc_); + } + next_attr.into(ctx, data, key, remains...); + } + }; +} + +#endif diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 2a69da8..6a88388 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -12,7 +12,7 @@ std::string str(rapidjson::Document& doc) { using namespace serde; -TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { +TEST_CASE("7: rapidjson struct (pass)", "[multi-file:5]") { auto json_v = serde::parse_file("../tests/test.json"); rapidjson::Document json_c = serialize(deserialize(json_v)); REQUIRE(str(json_v) == str(json_c)); diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in new file mode 100644 index 0000000..9a91577 --- /dev/null +++ b/thirdparty/cli11/2.2.0/cli11.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(cli11-2.2.0-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DBUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) + diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml new file mode 100644 index 0000000..c477cd1 --- /dev/null +++ b/thirdparty/cli11/2.2.0/cppkg.toml @@ -0,0 +1,9 @@ +[cli11] +version="2.2.0" #(require) +type="lib" #lib(default) | bin | cmake +description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) +module="CLI11::CLI11" #(require) if none_module=true -> no require +url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) +flags="-DBUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" +#branch="" #(optional & require git) +#link=private #default diff --git a/thirdparty/cli11/git/cppkg.toml b/thirdparty/cli11/git/cppkg.toml new file mode 100644 index 0000000..45a2a39 --- /dev/null +++ b/thirdparty/cli11/git/cppkg.toml @@ -0,0 +1,8 @@ +[CLI11] +version="2.2.0" #(require) +type="lib" #lib(default) | bin | cmake +description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) +module="CLI11::CLI11" #(require) if none_module=true -> no require +url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) +#branch="" #(optional & require git) +#link=private #default \ No newline at end of file diff --git a/thirdparty/fmt/8.0.1/.cmake.in b/thirdparty/fmt/8.0.1/.cmake.in new file mode 100644 index 0000000..a29e5af --- /dev/null +++ b/thirdparty/fmt/8.0.1/.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(-8.0.1-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package( 8.0.1 TYPE lib CMAKE_ARGS ${CMAKE_ARGS} ) + diff --git a/thirdparty/magic_enum/0.7.3/.cmake.in b/thirdparty/magic_enum/0.7.3/.cmake.in new file mode 100644 index 0000000..cc80880 --- /dev/null +++ b/thirdparty/magic_enum/0.7.3/.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(-0.7.3-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package( 0.7.3 TYPE lib CMAKE_ARGS ${CMAKE_ARGS} ) + From 782c82684321a19aa2e8ff92fd5718d38295a6c6 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:15:12 +0900 Subject: [PATCH 11/39] cppkg thirdparty bugfix --- include/serdepp/serializer.hpp | 9 +++++++++ thirdparty/cli11/2.2.0/cli11.cmake.in | 2 +- thirdparty/cli11/2.2.0/cppkg.toml | 2 +- thirdparty/fmt/8.0.1/.cmake.in | 8 -------- thirdparty/magic_enum/0.7.3/.cmake.in | 8 -------- thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in | 4 ++-- 6 files changed, 13 insertions(+), 20 deletions(-) delete mode 100644 thirdparty/fmt/8.0.1/.cmake.in delete mode 100644 thirdparty/magic_enum/0.7.3/.cmake.in diff --git a/include/serdepp/serializer.hpp b/include/serdepp/serializer.hpp index 2e984af..db33101 100644 --- a/include/serdepp/serializer.hpp +++ b/include/serdepp/serializer.hpp @@ -251,6 +251,7 @@ namespace serde Adaptor = [nlohmann::json serde_sstream, toml11::value ...] Adaptor(key) -> T or Adaptor -> T T t = deserialize(Adaptor, key) + */ template constexpr inline T deserialize(Adaptor&& adaptor, std::string_view key="") { @@ -283,6 +284,7 @@ namespace serde constexpr inline Adaptor serialize(T&& target, std::string_view key="") { using origin = meta::remove_cvref_t; Adaptor adaptor; + serde_context ctx(adaptor); serde_serializer>::into(ctx, target, key); return adaptor; @@ -448,6 +450,11 @@ namespace serde return std::make_tuple(std::forward(arg)...); } + template + inline constexpr std::tuple attrs(Ty&&... arg) { + return std::make_tuple(std::forward(arg)...); + } + template inline constexpr serde::serde_struct operator|(std::tuple attributes, serde::serde_struct serde_define) { @@ -671,6 +678,8 @@ namespace serde /*compile time: stuct member size*/ template [[maybe_unused]] constexpr static size_t tuple_size_v = tuple_size::value; + + template struct special_adaptor : std::false_type {}; } // namespace serde diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in index 9a91577..0da2468 100644 --- a/thirdparty/cli11/2.2.0/cli11.cmake.in +++ b/thirdparty/cli11/2.2.0/cli11.cmake.in @@ -4,5 +4,5 @@ project(cli11-2.2.0-install) set(CPPM_VERSION ${CPPM_VERSION}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DBUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) +download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml index c477cd1..a0bd08d 100644 --- a/thirdparty/cli11/2.2.0/cppkg.toml +++ b/thirdparty/cli11/2.2.0/cppkg.toml @@ -4,6 +4,6 @@ type="lib" #lib(default) | bin | cmake description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) module="CLI11::CLI11" #(require) if none_module=true -> no require url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) -flags="-DBUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" +flags="-DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" #branch="" #(optional & require git) #link=private #default diff --git a/thirdparty/fmt/8.0.1/.cmake.in b/thirdparty/fmt/8.0.1/.cmake.in deleted file mode 100644 index a29e5af..0000000 --- a/thirdparty/fmt/8.0.1/.cmake.in +++ /dev/null @@ -1,8 +0,0 @@ -# Cppkg Base Dependency Downloader -cmake_minimum_required(VERSION 3.6) -project(-8.0.1-install) - -set(CPPM_VERSION ${CPPM_VERSION}) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package( 8.0.1 TYPE lib CMAKE_ARGS ${CMAKE_ARGS} ) - diff --git a/thirdparty/magic_enum/0.7.3/.cmake.in b/thirdparty/magic_enum/0.7.3/.cmake.in deleted file mode 100644 index cc80880..0000000 --- a/thirdparty/magic_enum/0.7.3/.cmake.in +++ /dev/null @@ -1,8 +0,0 @@ -# Cppkg Base Dependency Downloader -cmake_minimum_required(VERSION 3.6) -project(-0.7.3-install) - -set(CPPM_VERSION ${CPPM_VERSION}) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package( 0.7.3 TYPE lib CMAKE_ARGS ${CMAKE_ARGS} ) - diff --git a/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in b/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in index 35946fd..27eeb4b 100644 --- a/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in +++ b/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in @@ -1,8 +1,8 @@ # Cppkg Base Dependency Downloader cmake_minimum_required(VERSION 3.6) -project(yaml-cpp-0.6.3-install) +project(yaml-cpp-0.7.0-install) set(CPPM_VERSION ${CPPM_VERSION}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(yaml-cpp 0.6.3 URL https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-0.6.3.tar.gz TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DYAML_CPP_BUILD_TESTS=OFF) +download_package(yaml-cpp 0.7.0 URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.7.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DYAML_CPP_BUILD_TESTS=OFF) From 8984ffaa28145cd4a6de72a611a40819e9ea13d5 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:25:26 +0900 Subject: [PATCH 12/39] yaml-cpp version down --- CMakeLists.txt | 2 +- cppm.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fd7245..636388a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ find_cppkg(RapidJSON 1.1.1 MODULE rapidjson TYPE lib) find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib) find_cppkg(cli11 2.2.0 MODULE CLI11::CLI11 TYPE lib) find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json TYPE lib) -find_cppkg(yaml-cpp 0.7.0 MODULE yaml-cpp 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() diff --git a/cppm.toml b/cppm.toml index 58a1863..d79e434 100644 --- a/cppm.toml +++ b/cppm.toml @@ -107,7 +107,7 @@ source = ["tests/.*"] # example, benchmark, debug dependencies [dev-dependencies] fmt = "8.0.1" - yaml-cpp ="0.7.0" + yaml-cpp ="0.6.3" toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" From 18478bccc0f8775693f31825a2eb63f1bac69ebe Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:29:32 +0900 Subject: [PATCH 13/39] github action unused flag remove --- .github/workflows/linux.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index eeaeecf..c286cc8 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -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'] @@ -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'] From a88a044deaded939f76f85e3f82f6b4bfd8348b2 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:36:11 +0900 Subject: [PATCH 14/39] cppkg cli11 bugfix --- CMakeLists.txt | 6 +++--- cppm.toml | 2 +- thirdparty/cli11/2.2.0/cli11.cmake.in | 4 ++-- thirdparty/cli11/2.2.0/cppkg.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636388a..7a001df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,10 @@ 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(toml11 3.7.0 MODULE toml11::toml11 TYPE lib) -find_cppkg(cli11 2.2.0 MODULE CLI11::CLI11 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() @@ -139,7 +139,7 @@ endif() 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 RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) + list(APPEND serdepp_global_deps PRIVATE CLI11 RapidJSON nlohmann_json toml11 yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) diff --git a/cppm.toml b/cppm.toml index d79e434..a5ec1f8 100644 --- a/cppm.toml +++ b/cppm.toml @@ -111,7 +111,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - cli11 = "2.2.0" + CLI11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in index 0da2468..06db87b 100644 --- a/thirdparty/cli11/2.2.0/cli11.cmake.in +++ b/thirdparty/cli11/2.2.0/cli11.cmake.in @@ -1,8 +1,8 @@ # Cppkg Base Dependency Downloader cmake_minimum_required(VERSION 3.6) -project(cli11-2.2.0-install) +project(CLI11-2.2.0-install) set(CPPM_VERSION ${CPPM_VERSION}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) +download_package(CLI11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml index a0bd08d..ce5e709 100644 --- a/thirdparty/cli11/2.2.0/cppkg.toml +++ b/thirdparty/cli11/2.2.0/cppkg.toml @@ -1,4 +1,4 @@ -[cli11] +[CLI11] version="2.2.0" #(require) type="lib" #lib(default) | bin | cmake description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) From ac0fc0c3f567d2cda0790a5965d1565c11c80717 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:41:17 +0900 Subject: [PATCH 15/39] cli11 folder bug --- thirdparty/cli11/2.2.0/cli11.cmake.in | 8 -------- thirdparty/cli11/2.2.0/cppkg.toml | 9 --------- thirdparty/cli11/git/cppkg.toml | 8 -------- 3 files changed, 25 deletions(-) delete mode 100644 thirdparty/cli11/2.2.0/cli11.cmake.in delete mode 100644 thirdparty/cli11/2.2.0/cppkg.toml delete mode 100644 thirdparty/cli11/git/cppkg.toml diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in deleted file mode 100644 index 06db87b..0000000 --- a/thirdparty/cli11/2.2.0/cli11.cmake.in +++ /dev/null @@ -1,8 +0,0 @@ -# Cppkg Base Dependency Downloader -cmake_minimum_required(VERSION 3.6) -project(CLI11-2.2.0-install) - -set(CPPM_VERSION ${CPPM_VERSION}) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(CLI11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) - diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml deleted file mode 100644 index ce5e709..0000000 --- a/thirdparty/cli11/2.2.0/cppkg.toml +++ /dev/null @@ -1,9 +0,0 @@ -[CLI11] -version="2.2.0" #(require) -type="lib" #lib(default) | bin | cmake -description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) -module="CLI11::CLI11" #(require) if none_module=true -> no require -url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) -flags="-DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" -#branch="" #(optional & require git) -#link=private #default diff --git a/thirdparty/cli11/git/cppkg.toml b/thirdparty/cli11/git/cppkg.toml deleted file mode 100644 index 45a2a39..0000000 --- a/thirdparty/cli11/git/cppkg.toml +++ /dev/null @@ -1,8 +0,0 @@ -[CLI11] -version="2.2.0" #(require) -type="lib" #lib(default) | bin | cmake -description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) -module="CLI11::CLI11" #(require) if none_module=true -> no require -url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) -#branch="" #(optional & require git) -#link=private #default \ No newline at end of file From a940d2233984f8d7dbdbfc60f30aa79bad357915 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:46:53 +0900 Subject: [PATCH 16/39] cli11 import bugtest --- CMakeLists.txt | 6 +++--- cppm.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a001df..636388a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,10 @@ 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(cli11 2.2.0 MODULE CLI11::CLI11 TYPE lib) +find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json 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() @@ -139,7 +139,7 @@ endif() 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) + list(APPEND serdepp_global_deps PRIVATE RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) diff --git a/cppm.toml b/cppm.toml index a5ec1f8..d79e434 100644 --- a/cppm.toml +++ b/cppm.toml @@ -111,7 +111,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - CLI11 = "2.2.0" + cli11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" From 3fdd877b07aa790abd862659f229b45a99393578 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:49:06 +0900 Subject: [PATCH 17/39] cppkg cli11 update --- thirdparty/cli11/2.2.0/cli11.cmake.in | 8 ++++++++ thirdparty/cli11/2.2.0/cppkg.toml | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 thirdparty/cli11/2.2.0/cli11.cmake.in create mode 100644 thirdparty/cli11/2.2.0/cppkg.toml diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in new file mode 100644 index 0000000..0da2468 --- /dev/null +++ b/thirdparty/cli11/2.2.0/cli11.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(cli11-2.2.0-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) + diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml new file mode 100644 index 0000000..a0bd08d --- /dev/null +++ b/thirdparty/cli11/2.2.0/cppkg.toml @@ -0,0 +1,9 @@ +[cli11] +version="2.2.0" #(require) +type="lib" #lib(default) | bin | cmake +description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) +module="CLI11::CLI11" #(require) if none_module=true -> no require +url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) +flags="-DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" +#branch="" #(optional & require git) +#link=private #default From 873397c6ba315f6ad009ca584ba197e808563da7 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Thu, 21 Apr 2022 01:55:12 +0900 Subject: [PATCH 18/39] cli11 disable --- CMakeLists.txt | 15 ++------------- cppm.toml | 10 +++++----- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636388a..031e8f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,9 +19,8 @@ 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(RapidJSON 1.1.1 MODULE rapidjson TYPE lib) -find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib) -find_cppkg(cli11 2.2.0 MODULE CLI11::CLI11 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() @@ -90,11 +89,6 @@ SOURCES examples/pointer.cpp ) -cppm_target_define(cli11 BINARY -SOURCES - examples/cli11.cpp -) - endif() cppm_unit_test_area() @@ -139,7 +133,7 @@ endif() 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 RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) + list(APPEND serdepp_global_deps PRIVATE RapidJSON nlohmann_json toml11 yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) @@ -188,10 +182,6 @@ cppm_target_dependencies(pointer ${serdepp_global_deps} serdepp) -cppm_target_dependencies(cli11 - ${serdepp_global_deps} - serdepp) - cppm_target_dependencies(unittest ${serdepp_global_deps} serdepp) @@ -222,5 +212,4 @@ cppm_target_install(sugar) cppm_target_install(reflection) cppm_target_install(print) cppm_target_install(pointer) -cppm_target_install(cli11) diff --git a/cppm.toml b/cppm.toml index d79e434..bc2a064 100644 --- a/cppm.toml +++ b/cppm.toml @@ -46,6 +46,7 @@ [[example]] name = "sugar" + source = ["examples/sugar.cpp"] [[example]] @@ -60,10 +61,9 @@ name = "pointer" source = ["examples/pointer.cpp"] - -[[example]] - name = "cli11" - source = ["examples/cli11.cpp"] +#[[example]] +# name = "cli11" +# source = ["examples/cli11.cpp"] #[[example]] # name = "protobuf" @@ -111,7 +111,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - cli11 = "2.2.0" + #cli11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" From 2a140171037694d6e4d5ba13a08329ba7d466178 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Fri, 22 Apr 2022 22:47:53 +0900 Subject: [PATCH 19/39] new adaptor library cli11 --- CMakeLists.txt | 15 +++++++++++++-- cppm.toml | 9 ++++----- examples/cli11.cpp | 19 +++++++++++++++---- include/serdepp/attribute/cli11.hpp | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 031e8f9..636388a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,9 @@ 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(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(cli11 2.2.0 MODULE CLI11::CLI11 TYPE lib) +find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json 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() @@ -89,6 +90,11 @@ SOURCES examples/pointer.cpp ) +cppm_target_define(cli11 BINARY +SOURCES + examples/cli11.cpp +) + endif() cppm_unit_test_area() @@ -133,7 +139,7 @@ endif() 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 RapidJSON nlohmann_json toml11 yaml-cpp fmt) + list(APPEND serdepp_global_deps PRIVATE RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) @@ -182,6 +188,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) @@ -212,4 +222,5 @@ cppm_target_install(sugar) cppm_target_install(reflection) cppm_target_install(print) cppm_target_install(pointer) +cppm_target_install(cli11) diff --git a/cppm.toml b/cppm.toml index bc2a064..de44abc 100644 --- a/cppm.toml +++ b/cppm.toml @@ -46,7 +46,6 @@ [[example]] name = "sugar" - source = ["examples/sugar.cpp"] [[example]] @@ -61,9 +60,9 @@ name = "pointer" source = ["examples/pointer.cpp"] -#[[example]] -# name = "cli11" -# source = ["examples/cli11.cpp"] +[[example]] + name = "cli11" + source = ["examples/cli11.cpp"] #[[example]] # name = "protobuf" @@ -111,7 +110,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - #cli11 = "2.2.0" + cli11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" diff --git a/examples/cli11.cpp b/examples/cli11.cpp index 5d2bbc5..955059f 100644 --- a/examples/cli11.cpp +++ b/examples/cli11.cpp @@ -1,14 +1,21 @@ #include #include #include +#include struct Nested { - DERIVE_SERDE(Nested, .attributes(cli11::desc{"Nested Cmd"}) + DERIVE_SERDE(Nested, .attributes(cli11::desc{"Nested Cmd"}, cli11::callback{Nested::execute}) [attrs(cli11::flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) [attrs(cli11::option("--hello", "hello"))]_SF_(hello) [attrs(cli11::option("first", "first"))]_SF_(first) [attrs(cli11::option("second", "second"))]_SF_(second) ) + + static void execute(Nested& n) { + fmt::print("{}\n",n); + exit(true); + } + bool check; std::string hello; std::string first; @@ -16,11 +23,17 @@ struct Nested { }; struct Cmd { - DERIVE_SERDE(Cmd, .attributes(cli11::desc{"Cmd Test"}) + DERIVE_SERDE(Cmd, .attributes(cli11::desc{"Cmd Test"}, cli11::callback{Cmd::execute}) [attrs(cli11::flag("--check,-c", "on off"))]_SF_(check) [attrs(cli11::option("--hello", "hello"))]_SF_(hello) _SF_(nest) ) + + static void execute(Cmd& n) { + fmt::print("{}\n",n); + exit(true); + } + bool check; std::string hello; Nested nest; @@ -33,7 +46,5 @@ int main(int argc, char *argv[]) Cmd cmd; serde::serialize_to(cmd, app); CLI11_PARSE(app, argc, argv); - - std::cout << cmd << "\n"; return 0; } diff --git a/include/serdepp/attribute/cli11.hpp b/include/serdepp/attribute/cli11.hpp index aa944af..9d0b165 100644 --- a/include/serdepp/attribute/cli11.hpp +++ b/include/serdepp/attribute/cli11.hpp @@ -71,6 +71,26 @@ namespace serde::attribute::cli11 { next_attr.into(ctx, data, key, remains...); } }; + + template + struct callback { + callback(Hook&& hook) : hook_(hook) {}; + Hook&& hook_; + template + constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + next_attr.from(ctx, data, key, remains...); + } + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(std::is_same_v) { + ctx.adaptor.final_callback([&data, hook = std::move(hook_)](){ hook(data); }); + } + next_attr.into(ctx, data, key, remains...); + } + }; } #endif From 7feff965ed32340503d36f4f38a004aee5119ed3 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 23 Apr 2022 18:52:15 +0900 Subject: [PATCH 20/39] cli11 find bugfix --- CMakeLists.txt | 6 +++--- cppm.toml | 2 +- thirdparty/cli11/2.2.0/cli11.cmake.in | 4 ++-- thirdparty/cli11/2.2.0/cppkg.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636388a..7a001df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,10 @@ 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(toml11 3.7.0 MODULE toml11::toml11 TYPE lib) -find_cppkg(cli11 2.2.0 MODULE CLI11::CLI11 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() @@ -139,7 +139,7 @@ endif() 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 RapidJSON toml11 cli11 nlohmann_json yaml-cpp fmt) + list(APPEND serdepp_global_deps PRIVATE CLI11 RapidJSON nlohmann_json toml11 yaml-cpp fmt) endif() cppm_target_dependencies(serdepp ${serdepp_global_deps}) diff --git a/cppm.toml b/cppm.toml index de44abc..1ac55a2 100644 --- a/cppm.toml +++ b/cppm.toml @@ -110,7 +110,7 @@ source = ["tests/.*"] toml11 ="3.7.0" nlohmann_json = "3.10.5" RapidJSON = "1.1.1" - cli11 = "2.2.0" + CLI11 = "2.2.0" #pybind11 = "2.9.0" #Protobuf = "3.20.0" #hiredis = "git" diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in index 0da2468..06db87b 100644 --- a/thirdparty/cli11/2.2.0/cli11.cmake.in +++ b/thirdparty/cli11/2.2.0/cli11.cmake.in @@ -1,8 +1,8 @@ # Cppkg Base Dependency Downloader cmake_minimum_required(VERSION 3.6) -project(cli11-2.2.0-install) +project(CLI11-2.2.0-install) set(CPPM_VERSION ${CPPM_VERSION}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(cli11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) +download_package(CLI11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml index a0bd08d..ce5e709 100644 --- a/thirdparty/cli11/2.2.0/cppkg.toml +++ b/thirdparty/cli11/2.2.0/cppkg.toml @@ -1,4 +1,4 @@ -[cli11] +[CLI11] version="2.2.0" #(require) type="lib" #lib(default) | bin | cmake description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) From 22a857490de5ec3e2e3ef2ee10588238f95b3472 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 23 Apr 2022 18:55:02 +0900 Subject: [PATCH 21/39] git bug fix --- thirdparty/cli11/2.2.0/cli11.cmake.in | 8 -------- thirdparty/cli11/2.2.0/cppkg.toml | 9 --------- 2 files changed, 17 deletions(-) delete mode 100644 thirdparty/cli11/2.2.0/cli11.cmake.in delete mode 100644 thirdparty/cli11/2.2.0/cppkg.toml diff --git a/thirdparty/cli11/2.2.0/cli11.cmake.in b/thirdparty/cli11/2.2.0/cli11.cmake.in deleted file mode 100644 index 06db87b..0000000 --- a/thirdparty/cli11/2.2.0/cli11.cmake.in +++ /dev/null @@ -1,8 +0,0 @@ -# Cppkg Base Dependency Downloader -cmake_minimum_required(VERSION 3.6) -project(CLI11-2.2.0-install) - -set(CPPM_VERSION ${CPPM_VERSION}) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(CLI11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) - diff --git a/thirdparty/cli11/2.2.0/cppkg.toml b/thirdparty/cli11/2.2.0/cppkg.toml deleted file mode 100644 index ce5e709..0000000 --- a/thirdparty/cli11/2.2.0/cppkg.toml +++ /dev/null @@ -1,9 +0,0 @@ -[CLI11] -version="2.2.0" #(require) -type="lib" #lib(default) | bin | cmake -description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) -module="CLI11::CLI11" #(require) if none_module=true -> no require -url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) -flags="-DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" -#branch="" #(optional & require git) -#link=private #default From 419c423e5404bb88adb6455daf1f443d42b1a306 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 23 Apr 2022 18:55:32 +0900 Subject: [PATCH 22/39] CLI11 git bugfix --- thirdparty/CLI11/2.2.0/CLI11.cmake.in | 8 ++++++++ thirdparty/CLI11/2.2.0/cppkg.toml | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 thirdparty/CLI11/2.2.0/CLI11.cmake.in create mode 100644 thirdparty/CLI11/2.2.0/cppkg.toml diff --git a/thirdparty/CLI11/2.2.0/CLI11.cmake.in b/thirdparty/CLI11/2.2.0/CLI11.cmake.in new file mode 100644 index 0000000..06db87b --- /dev/null +++ b/thirdparty/CLI11/2.2.0/CLI11.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(CLI11-2.2.0-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package(CLI11 2.2.0 URL https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF) + diff --git a/thirdparty/CLI11/2.2.0/cppkg.toml b/thirdparty/CLI11/2.2.0/cppkg.toml new file mode 100644 index 0000000..ce5e709 --- /dev/null +++ b/thirdparty/CLI11/2.2.0/cppkg.toml @@ -0,0 +1,9 @@ +[CLI11] +version="2.2.0" #(require) +type="lib" #lib(default) | bin | cmake +description="CLI11 is a command line parser for C++11 and beyond that provides a rich feature set with a simple and intuitive interface." #(require) +module="CLI11::CLI11" #(require) if none_module=true -> no require +url="https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.2.0.zip" #(require) +flags="-DCLI11_BUILD_TESTS=OFF -DCLI11_BUILD_EXAMPLES=OFF" +#branch="" #(optional & require git) +#link=private #default From 0c5f53948e421870267b9d7a05ce033bb2694898 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 23 Apr 2022 19:16:14 +0900 Subject: [PATCH 23/39] new alias type cli11_t --- include/serdepp/adaptor/cli11.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/serdepp/adaptor/cli11.hpp b/include/serdepp/adaptor/cli11.hpp index 48872d2..65a5633 100644 --- a/include/serdepp/adaptor/cli11.hpp +++ b/include/serdepp/adaptor/cli11.hpp @@ -7,9 +7,9 @@ #include namespace serde { - using cpcli_t = CLI::App; - template<> struct serde_type_checker { - using Format = cpcli_t; + using cli11_t = CLI::App; + template<> struct serde_type_checker { + using Format = cli11_t; static bool is_integer(Format& format) { return true; } static bool is_sequence(Format& format){ return true; } static bool is_map(Format& format) { return true; } @@ -20,27 +20,27 @@ namespace serde { static bool is_struct(Format& format) { return true; } }; - template<> struct serde_adaptor_helper : derive_serde_adaptor_helper { - inline constexpr static bool is_null(cpcli_t& adaptor, std::string_view key) { return true; } - inline constexpr static size_t size(cpcli_t& adaptor) { return 1; } - inline constexpr static bool is_struct(cpcli_t& adaptor) { return true; } + template<> struct serde_adaptor_helper : derive_serde_adaptor_helper { + inline constexpr static bool is_null(cli11_t& adaptor, std::string_view key) { return true; } + inline constexpr static size_t size(cli11_t& adaptor) { return 1; } + inline constexpr static bool is_struct(cli11_t& adaptor) { return true; } }; - template struct serde_adaptor { - static void from(cpcli_t& s, std::string_view key, T& data) { + template struct serde_adaptor { + static void from(cli11_t& s, std::string_view key, T& data) { deserialize_to(s.get_subcommand(std::string{key}), data); } - static void into(cpcli_t& s, std::string_view key, const T& data) { + static void into(cli11_t& s, std::string_view key, const T& data) { serialize_to(data, *s.add_subcommand(std::string{key})); } }; - template struct serde_adaptor { - static void from(cpcli_t& s, std::string_view key, T& data) { + template struct serde_adaptor { + static void from(cli11_t& s, std::string_view key, T& data) { //if(!s.get_arg(key).is_require() && !s.get_arg(key).visit()) return; //data = s.get_arg(key).get(); } - static void into(cpcli_t& s, std::string_view key, const T& data) { + static void into(cli11_t& s, std::string_view key, const T& data) { //s.arg_after_init(std::string{key}); } }; From 3a0e342ac31275bd85ec9794f7df1874ddb2280c Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 01:26:13 +0900 Subject: [PATCH 24/39] new attributes utility macro function SERDEPP_DEFAULT_ATTRIBUTE_INTO() SERDEPP_DEFAULT_ATTRIBUTE_FROM() --- include/serdepp/attribute/utility.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 include/serdepp/attribute/utility.hpp diff --git a/include/serdepp/attribute/utility.hpp b/include/serdepp/attribute/utility.hpp new file mode 100644 index 0000000..419813f --- /dev/null +++ b/include/serdepp/attribute/utility.hpp @@ -0,0 +1,19 @@ +#pragma once + +#ifndef __SERDEPP_ATTRIBUTE_UTILITY_HPP__ +#define __SERDEPP_ATTRIBUTE_UTILITY_HPP__ + +#define SERDEPP_DEFAULT_ATTRIBUTE_FROM() \ + template \ + constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { \ + next_attr.from(ctx, data, key, remains...); \ + } + + +#define SERDEPP_DEFAULT_ATTRIBUTE_INTO() \ + template \ + inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { \ + next_attr.into(ctx, data, key, remains...); \ + } + +#endif From 27609795f984d069540f32b27a8e572a0152dc53 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 01:33:14 +0900 Subject: [PATCH 25/39] cli11 adaptor update and new syntax sugar function attrs() --- examples/cli11.cpp | 77 ++++++++++++++++++----- include/serdepp/adaptor/cli11.hpp | 2 +- include/serdepp/attribute/cli11.hpp | 94 ++++++++++++++++++++++------- include/serdepp/attributes.hpp | 2 - include/serdepp/serializer.hpp | 19 +++++- 5 files changed, 155 insertions(+), 39 deletions(-) diff --git a/examples/cli11.cpp b/examples/cli11.cpp index 955059f..1f775aa 100644 --- a/examples/cli11.cpp +++ b/examples/cli11.cpp @@ -3,48 +3,97 @@ #include #include +struct callback_interface { + static void callback(std::vector& args){ throw serde::unimplemented_error("need callback function"); }; +}; + +using namespace serde::attribute::cli11; +template +struct SingleCommand { + SingleCommand()=default; + DERIVE_SERDE(SingleCommand, .attributes(cli11::callback{SingleCommand::callback}) + [attrs(cli11::option("args", "args"))]_SF_(args)) + std::vector args; + + static void callback(SingleCommand& cmd) { T::callback(cmd.args); } +}; + +struct Test : callback_interface { + static void callback(std::vector& args) { + fmt::print("Test {}\n",args); + + throw CLI::Success{}; + } +}; + +struct Test2 : callback_interface { + static void callback(std::vector& args) { + fmt::print("Test2 {}\n",args); + + throw CLI::Success{}; + } +}; + + struct Nested { - DERIVE_SERDE(Nested, .attributes(cli11::desc{"Nested Cmd"}, cli11::callback{Nested::execute}) - [attrs(cli11::flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) - [attrs(cli11::option("--hello", "hello"))]_SF_(hello) - [attrs(cli11::option("first", "first"))]_SF_(first) - [attrs(cli11::option("second", "second"))]_SF_(second) - ) + DERIVE_SERDE(Nested, .attributes(desc{"Nested Cmd"}, callback{Nested::execute}) + [attrs(flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) + [attrs(option("--hello", "hello"))]_SF_(hello) + [attrs(option("first", "first", [](auto* opt){ opt->required(); }))]_SF_(first) + [attrs(option("second", "second"))]_SF_(second) + _SF_(test)) static void execute(Nested& n) { fmt::print("{}\n",n); - exit(true); + + throw CLI::Success{}; } bool check; std::string hello; std::string first; std::string second; + SingleCommand test; }; struct Cmd { - DERIVE_SERDE(Cmd, .attributes(cli11::desc{"Cmd Test"}, cli11::callback{Cmd::execute}) - [attrs(cli11::flag("--check,-c", "on off"))]_SF_(check) - [attrs(cli11::option("--hello", "hello"))]_SF_(hello) + DERIVE_SERDE(Cmd, + .attrs(command{"Cmd Test"}, + option_group{"Type", "Project Type", [](auto* g){ g->require_option(1); }}, + callback{Cmd::execute}) + [attrs(flag("-c{check},-f{fheck}", "on off"))]_SF_(check) + [attrs(option("--hello", "hello"))]_SF_(hello) + [attrs(option("-D", "CMake option"))]_SF_(cmake) + [attrs(group_flag("Type","-l,--lib", "lib"))]_SF_(lib) + [attrs(group_flag("Type","-b,--bin", "bin"))]_SF_(bin) _SF_(nest) + _SF_(test) + _SF_(t2) ) + static void execute(Cmd& n) { fmt::print("{}\n",n); - exit(true); + throw CLI::Success{}; } - bool check; + std::string check; + bool lib; + bool bin; std::string hello; + std::string cmake; + SingleCommand test; + SingleCommand t2; Nested nest; }; -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { CLI::App app; + Cmd cmd; serde::serialize_to(cmd, app); + CLI11_PARSE(app, argc, argv); return 0; } diff --git a/include/serdepp/adaptor/cli11.hpp b/include/serdepp/adaptor/cli11.hpp index 65a5633..a40dc0f 100644 --- a/include/serdepp/adaptor/cli11.hpp +++ b/include/serdepp/adaptor/cli11.hpp @@ -31,7 +31,7 @@ namespace serde { deserialize_to(s.get_subcommand(std::string{key}), data); } static void into(cli11_t& s, std::string_view key, const T& data) { - serialize_to(data, *s.add_subcommand(std::string{key})); + serialize_to(data, *s.add_subcommand(std::string{key})->require_subcommand(0, 1)); } }; diff --git a/include/serdepp/attribute/cli11.hpp b/include/serdepp/attribute/cli11.hpp index 9d0b165..ba2634e 100644 --- a/include/serdepp/attribute/cli11.hpp +++ b/include/serdepp/attribute/cli11.hpp @@ -4,26 +4,40 @@ #define __SERDEPP_ATTIRBUTE_CLI11_HPP__ #include +#include namespace serde::attribute::cli11 { struct flag { using Hook = std::function; - flag(const std::string& key, const std::string& desc, Hook&& hook = [](auto* o){}) + flag(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : key_(key), desc_(desc), hook_(std::move(hook)) {}; - const std::string& key_; - const std::string& desc_; + std::string_view key_, desc_; Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + template - constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - next_attr.from(ctx, data, key, remains...); + if constexpr(std::is_same_v) { + hook_(ctx.adaptor.add_flag(std::string{key_}, data, std::string{desc_})); + } + next_attr.into(ctx, data, key, remains...); } + }; + + struct group_flag { + using Hook = std::function; + group_flag(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; + std::string_view group_, key_, desc_; + Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { if constexpr(std::is_same_v) { - hook_(ctx.adaptor.add_flag(key_, data, desc_)); + hook_(ctx.adaptor.get_option_group(std::string{group_})->add_flag(std::string{key_}, data, std::string{desc_})); } next_attr.into(ctx, data, key, remains...); } @@ -31,42 +45,68 @@ namespace serde::attribute::cli11 { struct option { using Hook = std::function; - option(const std::string& key, const std::string& desc, Hook&& hook = [](auto* o){}) + option(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : key_(key), desc_(desc), hook_(std::move(hook)) {}; - const std::string& key_; - const std::string& desc_; + std::string_view key_, desc_; Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + template - constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - next_attr.from(ctx, data, key, remains...); + if constexpr(std::is_same_v) { + hook_(ctx.adaptor.add_option(std::string{key_}, data, std::string{desc_})); + } + next_attr.into(ctx, data, key, remains...); } + }; + + struct group_option { + using Hook = std::function; + group_option(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; + std::string_view group_, key_, desc_; + Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { if constexpr(std::is_same_v) { - hook_(ctx.adaptor.add_option(key_, data, desc_)); + hook_(ctx.adaptor.get_option_group(std::string{group_})->add_option(std::string{key_}, data, std::string{desc_})); } next_attr.into(ctx, data, key, remains...); } }; struct desc { - using Hook = std::function; - desc(const std::string& desc) : desc_(desc) {}; - const std::string& desc_; + desc(std::string_view desc) : desc_(desc) {}; + std::string_view desc_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + template - constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - next_attr.from(ctx, data, key, remains...); + if constexpr(std::is_same_v) { + ctx.adaptor.description(std::string{desc_}); + } + next_attr.into(ctx, data, key, remains...); } + }; + + struct command { + using Hook = std::function; + command(std::string_view desc, Hook&& hook=[](CLI::App& a){}) : desc_(desc), hook_(std::move(hook)) {}; + std::string_view desc_; + Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { if constexpr(std::is_same_v) { - ctx.adaptor.description(desc_); + ctx.adaptor.description(std::string{desc_}); + hook_(ctx.adaptor); } next_attr.into(ctx, data, key, remains...); } @@ -76,17 +116,29 @@ namespace serde::attribute::cli11 { struct callback { callback(Hook&& hook) : hook_(hook) {}; Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template - constexpr inline void from(serde_ctx& ctx, T& data, std::string_view key, + inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - next_attr.from(ctx, data, key, remains...); + if constexpr(std::is_same_v) { + ctx.adaptor.final_callback([&data, hook = std::move(hook_)](){ hook(data); }); + } + next_attr.into(ctx, data, key, remains...); } + }; + + struct option_group { + using Hook = std::function; + option_group(std::string_view name, std::string_view desc, Hook&& hook=[](CLI::App* o){}) : name_(name), desc_(desc), hook_(std::move(hook)) {}; + std::string_view name_, desc_; + Hook&& hook_; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { if constexpr(std::is_same_v) { - ctx.adaptor.final_callback([&data, hook = std::move(hook_)](){ hook(data); }); + hook_(ctx.adaptor.add_option_group(std::string{name_}, std::string{desc_})); } next_attr.into(ctx, data, key, remains...); } diff --git a/include/serdepp/attributes.hpp b/include/serdepp/attributes.hpp index 407c982..3c0d732 100644 --- a/include/serdepp/attributes.hpp +++ b/include/serdepp/attributes.hpp @@ -15,6 +15,4 @@ //namespace serde::attribute {} - - #endif diff --git a/include/serdepp/serializer.hpp b/include/serdepp/serializer.hpp index db33101..68f1474 100644 --- a/include/serdepp/serializer.hpp +++ b/include/serdepp/serializer.hpp @@ -402,7 +402,6 @@ namespace serde return serde_struct(context_, value_); } - template inline constexpr serde_struct& attributes(Attribute&& attribute, Attributes&&... attributes) { if(context_.skip_all_) return *this; @@ -420,6 +419,24 @@ namespace serde return *this; } + // attributes short name version for [attrs(...)] + template + inline constexpr serde_struct& attrs(Attribute&& attribute, Attributes&&... attributes) { + if(context_.skip_all_) return *this; + if constexpr(!Context::is_serialize) { + attribute.template from(context_, value_, "", + std::forward> + (const_cast&>(attributes))..., + attribute::pass); + } else { + attribute.template into(context_, value_, "", + std::forward> + (const_cast&>(attributes))..., + attribute::pass); + } + return *this; + } + template struct ApplyAttribute{ using def = serde_struct; From 02b02f08802d0e152642bea393099a6f73902eeb Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 11:53:03 +0900 Subject: [PATCH 26/39] cli11 example update and readme update --- CMakeLists.txt | 2 +- README.md | 88 ++++++++-------------------------------------- cppm.toml | 2 +- examples/cli11.cpp | 23 ++++++------ 4 files changed, 26 insertions(+), 89 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a001df..ebcc3d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ 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( diff --git a/README.md b/README.md index 96b3728..1d3438a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ c++17 low cost serialize deserialize adaptor library like rust serde.rs - [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] 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 @@ -43,6 +44,7 @@ c++17 low cost serialize deserialize adaptor library like rust serde.rs ## Get Started ```cpp #include + #include enum class t_enum { A, B }; @@ -59,8 +61,10 @@ struct example { int number_; std::vector vec_; std::optional> opt_vec_; + t_enum tenum_; -}; +}; + int main() { example ex; @@ -100,11 +104,12 @@ fmt:{"vec: {"a", "b", "c"}", "t_enum: B"} - [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 +# with other adaptors vcpkg install ${adaptor} # with nlohmann-json adaptor @@ -121,6 +126,9 @@ vcpkg install fmt # with rapidjson adaptor vcpkg install rapidjson + +# with cli11 adaptor +vcpkg install cli11 ``` ## Install ```console @@ -202,6 +210,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; @@ -252,7 +262,8 @@ struct A { }; int main(int argc, char* argv[]) { - constexpr auto info = serde::type_info; + constexpr auto info = serde::type_info +; static_assert(serde::type_info.size == 5); static_assert(serde::tuple_size_v == 5); static_assert(std::is_same_v, std::tuple, int>>); @@ -281,73 +292,6 @@ int main(int argc, char* argv[]) { return 0; } ``` - -## [Simple Example](./examples/simple_example.cpp) -```cpp -#include -#include -#include -#include -#include - -using namespace serde::ostream; - -enum class tenum { - INPUT, - OUTPUT, -}; - -class test { -public: - template - 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 str; - int i; - std::optional> vec; - tenum io; - std::map 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(v); - - auto v_to_json = serde::serialize(t); - auto v_to_toml = serde::serialize(t); - auto v_to_yaml = serde::serialize(t); - - test t_from_toml = serde::deserialize(v_to_toml); - test t_from_yaml = serde::deserialize(v_to_yaml); - - fmt::print("{}\n", t); - std::cout << t << '\n'; - - return 0; -} -``` - - ### [Nested Class Example](./examples/example.cpp) ```cpp #include @@ -742,7 +686,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 diff --git a/cppm.toml b/cppm.toml index 1ac55a2..b98be49 100644 --- a/cppm.toml +++ b/cppm.toml @@ -1,6 +1,6 @@ [package] name = "serdepp" - version = "0.1.4" + version = "0.1.5" description = "c++ universal serialize deserialize library like rust serde" standard="17" #tool-version = "dev" diff --git a/examples/cli11.cpp b/examples/cli11.cpp index 1f775aa..921a24a 100644 --- a/examples/cli11.cpp +++ b/examples/cli11.cpp @@ -4,21 +4,23 @@ #include struct callback_interface { - static void callback(std::vector& args){ throw serde::unimplemented_error("need callback function"); }; + static constexpr std::string_view desc = ""; + static void callback(std::vector& args){ throw serde::unimplemented_error("need callback function"); } }; using namespace serde::attribute::cli11; template struct SingleCommand { SingleCommand()=default; - DERIVE_SERDE(SingleCommand, .attributes(cli11::callback{SingleCommand::callback}) - [attrs(cli11::option("args", "args"))]_SF_(args)) + DERIVE_SERDE(SingleCommand, + .attrs(desc{std::string{T::desc}}, cli11::callback{SingleCommand::callback}) + [attrs(cli11::option("args", "args"))]_SF_(args)) std::vector args; - static void callback(SingleCommand& cmd) { T::callback(cmd.args); } }; struct Test : callback_interface { + static constexpr std::string_view desc ="Test1 Descripition"; static void callback(std::vector& args) { fmt::print("Test {}\n",args); @@ -27,6 +29,7 @@ struct Test : callback_interface { }; struct Test2 : callback_interface { + static constexpr std::string_view desc ="Test2 Descripition"; static void callback(std::vector& args) { fmt::print("Test2 {}\n",args); @@ -34,9 +37,9 @@ struct Test2 : callback_interface { } }; - struct Nested { - DERIVE_SERDE(Nested, .attributes(desc{"Nested Cmd"}, callback{Nested::execute}) + DERIVE_SERDE(Nested, + .attrs(desc{"Nested Cmd"}, callback{Nested::execute}) [attrs(flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) [attrs(option("--hello", "hello"))]_SF_(hello) [attrs(option("first", "first", [](auto* opt){ opt->required(); }))]_SF_(first) @@ -89,11 +92,5 @@ struct Cmd { int main(int argc, char *argv[]) { - CLI::App app; - - Cmd cmd; - serde::serialize_to(cmd, app); - - CLI11_PARSE(app, argc, argv); - return 0; + return serde::cli11_parse(argc, argv); } From 57c7a4d95d21de09be05354f918f9b24bf48d07a Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 13:04:31 +0900 Subject: [PATCH 27/39] add cli_parser function --- include/serdepp/adaptor/cli11.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/serdepp/adaptor/cli11.hpp b/include/serdepp/adaptor/cli11.hpp index a40dc0f..fc45f38 100644 --- a/include/serdepp/adaptor/cli11.hpp +++ b/include/serdepp/adaptor/cli11.hpp @@ -44,6 +44,17 @@ namespace serde { //s.arg_after_init(std::string{key}); } }; + + template + int cli11_parse(int argc, char *argv[]) { + CLI::App app; + Type cmd; + serde::serialize_to(cmd, app); + + CLI11_PARSE(app, argc, argv); + return 0; + } + } #endif From 9aff7eaf2aff670e76872b6934672d7bbdb6566a Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 19:37:53 +0900 Subject: [PATCH 28/39] new attributes skip_if_not_adaptor or skip_if_adatpor --- include/serdepp/attribute/skip.hpp | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/include/serdepp/attribute/skip.hpp b/include/serdepp/attribute/skip.hpp index bdcb9d5..5494976 100644 --- a/include/serdepp/attribute/skip.hpp +++ b/include/serdepp/attribute/skip.hpp @@ -21,7 +21,7 @@ namespace serde::attribute { template constexpr inline void from(serde_ctx &ctx, T &data, std::string_view key, Next &&next_attr, Attributes &&...remains) const{ - next_attr.from(ctx, data, key, remains...); + next_attr.from(ctx, data, key, remains...); } template @@ -41,6 +41,43 @@ namespace serde::attribute { } }; + template + struct skip_if_not_adaptor { + template + constexpr inline void from(serde_ctx &ctx, T &data, std::string_view key, + Next &&next_attr, Attributes &&...remains) const{ + if constexpr(std::is_same_v) { + next_attr.from(ctx, data, key, remains...); + } + } + + template + constexpr inline void into(serde_ctx &ctx, T &data, std::string_view key, + Next &&next_attr, Attributes &&...remains) const{ + if constexpr(std::is_same_v) { + next_attr.into(ctx, data, key, remains...); + } + } + }; + + template + struct skip_if_adaptor { + template + constexpr inline void from(serde_ctx &ctx, T &data, std::string_view key, + Next &&next_attr, Attributes &&...remains) const{ + if constexpr(!std::is_same_v) { + next_attr.from(ctx, data, key, remains...); + } + } + + template + constexpr inline void into(serde_ctx &ctx, T &data, std::string_view key, + Next &&next_attr, Attributes &&...remains) const{ + if constexpr(!std::is_same_v) { + next_attr.into(ctx, data, key, remains...); + } + } + }; struct skip_if_null_attr { template From e8d1350aacdfce3bd025855a5179559721455107 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 19:57:44 +0900 Subject: [PATCH 29/39] unittest update --- .github/workflows/code-cov.yml | 2 +- tests/catch_main.cpp | 1 - tests/rapid_json.cpp | 17 ++++++++++++++++- tests/reflection.cpp | 2 +- tests/toml11.cpp | 18 +++++++++++++++++- tests/yaml_cpp.cpp | 2 +- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 790a671..66a2f00 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -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'] diff --git a/tests/catch_main.cpp b/tests/catch_main.cpp index b955482..22c1330 100644 --- a/tests/catch_main.cpp +++ b/tests/catch_main.cpp @@ -3,5 +3,4 @@ #include TEST_CASE("1: test (pass)", "[multi-file:1]") { - REQUIRE(1==1); } diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 6a88388..38da256 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -12,7 +12,22 @@ std::string str(rapidjson::Document& doc) { using namespace serde; -TEST_CASE("7: rapidjson struct (pass)", "[multi-file:5]") { + +TEST_CASE("3: rapidjson struct (pass)", "[multi-file:3]") { + rapidjson::Document json_v; + json_v.Parse(R"({ +"str" : "hello", +"i": 10, +"vec": [ "one", "two", "three"], +"opt": "hello", +"sm": { "one" : "tone", "two" : "ttwo"}, +"sub" : { "str": "hello" } +})"); + rapidjson::Document json_c = serialize(deserialize(json_v)); + REQUIRE(str(json_v) == str(json_c)); +} + +TEST_CASE("3: rapidjson struct from file(pass)", "[multi-file:3]") { auto json_v = serde::parse_file("../tests/test.json"); rapidjson::Document json_c = serialize(deserialize(json_v)); REQUIRE(str(json_v) == str(json_c)); diff --git a/tests/reflection.cpp b/tests/reflection.cpp index f8caee8..0dd9999 100644 --- a/tests/reflection.cpp +++ b/tests/reflection.cpp @@ -4,7 +4,7 @@ using namespace serde; -TEST_CASE("3: reflection struct (pass)", "[multi-file:3]") { +TEST_CASE("4: reflection struct (pass)", "[multi-file:4]") { REQUIRE(std::is_same_v, std::tuple(deserialize(toml_vl))); +} + +TEST_CASE("5: toml11 struct from_file (pass)", "[multi-file:5]") { auto toml_vl = serde::parse_file("../tests/test.toml"); REQUIRE(toml_vl == serialize(deserialize(toml_vl))); } diff --git a/tests/yaml_cpp.cpp b/tests/yaml_cpp.cpp index 8343331..96f0fa5 100644 --- a/tests/yaml_cpp.cpp +++ b/tests/yaml_cpp.cpp @@ -4,7 +4,7 @@ using namespace serde; -TEST_CASE("5: yaml-cpp struct (pass)", "[multi-file:5]") { +TEST_CASE("6: yaml-cpp struct (pass)", "[multi-file:6]") { std::ostringstream convert; auto yaml_v = serde::parse_file("../tests/test.yaml"); std::ostringstream origin; From 5ee267a48be5f08b329a07d21dd31f227aedce4f Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 20:33:20 +0900 Subject: [PATCH 30/39] github action code-cov update --- .github/workflows/code-cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 66a2f00..c47a9ac 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -38,7 +38,7 @@ jobs: - name: Generate Coverage Report run: | cd build - ctest . + ./${{matrix.build-type}}/unittest llvm-profdata-${{matrix.clang-version}} merge -sparse default.profraw -o default.profdata llvm-cov-${{matrix.clang-version}} export ${{matrix.build-type}}/unittest --instr-profile default.profdata -format=lcov >> lcov.info - name: Upload coverage to Codecov From e287ff4f07f0ca1444af141c4e138a968e9ebddf Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 21:13:47 +0900 Subject: [PATCH 31/39] unittest update --- CMakeLists.txt | 1 + tests/attribute.cpp | 6 ++++++ tests/nlohmann_json.cpp | 6 ++++++ tests/rapid_json.cpp | 14 -------------- tests/test_struct.hpp | 23 +++++++++++++++++++---- tests/toml11.cpp | 18 ++---------------- 6 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 tests/attribute.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ebcc3d7..0fae091 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ SOURCES tests/test.yaml tests/test.json tests/yaml_cpp.cpp + tests/attribute.cpp tests/toml11.cpp tests/reflection.cpp tests/nlohmann_json.cpp diff --git a/tests/attribute.cpp b/tests/attribute.cpp new file mode 100644 index 0000000..26a5f53 --- /dev/null +++ b/tests/attribute.cpp @@ -0,0 +1,6 @@ + +#include +#include + + +TEST_CASE("7: attributes test (pass)", "[multi-file:7]") {} diff --git a/tests/nlohmann_json.cpp b/tests/nlohmann_json.cpp index ed2ab57..c40b6a4 100644 --- a/tests/nlohmann_json.cpp +++ b/tests/nlohmann_json.cpp @@ -10,3 +10,9 @@ TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") { auto json_v = serde::parse_file("../tests/test.json"); REQUIRE(json_v.dump() == serialize(deserialize(json_v)).dump()); } + + +TEST_CASE("2: nlohmann json variant(pass)", "[multi-file:2]") { + auto json_v = variant_test_data(); + REQUIRE(json_v.dump() == serialize(deserialize>(json_v)).dump()); +} diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 38da256..abb4532 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -14,20 +14,6 @@ using namespace serde; TEST_CASE("3: rapidjson struct (pass)", "[multi-file:3]") { - rapidjson::Document json_v; - json_v.Parse(R"({ -"str" : "hello", -"i": 10, -"vec": [ "one", "two", "three"], -"opt": "hello", -"sm": { "one" : "tone", "two" : "ttwo"}, -"sub" : { "str": "hello" } -})"); - rapidjson::Document json_c = serialize(deserialize(json_v)); - REQUIRE(str(json_v) == str(json_c)); -} - -TEST_CASE("3: rapidjson struct from file(pass)", "[multi-file:3]") { auto json_v = serde::parse_file("../tests/test.json"); rapidjson::Document json_c = serialize(deserialize(json_v)); REQUIRE(str(json_v) == str(json_c)); diff --git a/tests/test_struct.hpp b/tests/test_struct.hpp index 28b97bf..03003c7 100644 --- a/tests/test_struct.hpp +++ b/tests/test_struct.hpp @@ -1,4 +1,5 @@ #include +#include #pragma once @@ -23,7 +24,7 @@ struct Circle { struct test { - DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec)_SF_(opt)_SF_(none_opt)_SF_(sm)_SF_(sub)) + DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec)_SF_(opt)_SF_(none_opt)_SF_(sm)_SF_(sub).no_remain()) std::string str; int i; std::vector vec; @@ -34,11 +35,25 @@ struct test { }; struct variant_test { - DERIVE_SERDE(variant_test, _SF_(opt_var)_SF_(var)) - std::variant opt_var; - std::variant var; + DERIVE_SERDE(variant_test, _SF_(type)_SF_(object)) + std::string type; + std::variant object; }; +inline nlohmann::json variant_flatten_test_data() { + return R"([ + {"type": "circle", "radius": 5}, + {"type": "circle", "radi": 5}, + {"type": "rectangle", "width": 6, "height": 5} + ])"_json; +} + +inline nlohmann::json variant_test_data() { + return R"([ + {"type": "circle", "object": {"radius" : 5}}, + {"type": "rectangle", "object": {"width": 6, "height": 5}} + ])"_json; +} #endif diff --git a/tests/toml11.cpp b/tests/toml11.cpp index 2fa2c46..2448e97 100644 --- a/tests/toml11.cpp +++ b/tests/toml11.cpp @@ -7,22 +7,8 @@ using namespace serde; using namespace toml::literals; TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { - toml::value toml_vl = R"( - str = "hello" - i = 10 - vec = [ "one", "two", "three" ] - opt = "hello" - [sm] - one = "tone" - two = "ttwo" - [sub] - str = "hello" - )"_toml; - - REQUIRE(toml_vl == serialize(deserialize(toml_vl))); -} - -TEST_CASE("5: toml11 struct from_file (pass)", "[multi-file:5]") { auto toml_vl = serde::parse_file("../tests/test.toml"); + std::cout << serialize(deserialize(toml_vl)) << "\n"; + std::cout << toml_vl << "\n"; REQUIRE(toml_vl == serialize(deserialize(toml_vl))); } From b7bb508c51e1f96feb6973b67890db8be34a007a Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 24 Apr 2022 21:29:40 +0900 Subject: [PATCH 32/39] unittest update --- include/serdepp/attributes.hpp | 12 +++++++----- tests/nlohmann_json.cpp | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/serdepp/attributes.hpp b/include/serdepp/attributes.hpp index 3c0d732..7b21742 100644 --- a/include/serdepp/attributes.hpp +++ b/include/serdepp/attributes.hpp @@ -4,14 +4,16 @@ #define __SERDEPP_ATTRIBUTE_HPP__ #include "serdepp/serializer.hpp" -#include "serdepp/attribute/skip.hpp" -#include "serdepp/attribute/value_or_struct.hpp" -#include "serdepp/attribute/string_convert.hpp" -#include "serdepp/attribute/default.hpp" #include "serdepp/attribute/algorithm.hpp" +#include "serdepp/attribute/default.hpp" +#include "serdepp/attribute/flatten.hpp" #include "serdepp/attribute/make_optional.hpp" +#include "serdepp/attribute/meta.hpp" #include "serdepp/attribute/mutli_key.hpp" -#include "serdepp/attribute/flatten.hpp" +#include "serdepp/attribute/skip.hpp" +#include "serdepp/attribute/string_convert.hpp" +#include "serdepp/attribute/utility.hpp" +#include "serdepp/attribute/value_or_struct.hpp" //namespace serde::attribute {} diff --git a/tests/nlohmann_json.cpp b/tests/nlohmann_json.cpp index c40b6a4..ed2ab57 100644 --- a/tests/nlohmann_json.cpp +++ b/tests/nlohmann_json.cpp @@ -10,9 +10,3 @@ TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") { auto json_v = serde::parse_file("../tests/test.json"); REQUIRE(json_v.dump() == serialize(deserialize(json_v)).dump()); } - - -TEST_CASE("2: nlohmann json variant(pass)", "[multi-file:2]") { - auto json_v = variant_test_data(); - REQUIRE(json_v.dump() == serialize(deserialize>(json_v)).dump()); -} From 032246451c35068d5c804d97c2090234cb760f06 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 7 May 2022 17:04:37 +0900 Subject: [PATCH 33/39] add annotation [[maybe_unused]] --- include/serdepp/serializer.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/serdepp/serializer.hpp b/include/serdepp/serializer.hpp index 68f1474..107bb6b 100644 --- a/include/serdepp/serializer.hpp +++ b/include/serdepp/serializer.hpp @@ -27,39 +27,39 @@ namespace serde template struct serde_adaptor_helper { // for support optional type parse - inline constexpr static bool is_null(Adaptor& adaptor, std::string_view key); + [[maybe_unused]] inline constexpr static bool is_null(Adaptor& adaptor, std::string_view key); // for support no_remain function - inline constexpr static size_t size(Adaptor& adaptor); + [[maybe_unused]] inline constexpr static size_t size(Adaptor& adaptor); // for support string_or_struct - inline constexpr static bool is_struct(Adaptor& adaptor); + [[maybe_unused]] inline constexpr static bool is_struct(Adaptor& adaptor); // for support parse_file - inline constexpr static Adaptor parse_file(const std::string& path); + [[maybe_unused]] inline constexpr static Adaptor parse_file(const std::string& path); }; template struct derive_serde_adaptor_helper { // default serde adaptor helper - inline constexpr static bool is_null(Adaptor& adaptor, std::string_view key) { + [[maybe_unused]] inline constexpr static bool is_null(Adaptor& adaptor, std::string_view key) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::is_null(adaptor, key)"); return adaptor.contains(key); } - inline constexpr static size_t size(Adaptor& adaptor) { + [[maybe_unused]] inline constexpr static size_t size(Adaptor& adaptor) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::size(adaptor, key)"); return adaptor.size(); } - inline constexpr static bool is_struct(Adaptor& adaptor) { + [[maybe_unused]] inline constexpr static bool is_struct(Adaptor& adaptor) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::is_struct(adaptor, key)"); return true; } - inline constexpr static Adaptor parse_file(Adaptor& adaptor) { + [[maybe_unused]] inline constexpr static Adaptor parse_file(Adaptor& adaptor) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::parse_file(adaptor, key)"); @@ -69,14 +69,14 @@ namespace serde template struct serde_adaptor { - static void from(S& s, std::string_view key, T& data){} - static void into(S& s, std::string_view key, const T& data){} + [[maybe_unused]] static void from(S& s, std::string_view key, T& data){} + [[maybe_unused]] static void into(S& s, std::string_view key, const T& data){} }; namespace detail { struct dummy_adaptor{ - bool contains(std::string_view key) { return true; } - size_t size() { return 1; } + [[maybe_unused]] bool contains(std::string_view key) { return true; } + [[maybe_unused]] size_t size() { return 1; } }; }; From 2a63036dc28c8c3db93ee69fd60e73e2c6107c88 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 15 May 2022 23:30:24 +0900 Subject: [PATCH 34/39] new helper is_adaptor_v --- include/serdepp/meta.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/serdepp/meta.hpp b/include/serdepp/meta.hpp index d0a607a..6eb8c11 100644 --- a/include/serdepp/meta.hpp +++ b/include/serdepp/meta.hpp @@ -46,6 +46,18 @@ namespace serde::meta { template using tuple_extend_t = typename tuple_extend::type; + template + struct to_variant { + using type = std::variant; + }; + + template + struct to_variant> { + using type = std::variant; + }; + + template + using to_variant_t = typename to_variant::type; template struct is_iterable : std::false_type {}; template @@ -186,6 +198,8 @@ namespace serde::meta { > : std::true_type {}; template inline constexpr auto is_serdeable_v = is_serdeable::value; + template + constexpr const auto is_adaptor_v = std::is_same_v; template using attr = typename Attribute::template serde_attribute; From 229551364671d047d4333c122fe09cda69039207 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 15 May 2022 23:32:11 +0900 Subject: [PATCH 35/39] cli11 adaptor support update new attributes - `***_r` == [option_r, flag_r, ...] require option, require flag ... - `sub_command` inline subcommand `DERIVE_SERDE(T, attrs(desc("T desc"), callback{...}, sub_command("sc", "T subdommand sc desc", [](T& d){ ... })))` --- examples/cli11.cpp | 35 +++-- include/serdepp/adaptor/cli11.hpp | 10 +- include/serdepp/attribute/cli11.hpp | 197 +++++++++++++++++++++++----- 3 files changed, 191 insertions(+), 51 deletions(-) diff --git a/examples/cli11.cpp b/examples/cli11.cpp index 921a24a..643a074 100644 --- a/examples/cli11.cpp +++ b/examples/cli11.cpp @@ -39,36 +39,47 @@ struct Test2 : callback_interface { struct Nested { DERIVE_SERDE(Nested, - .attrs(desc{"Nested Cmd"}, callback{Nested::execute}) - [attrs(flag("--check,-c", "on off", [](auto* opt){ opt->required(); }))]_SF_(check) + .attrs(desc{"Nested Cmd"}, callback{Nested::execute}, + option_group{"Type", "Project Type", [](auto* g){ g->require_option(1); }}, + sub_command{"test2", "Test2 subcommand", Nested::test2}, + sub_command{"test1", "Test1 subcommand", Nested::test1} + ) + [attrs(flag("--check,-c", "on off"))]_SF_(check) [attrs(option("--hello", "hello"))]_SF_(hello) - [attrs(option("first", "first", [](auto* opt){ opt->required(); }))]_SF_(first) + [attrs(group_flag("Type","-l,--lib", "lib"))]_SF_(lib) + [attrs(group_flag("Type","-b,--bin", "bin"))]_SF_(bin) + [attrs(option("first", "first"))]_SF_(first) [attrs(option("second", "second"))]_SF_(second) - _SF_(test)) + _SF_(test3)) static void execute(Nested& n) { fmt::print("{}\n",n); - throw CLI::Success{}; } + static void test2(Nested& n) { + fmt::print("hello2 {}", n); + } + + static void test1(Nested& n) { + fmt::print("hello {}", n); + } + bool check; + bool lib; + bool bin; std::string hello; std::string first; std::string second; - SingleCommand test; + SingleCommand test3; }; struct Cmd { DERIVE_SERDE(Cmd, - .attrs(command{"Cmd Test"}, - option_group{"Type", "Project Type", [](auto* g){ g->require_option(1); }}, - callback{Cmd::execute}) + .attrs(command{"Cmd Test"}, callback{Cmd::execute}) [attrs(flag("-c{check},-f{fheck}", "on off"))]_SF_(check) [attrs(option("--hello", "hello"))]_SF_(hello) [attrs(option("-D", "CMake option"))]_SF_(cmake) - [attrs(group_flag("Type","-l,--lib", "lib"))]_SF_(lib) - [attrs(group_flag("Type","-b,--bin", "bin"))]_SF_(bin) _SF_(nest) _SF_(test) _SF_(t2) @@ -81,8 +92,6 @@ struct Cmd { } std::string check; - bool lib; - bool bin; std::string hello; std::string cmake; SingleCommand test; diff --git a/include/serdepp/adaptor/cli11.hpp b/include/serdepp/adaptor/cli11.hpp index fc45f38..058f522 100644 --- a/include/serdepp/adaptor/cli11.hpp +++ b/include/serdepp/adaptor/cli11.hpp @@ -36,13 +36,8 @@ namespace serde { }; template struct serde_adaptor { - static void from(cli11_t& s, std::string_view key, T& data) { - //if(!s.get_arg(key).is_require() && !s.get_arg(key).visit()) return; - //data = s.get_arg(key).get(); - } - static void into(cli11_t& s, std::string_view key, const T& data) { - //s.arg_after_init(std::string{key}); - } + static void from(cli11_t& s, std::string_view key, T& data) {} + static void into(cli11_t& s, std::string_view key, const T& data) {} }; template @@ -54,7 +49,6 @@ namespace serde { CLI11_PARSE(app, argc, argv); return 0; } - } #endif diff --git a/include/serdepp/attribute/cli11.hpp b/include/serdepp/attribute/cli11.hpp index ba2634e..daa0112 100644 --- a/include/serdepp/attribute/cli11.hpp +++ b/include/serdepp/attribute/cli11.hpp @@ -7,141 +7,278 @@ #include namespace serde::attribute::cli11 { - struct flag { + + class flag { + public: using Hook = std::function; flag(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : key_(key), desc_(desc), hook_(std::move(hook)) {}; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.add_flag(std::string{key_}, data, std::string{desc_})); + } + next_attr.into(ctx, data, key, remains...); + } + private: std::string_view key_, desc_; Hook&& hook_; + }; + + // require flag + class flag_r { + public: + using Hook = std::function; + flag_r(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : key_(key), desc_(desc), hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { - hook_(ctx.adaptor.add_flag(std::string{key_}, data, std::string{desc_})); + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.add_flag(std::string{key_}, data, std::string{desc_})->required()); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view key_, desc_; + Hook&& hook_; }; - struct group_flag { + class group_flag { + public: using Hook = std::function; group_flag(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.get_option_group(std::string{group_}) + ->add_flag(std::string{key_}, data, std::string{desc_})); + } + next_attr.into(ctx, data, key, remains...); + } + private: std::string_view group_, key_, desc_; Hook&& hook_; + }; + + // group require flag + class group_flag_r { + public: + using Hook = std::function; + group_flag_r(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { - hook_(ctx.adaptor.get_option_group(std::string{group_})->add_flag(std::string{key_}, data, std::string{desc_})); + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.get_option_group(std::string{group_}) + ->add_flag(std::string{key_}, data, std::string{desc_}) + ->required()); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view group_, key_, desc_; + Hook&& hook_; }; - struct option { + class option { + public: using Hook = std::function; option(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : key_(key), desc_(desc), hook_(std::move(hook)) {}; - std::string_view key_, desc_; - Hook&& hook_; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { + if constexpr(is_adaptor_v) { hook_(ctx.adaptor.add_option(std::string{key_}, data, std::string{desc_})); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view key_, desc_; + Hook&& hook_; }; - struct group_option { + class group_option { + public: using Hook = std::function; group_option(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.get_option_group(std::string{group_}) + ->add_option(std::string{key_}, data, std::string{desc_})); + } + next_attr.into(ctx, data, key, remains...); + } + private: std::string_view group_, key_, desc_; Hook&& hook_; + }; + + // require option + class option_r { + public: + using Hook = std::function; + option_r(std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : key_(key), desc_(desc), hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { - hook_(ctx.adaptor.get_option_group(std::string{group_})->add_option(std::string{key_}, data, std::string{desc_})); + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.add_option(std::string{key_}, data, std::string{desc_})->required()); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view key_, desc_; + Hook&& hook_; }; - struct desc { - desc(std::string_view desc) : desc_(desc) {}; - std::string_view desc_; + // group require option + class group_option_r { + public: + using Hook = std::function; + group_option_r(std::string_view group, std::string_view key, std::string_view desc, Hook&& hook = [](CLI::Option* o){}) + : group_(group), key_(key), desc_(desc), hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { - ctx.adaptor.description(std::string{desc_}); + if constexpr(is_adaptor_v) { + hook_(ctx.adaptor.get_option_group(std::string{group_}) + ->add_option(std::string{key_}, data, std::string{desc_}) + ->required()); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view group_, key_, desc_; + Hook&& hook_; }; - struct command { + class command { + public: using Hook = std::function; - command(std::string_view desc, Hook&& hook=[](CLI::App& a){}) : desc_(desc), hook_(std::move(hook)) {}; + command(std::string_view desc, Hook&& hook=[](CLI::App& a){}) + : desc_(desc), hook_(std::move(hook)) {}; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(is_adaptor_v) { + ctx.adaptor.description(std::string{desc_}); + hook_(ctx.adaptor); + } + next_attr.into(ctx, data, key, remains...); + } + private: std::string_view desc_; Hook&& hook_; + }; + + // for struct attributes(...) + class desc { + public: + desc(std::string_view desc) : desc_(desc) {}; + SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { + if constexpr(is_adaptor_v) { ctx.adaptor.description(std::string{desc_}); - hook_(ctx.adaptor); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view desc_; }; + template - struct callback { - callback(Hook&& hook) : hook_(hook) {}; - Hook&& hook_; + class callback { + public: + callback(Hook&& hook) : hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { + if constexpr(is_adaptor_v) { ctx.adaptor.final_callback([&data, hook = std::move(hook_)](){ hook(data); }); } next_attr.into(ctx, data, key, remains...); } + private: + Hook&& hook_; }; - struct option_group { - using Hook = std::function; - option_group(std::string_view name, std::string_view desc, Hook&& hook=[](CLI::App* o){}) : name_(name), desc_(desc), hook_(std::move(hook)) {}; + template + class sub_command { + public: + sub_command(std::string_view name, std::string_view desc, Hook&& hook) + : name_(name), desc_(desc), hook_(std::move(hook)) {}; + + SERDEPP_DEFAULT_ATTRIBUTE_FROM() + template + inline void into(serde_ctx& ctx, T& data, std::string_view key, + Next&& next_attr, Attributes&&... remains) { + if constexpr(is_adaptor_v) { + ctx.adaptor + .add_subcommand(std::string{name_}, std::string{desc_}) + ->final_callback([&data, hook = std::move(hook_)](){ + hook(data); + throw CLI::Success{}; + }); + } + next_attr.into(ctx, data, key, remains...); + } + private: std::string_view name_, desc_; Hook&& hook_; + }; + + class option_group { + public: + using Hook = std::function; + option_group(std::string_view name, std::string_view desc, Hook&& hook=[](CLI::App* o){}) + : name_(name), desc_(desc), hook_(std::move(hook)) {}; SERDEPP_DEFAULT_ATTRIBUTE_FROM() template inline void into(serde_ctx& ctx, T& data, std::string_view key, Next&& next_attr, Attributes&&... remains) { - if constexpr(std::is_same_v) { + if constexpr(is_adaptor_v) { hook_(ctx.adaptor.add_option_group(std::string{name_}, std::string{desc_})); } next_attr.into(ctx, data, key, remains...); } + private: + std::string_view name_, desc_; + Hook&& hook_; }; } From 7c63e85c22ffb84bf495a94afc21ee6d9c46a478 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sun, 15 May 2022 23:36:20 +0900 Subject: [PATCH 36/39] remove example/reflection.cpp unused waring --- include/serdepp/adaptor/reflection.hpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/serdepp/adaptor/reflection.hpp b/include/serdepp/adaptor/reflection.hpp index f1613a0..665017e 100644 --- a/include/serdepp/adaptor/reflection.hpp +++ b/include/serdepp/adaptor/reflection.hpp @@ -11,7 +11,7 @@ namespace serde { template void func(T& type, std::string_view key) {} }; - template + template class type_info_adaptor { public: using Hook = H; @@ -24,6 +24,7 @@ namespace serde { Hook& hook_; }; + template class MemberFromKey { public: @@ -89,6 +90,21 @@ namespace serde { M* member_; }; + template + class MemberArray { + public: + using value_type = meta::to_variant_t>; + DERIVE_SERDE(MemberArray,(&Self::array_, "array")) + friend type_info_adaptor>; + constexpr MemberArray() : visit_(0) {}; + constexpr inline auto& value() { return array_; } + private: + template + inline constexpr void func(U& data, std::string_view key) { array_[visit_++] = data; } + std::array> array_; + size_t visit_; + }; + template class MemberNames { public: @@ -98,9 +114,7 @@ namespace serde { inline constexpr const auto& members() const { return members_; } private: template - inline constexpr void func(U& data, std::string_view key) { - members_[index_++]=key; - } + inline constexpr void func(U& data, std::string_view key) { members_[index_++]=key; } std::array> members_; size_t index_; }; @@ -114,7 +128,6 @@ namespace serde { constexpr static std::string_view name = nameof::nameof_type(); constexpr serde_struct_info() = default; - //constexpr std::string_view name() { return nameof::nameof_type();} template @@ -176,6 +189,8 @@ namespace serde { using rtype = meta::remove_cvref_t; return detail::make_tuple_impl(value, std::make_index_sequence>()); } + + template struct special_adaptor> : std::true_type {}; } #endif From 9e5113a20004154ed269b73b74832bce8f94d11c Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 17 Sep 2022 23:36:28 +0900 Subject: [PATCH 37/39] formatting --- cppm.toml | 4 ++-- examples/reflection.cpp | 4 ++-- examples/sugar.cpp | 1 - include/serdepp/meta.hpp | 10 ++++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cppm.toml b/cppm.toml index b98be49..dee97ee 100644 --- a/cppm.toml +++ b/cppm.toml @@ -93,8 +93,8 @@ source = ["benchmark/syntax_benchmark.cpp"] [[tests]] -name = "unittest" -source = ["tests/.*"] + name = "unittest" + source = ["tests/.*"] [dependencies] diff --git a/examples/reflection.cpp b/examples/reflection.cpp index 7749c89..fcffac8 100644 --- a/examples/reflection.cpp +++ b/examples/reflection.cpp @@ -29,8 +29,8 @@ int main(int argc, char* argv[]) { member_b_info = 3.14; auto member_d_info = info.member_info<3>(a); - std::string_view member_d_name = member_d_info.name(); - std::vector& member_d = member_d_info.value(); + [[maybe_unused]] std::string_view member_d_name = member_d_info.name(); + [[maybe_unused]] std::vector& member_d = member_d_info.value(); auto names = info.member_names(); for(auto& name : names.members()) { diff --git a/examples/sugar.cpp b/examples/sugar.cpp index 22bc609..7ee9e43 100644 --- a/examples/sugar.cpp +++ b/examples/sugar.cpp @@ -22,7 +22,6 @@ namespace serde::attribute { [[maybe_unused]] constexpr static auto tttt = detail::tttt{}; } - struct Test { DERIVE_SERDE(Test, [attributes(flatten)] diff --git a/include/serdepp/meta.hpp b/include/serdepp/meta.hpp index 6eb8c11..a913e0c 100644 --- a/include/serdepp/meta.hpp +++ b/include/serdepp/meta.hpp @@ -40,7 +40,7 @@ namespace serde::meta { template struct tuple_extend> { - using type = std::tuple; + using type = std::tuple; }; template @@ -61,7 +61,9 @@ namespace serde::meta { template struct is_iterable : std::false_type {}; template - struct is_iterable().begin()), decltype(std::declval().end())>> + struct is_iterable().begin()), + decltype(std::declval().end())>> : std::true_type {}; template constexpr auto is_iterable_v = is_iterable::value; @@ -87,7 +89,8 @@ namespace serde::meta { template struct is_mappable()[std::declval()])>> + decltype(std::declval() + [std::declval()])>> : std::true_type { }; template inline constexpr auto is_mappable_v = is_mappable::value; @@ -102,7 +105,6 @@ namespace serde::meta { magic_enum::is_unscoped_enum_v>> : std::true_type {}; template inline constexpr auto is_enumable_v = is_enumable::value; - //template struct is_pointer : std::false_type {}; //template //struct is_pointer>> : std::true_type {}; From 78d99ded71205e4f43abb566012b2cd60669d16f Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 17 Sep 2022 23:36:41 +0900 Subject: [PATCH 38/39] readme update --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d3438a..4e0fd7b 100644 --- a/README.md +++ b/README.md @@ -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) From 8d05448eb3a7a4402aab02e1356ea871040d5f39 Mon Sep 17 00:00:00 2001 From: injae <8687lee@gmail.com> Date: Sat, 17 Sep 2022 23:38:14 +0900 Subject: [PATCH 39/39] readme update --- README.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 4e0fd7b..fcce0a8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![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) +[![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) @@ -306,11 +306,6 @@ int main(int argc, char* argv[]) { #include #include -/// optional beta feature (for std::cout) -#include -using namespace serde::ostream; -/// - enum class tenum { INPUT = 1, OUTPUT = 2, @@ -405,9 +400,6 @@ int main() // class(test) -> string fmt::print("{}\n", t); - // beta feature - // need: #include - // need: using namespace serdepp::ostream; // class(test) -> string std:cout << t << '\n'; //