diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 0125cca6..f824b7a7 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks"] + format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks", "headers"] compiler: [llvm, gcc] compiler-version: [11, 12, 13, 14, 16, 17, 18] cxx: [20, 23] @@ -82,12 +82,14 @@ jobs: cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release elif [[ "${{ matrix.format }}" == "benchmarks" ]]; then cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_BENCHMARKS=ON -DREFLECTCPP_ALL_FORMATS=ON -DCMAKE_BUILD_TYPE=Release + elif [[ "${{ matrix.format }}" == "headers" ]]; then + cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_CHECK_HEADERS=ON -DCMAKE_BUILD_TYPE=Release else cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_JSON=OFF -DREFLECTCPP_${{ matrix.format }}=ON -DCMAKE_BUILD_TYPE=Release fi cmake --build build -j4 - name: Run tests - if: matrix.format != 'benchmarks' + if: (matrix.format != 'benchmarks') && (matrix.format != 'headers') run: | ctest --test-dir build --output-on-failure - name: Run benchmarks diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 109b232c..14d17156 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: ["macos-latest", "macos-13"] - format: ["JSON", "AVRO", "CAPNPROTO", "CBOR", "FLEXBUFFERS", "MSGPACK", "PARQUET", "TOML", "UBJSON", "XML", "YAML", "benchmarks"] + format: ["tests", "benchmarks"] name: "${{ matrix.os }} (${{ matrix.format }})" runs-on: ${{ matrix.os }} steps: @@ -43,12 +43,10 @@ jobs: export CMAKE_GENERATOR=Ninja fi $CXX --version - if [[ "${{ matrix.format }}" == "JSON" ]]; then - cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - elif [[ "${{ matrix.format }}" == "benchmarks" ]]; then + if [[ "${{ matrix.format }}" == "benchmarks" ]]; then cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_BENCHMARKS=ON -DREFLECTCPP_ALL_FORMATS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ else - cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_JSON=OFF -DREFLECTCPP_${{ matrix.format }}=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_ALL_FORMATS=ON -DREFLECTCPP_CHECK_HEADERS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ fi cmake --build build -j 4 - name: Run tests diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index b5056c26..be942f87 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -32,17 +32,23 @@ jobs: run: | cmake -S . -B build -G Ninja -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_BENCHMARKS=ON -DREFLECTCPP_ALL_FORMATS=ON -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -j4 + - name: Check headers + if: matrix.format == 'headers' + run: | + cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_CHECK_HEADERS=ON -DCMAKE_BUILD_TYPE=Release + cmake --build build --config Release -j4 - name: Compile tests (JSON) if: matrix.format == 'JSON' run: | cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -j4 - name: Compile tests (Other formats) - if: matrix.format != 'JSON' && matrix.format != 'benchmarks' + if: matrix.format != 'JSON' && matrix.format != 'benchmarks' && matrix.format != 'headers' run: | cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_JSON=OFF -DREFLECTCPP_${{ matrix.format }}=ON -DCMAKE_BUILD_TYPE=Release cmake --build build --config Release -j4 - name: Run tests + if: matrix.format != 'benchmarks' run: | ctest --test-dir build --output-on-failure - name: Run benchmarks @@ -99,4 +105,4 @@ jobs: run: | ctest --test-dir build --output-on-failure - \ No newline at end of file + diff --git a/CMakeLists.txt b/CMakeLists.txt index 2012b679..7aea8a0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(REFLECTCPP_YAML "Enable YAML support" ${REFLECTCPP_ALL_FORMATS}) option(REFLECTCPP_BUILD_BENCHMARKS "Build benchmarks" OFF) option(REFLECTCPP_BUILD_TESTS "Build tests" OFF) +option(REFLECTCPP_CHECK_HEADERS "Make sure that all headers are self-contained" OFF) option(REFLECTCPP_USE_BUNDLED_DEPENDENCIES "Use the bundled dependencies" ON) @@ -55,7 +56,7 @@ if(REFLECTCPP_BUILD_BENCHMARKS) set(REFLECTCPP_YAML ON CACHE BOOL "" FORCE) endif() -if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BUILD_BENCHMARKS OR +if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BUILD_BENCHMARKS OR REFLECTCPP_CHECK_HEADERS OR (REFLECTCPP_JSON AND NOT REFLECTCPP_USE_BUNDLED_DEPENDENCIES) OR REFLECTCPP_AVRO OR REFLECTCPP_BSON OR REFLECTCPP_CAPNPROTO OR REFLECTCPP_CBOR OR REFLECTCPP_CSV OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_PARQUET OR REFLECTCPP_XML OR @@ -73,31 +74,31 @@ endif() option(REFLECTCPP_USE_VCPKG "Use VCPKG to download and build dependencies" ${REFLECTCPP_USE_VCPKG_DEFAULT}) if (REFLECTCPP_USE_VCPKG) - if (REFLECTCPP_AVRO) + if (REFLECTCPP_AVRO OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "avro") endif() - if (REFLECTCPP_BSON) + if (REFLECTCPP_BSON OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "bson") endif() - if (REFLECTCPP_BUILD_BENCHMARKS) + if (REFLECTCPP_BUILD_BENCHMARKS OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "benchmarks") endif() - if (REFLECTCPP_BUILD_TESTS) + if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "tests") endif() - if (REFLECTCPP_CAPNPROTO) + if (REFLECTCPP_CAPNPROTO OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "capnproto") endif() - if (REFLECTCPP_CBOR) + if (REFLECTCPP_CBOR OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "cbor") endif() - if (REFLECTCPP_CSV) + if (REFLECTCPP_CSV OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "csv") endif() @@ -105,7 +106,7 @@ if (REFLECTCPP_USE_VCPKG) list(APPEND VCPKG_MANIFEST_FEATURES "ctre") endif() - if (REFLECTCPP_FLEXBUFFERS) + if (REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "flexbuffers") endif() @@ -113,27 +114,27 @@ if (REFLECTCPP_USE_VCPKG) list(APPEND VCPKG_MANIFEST_FEATURES "json") endif() - if (REFLECTCPP_MSGPACK) + if (REFLECTCPP_MSGPACK OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "msgpack") endif() - if (REFLECTCPP_PARQUET) + if (REFLECTCPP_PARQUET OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "parquet") endif() - if (REFLECTCPP_TOML) + if (REFLECTCPP_TOML OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "toml") endif() - if (REFLECTCPP_UBJSON) + if (REFLECTCPP_UBJSON OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "ubjson") endif() - if (REFLECTCPP_XML) + if (REFLECTCPP_XML OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "xml") endif() - if (REFLECTCPP_YAML) + if (REFLECTCPP_YAML OR REFLECTCPP_CHECK_HEADERS) list(APPEND VCPKG_MANIFEST_FEATURES "yaml") endif() @@ -237,7 +238,7 @@ if (_REFLECTCPP_NEEDS_JSON_IMPL) endif () endif () -if (REFLECTCPP_AVRO) +if (REFLECTCPP_AVRO OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_avro.cpp ) @@ -270,7 +271,7 @@ if (REFLECTCPP_AVRO) target_link_libraries(reflectcpp PRIVATE jansson::jansson) endif () -if (REFLECTCPP_BSON) +if (REFLECTCPP_BSON OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_bson.cpp ) @@ -280,7 +281,7 @@ if (REFLECTCPP_BSON) target_link_libraries(reflectcpp PUBLIC $,mongo::bson_static,mongo::bson_shared>) endif () -if (REFLECTCPP_CAPNPROTO) +if (REFLECTCPP_CAPNPROTO OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_capnproto.cpp ) @@ -295,7 +296,7 @@ if (REFLECTCPP_CAPNPROTO) target_link_libraries(reflectcpp PUBLIC CapnProto::kj CapnProto::capnp ${CAPNPC_LIB} CapnProto::kj-gzip) endif () -if (REFLECTCPP_CBOR) +if (REFLECTCPP_CBOR OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_cbor.cpp ) @@ -305,7 +306,7 @@ if (REFLECTCPP_CBOR) include_directories(PUBLIC ${jsoncons_INCLUDE_DIRS}) endif () -if (REFLECTCPP_CSV) +if (REFLECTCPP_CSV OR REFLECTCPP_CHECK_HEADERS) if (NOT TARGET Arrow) find_package(Arrow CONFIG REQUIRED) endif() @@ -316,7 +317,7 @@ if (REFLECTCPP_CSV) endif() endif () -if (REFLECTCPP_FLEXBUFFERS) +if (REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_flexbuf.cpp ) @@ -326,7 +327,7 @@ if (REFLECTCPP_FLEXBUFFERS) target_link_libraries(reflectcpp PUBLIC flatbuffers::flatbuffers) endif () -if (REFLECTCPP_MSGPACK) +if (REFLECTCPP_MSGPACK OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_msgpack.cpp ) @@ -336,7 +337,7 @@ if (REFLECTCPP_MSGPACK) target_link_libraries(reflectcpp PUBLIC msgpack-c) endif () -if (REFLECTCPP_PARQUET) +if (REFLECTCPP_PARQUET OR REFLECTCPP_CHECK_HEADERS) if (NOT TARGET Arrow) find_package(Arrow CONFIG REQUIRED) endif() @@ -351,7 +352,7 @@ if (REFLECTCPP_PARQUET) endif() endif () -if (REFLECTCPP_TOML) +if (REFLECTCPP_TOML OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_toml.cpp ) @@ -361,7 +362,7 @@ if (REFLECTCPP_TOML) target_link_libraries(reflectcpp PUBLIC tomlplusplus::tomlplusplus) endif() -if (REFLECTCPP_UBJSON) +if (REFLECTCPP_UBJSON OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_ubjson.cpp ) @@ -371,7 +372,7 @@ if (REFLECTCPP_UBJSON) include_directories(PUBLIC ${jsoncons_INCLUDE_DIRS}) endif () -if (REFLECTCPP_XML) +if (REFLECTCPP_XML OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_xml.cpp ) @@ -381,7 +382,7 @@ if (REFLECTCPP_XML) target_link_libraries(reflectcpp PUBLIC pugixml::pugixml) endif () -if (REFLECTCPP_YAML) +if (REFLECTCPP_YAML OR REFLECTCPP_CHECK_HEADERS) list(APPEND REFLECT_CPP_SOURCES src/reflectcpp_yaml.cpp ) @@ -415,6 +416,34 @@ if (REFLECTCPP_BUILD_BENCHMARKS) add_subdirectory(benchmarks) endif () +if(REFLECTCPP_CHECK_HEADERS) + file(GLOB_RECURSE PROJECT_HEADERS "include/*.hpp") + + set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/self_contained_tests") + file(MAKE_DIRECTORY "${TEST_DIR}") + + foreach(HEADER_FILE ${PROJECT_HEADERS}) + if(NOT HEADER_FILE MATCHES "thirdparty") + string(MAKE_C_IDENTIFIER ${HEADER_FILE} HEADER_NAME) + set(TEST_SOURCE_FILE "${TEST_DIR}/test_${HEADER_NAME}.cpp") + + file(GENERATE + OUTPUT ${TEST_SOURCE_FILE} + CONTENT "#include \"${HEADER_FILE}\"\n" + ) + + add_library(check_header_${HEADER_NAME} "${TEST_SOURCE_FILE}") + + target_include_directories(check_header_${HEADER_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${ADDITIONAL_INCLUDE_DIRS} + ) + + add_custom_target(check_${HEADER_NAME} ALL DEPENDS check_header_${HEADER_NAME}) + endif() + endforeach() +endif() + if (REFLECTCPP_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -451,9 +480,6 @@ if (REFLECTCPP_INSTALL) ) endif () - -# CPack configuration - # Set general package information set(CPACK_PACKAGE_NAME "reflectcpp") set(CPACK_PACKAGE_VENDOR "Reflect C++ Team") diff --git a/include/rfl/Processors.hpp b/include/rfl/Processors.hpp index 696e9f8e..14707b1f 100644 --- a/include/rfl/Processors.hpp +++ b/include/rfl/Processors.hpp @@ -2,6 +2,7 @@ #define RFL_INTERNAL_PROCESSORS_HPP_ #include +#include #include "internal/is_add_tags_to_variants_v.hpp" #include "internal/is_allow_raw_ptrs_v.hpp" @@ -69,9 +70,9 @@ struct Processors { template static auto process(NamedTupleType&& _named_tuple) { - static_assert(!add_tags_to_variants_ || !add_namespaced_tags_to_variants_, - "You cannot add both rfl::AddTagsToVariants and " - "rfl::AddNamespacedTagsToVariants."); + static_assert(!add_tags_to_variants_ || !add_namespaced_tags_to_variants_, + "You cannot add both rfl::AddTagsToVariants and " + "rfl::AddNamespacedTagsToVariants."); return Processors::template process( Head::template process(std::move(_named_tuple))); } diff --git a/include/rfl/Timestamp.hpp b/include/rfl/Timestamp.hpp index 31eaa657..64468229 100644 --- a/include/rfl/Timestamp.hpp +++ b/include/rfl/Timestamp.hpp @@ -7,6 +7,7 @@ #include #include +#include "Literal.hpp" #include "Result.hpp" #include "internal/StringLiteral.hpp" diff --git a/include/rfl/Tuple.hpp b/include/rfl/Tuple.hpp index d88af559..f654be47 100644 --- a/include/rfl/Tuple.hpp +++ b/include/rfl/Tuple.hpp @@ -2,6 +2,7 @@ #define RFL_TUPLE_HPP_ #include +#include #include #include #include @@ -43,9 +44,7 @@ class Tuple { Tuple(const Tuple& _other) { copy_from_other(_other, seq_); } - Tuple(Tuple&& _other) noexcept { - move_from_other(std::move(_other), seq_); - } + Tuple(Tuple&& _other) noexcept { move_from_other(std::move(_other), seq_); } ~Tuple() { destroy_if_necessary(seq_); } @@ -154,8 +153,7 @@ class Tuple { } template - void move_from_other(Tuple&& _other, - std::integer_sequence) { + void move_from_other(Tuple&& _other, std::integer_sequence) { const auto move_one = [this](auto&& _other, std::integral_constant) { using Type = internal::nth_element_t<_i, Types...>; diff --git a/include/rfl/avro/Parser.hpp b/include/rfl/avro/Parser.hpp index 706f4caf..369bb797 100644 --- a/include/rfl/avro/Parser.hpp +++ b/include/rfl/avro/Parser.hpp @@ -2,9 +2,11 @@ #define RFL_AVRO_PARSER_HPP_ #include "../Generic.hpp" +#include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" -//#include "../parsing/Parser.hpp" +#include "../parsing/AreReaderAndWriter.hpp" +#include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" diff --git a/include/rfl/avro/SchemaImpl.hpp b/include/rfl/avro/SchemaImpl.hpp index 85e1492f..0264c016 100644 --- a/include/rfl/avro/SchemaImpl.hpp +++ b/include/rfl/avro/SchemaImpl.hpp @@ -5,8 +5,7 @@ #include -//#include "../Box.hpp" -//#include "../Result.hpp" +#include "../Box.hpp" #include "../common.hpp" namespace rfl::avro { diff --git a/include/rfl/avro/Writer.hpp b/include/rfl/avro/Writer.hpp index 2ce8b7bf..5f780256 100644 --- a/include/rfl/avro/Writer.hpp +++ b/include/rfl/avro/Writer.hpp @@ -1,21 +1,22 @@ #ifndef RFL_AVRO_WRITER_HPP_ #define RFL_AVRO_WRITER_HPP_ +#include + +#include #include #include #include #include -#include - -//#include "../Box.hpp" #include "../Bytestring.hpp" -//#include "../Ref.hpp" -//#include "../Result.hpp" +#include "../Timestamp.hpp" #include "../Vectorstring.hpp" #include "../always_false.hpp" -#include "../internal/is_literal.hpp" #include "../common.hpp" +#include "../internal/is_literal.hpp" +#include "../internal/is_validator.hpp" +#include "../patterns.hpp" namespace rfl::avro { @@ -102,9 +103,9 @@ class RFL_API Writer { const size_t _size, OutputMapType* _parent) const; - OutputObjectType add_object_to_object( - const std::string_view& _name, const size_t _size, - OutputObjectType* _parent) const; + OutputObjectType add_object_to_object(const std::string_view& _name, + const size_t _size, + OutputObjectType* _parent) const; OutputObjectType add_object_to_union(const size_t _index, const size_t _size, OutputUnionType* _parent) const; @@ -137,7 +138,9 @@ class RFL_API Writer { avro_value_t new_value; int result = avro_value_append(&_parent->val_, &new_value, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } set_value(_var, &new_value); return OutputVarType{new_value}; @@ -147,9 +150,12 @@ class RFL_API Writer { OutputVarType add_value_to_map(const std::string_view& _name, const T& _var, OutputMapType* _parent) const { avro_value_t new_value; - int result = avro_value_add(&_parent->val_, _name.data(), &new_value, nullptr, nullptr); + int result = avro_value_add(&_parent->val_, _name.data(), &new_value, + nullptr, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } set_value(_var, &new_value); return OutputVarType{new_value}; @@ -160,9 +166,12 @@ class RFL_API Writer { const T& _var, OutputObjectType* _parent) const { avro_value_t new_value; - int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_value, nullptr); + int result = avro_value_get_by_name(&_parent->val_, _name.data(), + &new_value, nullptr); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } set_value(_var, &new_value); return OutputVarType{new_value}; @@ -175,9 +184,12 @@ class RFL_API Writer { throw std::runtime_error(std::string(__FUNCTION__) + " index error"); } avro_value_t new_value; - int result = avro_value_set_branch(&_parent->val_, static_cast(_index), &new_value); + int result = avro_value_set_branch(&_parent->val_, static_cast(_index), + &new_value); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } set_value(_var, &new_value); return OutputVarType{new_value}; @@ -193,9 +205,12 @@ class RFL_API Writer { template void set_value(const T& _var, avro_value_t* _val) const { if constexpr (std::is_same, std::string>()) { - int result = avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1); + int result = + avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } } else if constexpr (std::is_same, rfl::Bytestring>() || @@ -207,35 +222,44 @@ class RFL_API Writer { } int result = avro_value_set_bytes(_val, var.data(), var.size()); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } } else if constexpr (std::is_same, bool>()) { int result = avro_value_set_boolean(_val, _var); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } } else if constexpr (std::is_floating_point>()) { /*int result = avro_value_set_double(_val, static_cast(_var)); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error("+ + std::to_string(result)+"): " + avro_strerror()); }*/ avro_value_set_double(_val, static_cast(_var)); } else if constexpr (std::is_integral>()) { /*int result = avro_value_set_long(_val, static_cast(_var)); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error("+ + std::to_string(result)+"): " + avro_strerror()); }*/ avro_value_set_long(_val, static_cast(_var)); } else if constexpr (internal::is_literal_v) { int result = avro_value_set_enum(_val, static_cast(_var.value())); if (result != 0) { - throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror()); + throw std::runtime_error(std::string(__FUNCTION__) + " error(" + + std::to_string(result) + + "): " + avro_strerror()); } } else if constexpr (internal::is_validator_v) { using ValueType = std::remove_cvref_t; const auto val = _var.value(); set_value(val, _val); - } else if constexpr (std::is_same, rfl::Timestamp<"%Y-%m-%d">>()) { + } else if constexpr (std::is_same, + rfl::Timestamp<"%Y-%m-%d">>()) { const auto str = _var.to_string(); set_value(str, _val); } else if constexpr (std::is_same, rfl::Email>()) { diff --git a/include/rfl/bson/Parser.hpp b/include/rfl/bson/Parser.hpp index 8f132943..e3973a46 100644 --- a/include/rfl/bson/Parser.hpp +++ b/include/rfl/bson/Parser.hpp @@ -3,7 +3,8 @@ #include -//#include "../parsing/Parser.hpp" +#include "../parsing/AreReaderAndWriter.hpp" +#include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -12,7 +13,7 @@ namespace rfl::parsing { /// bson_oid_t needs to be treated as a special case, otherwise it will be read /// as a struct. template -requires AreReaderAndWriter + requires AreReaderAndWriter struct Parser { using InputVarType = typename R::InputVarType; diff --git a/include/rfl/bson/Reader.hpp b/include/rfl/bson/Reader.hpp index e8abc5af..9cb714d6 100644 --- a/include/rfl/bson/Reader.hpp +++ b/include/rfl/bson/Reader.hpp @@ -9,12 +9,11 @@ #include #include -//#include "../Box.hpp" -//#include "../Bytestring.hpp" +#include "../Bytestring.hpp" #include "../Result.hpp" -//#include "../Vectorstring.hpp" +#include "../Vectorstring.hpp" #include "../always_false.hpp" -//#include "../internal/ptr_cast.hpp" +#include "../internal/ptr_cast.hpp" namespace rfl { namespace bson { @@ -110,16 +109,14 @@ struct Reader { using VectorType = std::remove_cvref_t; using ValueType = typename VectorType::value_type; if (btype != BSON_TYPE_BINARY) { - if constexpr (std::is_same, - rfl::Bytestring>()) { + if constexpr (std::is_same, rfl::Bytestring>()) { return error("Could not cast to bytestring."); } else { return error("Could not cast to vectorstring."); } } if (value.v_binary.subtype != BSON_SUBTYPE_BINARY) { - if constexpr (std::is_same, - rfl::Bytestring>()) { + if constexpr (std::is_same, rfl::Bytestring>()) { return error( "The BSON subtype must be a binary in order to read into a " "bytestring."); diff --git a/include/rfl/capnproto/Parser.hpp b/include/rfl/capnproto/Parser.hpp index 43e9ed73..60e205c1 100644 --- a/include/rfl/capnproto/Parser.hpp +++ b/include/rfl/capnproto/Parser.hpp @@ -1,10 +1,11 @@ #ifndef RFL_CAPNPROTO_PARSER_HPP_ #define RFL_CAPNPROTO_PARSER_HPP_ -//#include "../Generic.hpp" +#include "../Generic.hpp" +#include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" -//#include "../parsing/Parser.hpp" +#include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" diff --git a/include/rfl/capnproto/Reader.hpp b/include/rfl/capnproto/Reader.hpp index d041b5c5..819a5f3e 100644 --- a/include/rfl/capnproto/Reader.hpp +++ b/include/rfl/capnproto/Reader.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,9 +12,9 @@ #include "../Result.hpp" #include "../Vectorstring.hpp" #include "../always_false.hpp" +#include "../common.hpp" #include "../internal/is_literal.hpp" #include "../internal/ptr_cast.hpp" -#include "../common.hpp" namespace rfl::capnproto { @@ -69,8 +70,7 @@ class RFL_API Reader { using VectorType = std::remove_cvref_t; using ValueType = typename VectorType::value_type; if (type != capnp::DynamicValue::DATA) { - if constexpr (std::is_same, - rfl::Bytestring>()) { + if constexpr (std::is_same, rfl::Bytestring>()) { return error("Could not cast to bytestring."); } else { return error("Could not cast to vectorstring."); diff --git a/include/rfl/capnproto/SchemaImpl.hpp b/include/rfl/capnproto/SchemaImpl.hpp index ff783bc9..b45fe4d8 100644 --- a/include/rfl/capnproto/SchemaImpl.hpp +++ b/include/rfl/capnproto/SchemaImpl.hpp @@ -5,8 +5,7 @@ #include -//#include "../Box.hpp" -//#include "../Result.hpp" +#include "../Box.hpp" #include "../common.hpp" namespace rfl::capnproto { diff --git a/include/rfl/capnproto/is_named_type.hpp b/include/rfl/capnproto/is_named_type.hpp index c95377c3..cad64d63 100644 --- a/include/rfl/capnproto/is_named_type.hpp +++ b/include/rfl/capnproto/is_named_type.hpp @@ -1,6 +1,8 @@ #ifndef RFL_CAPNPROTO_IS_NAMED_TYPE_HPP_ #define RFL_CAPNPROTO_IS_NAMED_TYPE_HPP_ +#include "../parsing/schema/Type.hpp" + namespace rfl::capnproto { inline bool is_named_type(const parsing::schema::Type& _type) { diff --git a/include/rfl/capnproto/schema/CapnProtoTypes.hpp b/include/rfl/capnproto/schema/CapnProtoTypes.hpp index 5a5515f4..6f50f4e6 100644 --- a/include/rfl/capnproto/schema/CapnProtoTypes.hpp +++ b/include/rfl/capnproto/schema/CapnProtoTypes.hpp @@ -3,6 +3,7 @@ #include +#include "../../internal/strings/strings.hpp" #include "Type.hpp" namespace rfl::capnproto::schema { diff --git a/include/rfl/capnproto/to_schema.hpp b/include/rfl/capnproto/to_schema.hpp index 8fc31f80..2a6e96a2 100644 --- a/include/rfl/capnproto/to_schema.hpp +++ b/include/rfl/capnproto/to_schema.hpp @@ -3,20 +3,20 @@ #include -//#include "../Literal.hpp" -//#include "../Processors.hpp" +#include "../Literal.hpp" +#include "../Processors.hpp" #include "../Result.hpp" -//#include "../SnakeCaseToCamelCase.hpp" -//#include "../Variant.hpp" -//#include "../json.hpp" -//#include "../parsing/schema/Type.hpp" -//#include "../parsing/schema/ValidationType.hpp" +#include "../SnakeCaseToCamelCase.hpp" +#include "../Variant.hpp" +#include "../common.hpp" +#include "../json.hpp" +#include "../parsing/schema/Type.hpp" +#include "../parsing/schema/ValidationType.hpp" #include "../parsing/schema/make.hpp" +#include "Reader.hpp" #include "Schema.hpp" #include "Writer.hpp" -#include "Reader.hpp" -//#include "schema/Type.hpp" -#include "../common.hpp" +#include "schema/Type.hpp" namespace rfl::capnproto { diff --git a/include/rfl/cbor/Parser.hpp b/include/rfl/cbor/Parser.hpp index 658190bf..8bcd9150 100644 --- a/include/rfl/cbor/Parser.hpp +++ b/include/rfl/cbor/Parser.hpp @@ -1,8 +1,7 @@ #ifndef RFL_CBOR_PARSER_HPP_ #define RFL_CBOR_PARSER_HPP_ -//#include "../Tuple.hpp" -//#include "../parsing/Parser.hpp" +#include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" diff --git a/include/rfl/flexbuf/Reader.hpp b/include/rfl/flexbuf/Reader.hpp index d8d8460f..539c338c 100644 --- a/include/rfl/flexbuf/Reader.hpp +++ b/include/rfl/flexbuf/Reader.hpp @@ -9,11 +9,12 @@ #include #include -//#include "../Bytestring.hpp" +#include "../Bytestring.hpp" +#include "../Ref.hpp" #include "../Result.hpp" -//#include "../Vectorstring.hpp" +#include "../Vectorstring.hpp" #include "../always_false.hpp" -//#include "../internal/ptr_cast.hpp" +#include "../internal/ptr_cast.hpp" namespace rfl { namespace flexbuf { @@ -79,8 +80,7 @@ struct Reader { using VectorType = std::remove_cvref_t; using ValueType = typename VectorType::value_type; if (!_var.IsBlob()) { - if constexpr (std::is_same, - rfl::Bytestring>()) { + if constexpr (std::is_same, rfl::Bytestring>()) { return error("Could not cast to bytestring."); } else { return error("Could not cast to vectorstring."); diff --git a/include/rfl/flexbuf/Writer.hpp b/include/rfl/flexbuf/Writer.hpp index df5c82ae..bf4c85b3 100644 --- a/include/rfl/flexbuf/Writer.hpp +++ b/include/rfl/flexbuf/Writer.hpp @@ -9,8 +9,7 @@ #include #include "../Bytestring.hpp" -//#include "../Ref.hpp" -//#include "../Result.hpp" +#include "../Ref.hpp" #include "../Vectorstring.hpp" #include "../always_false.hpp" #include "../common.hpp" @@ -51,27 +50,27 @@ struct RFL_API Writer { OutputArrayType add_array_to_array(const size_t _size, OutputArrayType* _parent) const noexcept; - OutputArrayType add_array_to_object( - const std::string_view& _name, const size_t _size, - OutputObjectType* _parent) const noexcept; + OutputArrayType add_array_to_object(const std::string_view& _name, + const size_t _size, + OutputObjectType* _parent) const noexcept; - OutputObjectType add_object_to_array( - const size_t _size, OutputArrayType* _parent) const noexcept; + OutputObjectType add_object_to_array(const size_t _size, + OutputArrayType* _parent) const noexcept; OutputObjectType add_object_to_object( const std::string_view& _name, const size_t _size, OutputObjectType* _parent) const noexcept; template - OutputVarType add_value_to_array(const T& _var, - OutputArrayType* /*_parent*/) const noexcept { + OutputVarType add_value_to_array( + const T& _var, OutputArrayType* /*_parent*/) const noexcept { return insert_value(_var); } template - OutputVarType add_value_to_object(const std::string_view& _name, - const T& _var, - OutputObjectType* /*_parent*/) const noexcept { + OutputVarType add_value_to_object( + const std::string_view& _name, const T& _var, + OutputObjectType* /*_parent*/) const noexcept { return insert_value(_name, _var); } diff --git a/include/rfl/internal/Array.hpp b/include/rfl/internal/Array.hpp index e61ef76d..8e16b633 100644 --- a/include/rfl/internal/Array.hpp +++ b/include/rfl/internal/Array.hpp @@ -1,6 +1,7 @@ #ifndef RFL_INTERNAL_ARRAY_HPP_ #define RFL_INTERNAL_ARRAY_HPP_ +#include #include #include "to_std_array.hpp" @@ -9,7 +10,7 @@ namespace rfl { namespace internal { template -requires std::is_array_v + requires std::is_array_v struct Array { using Type = T; using StdArrayType = to_std_array_t; diff --git a/include/rfl/internal/Skip.hpp b/include/rfl/internal/Skip.hpp index 763229ae..a97603d4 100644 --- a/include/rfl/internal/Skip.hpp +++ b/include/rfl/internal/Skip.hpp @@ -2,6 +2,9 @@ #define RFL_INTERNAL_SKIP_HPP_ #include +#include + +#include "../default.hpp" namespace rfl::internal { diff --git a/include/rfl/internal/find_index.hpp b/include/rfl/internal/find_index.hpp index 347d27b7..f32bc968 100644 --- a/include/rfl/internal/find_index.hpp +++ b/include/rfl/internal/find_index.hpp @@ -1,6 +1,7 @@ #ifndef RFL_FIND_INDEX_HPP_ #define RFL_FIND_INDEX_HPP_ +#include "../Tuple.hpp" #include "StringLiteral.hpp" namespace rfl { diff --git a/include/rfl/internal/has_custom_parser.hpp b/include/rfl/internal/has_custom_parser.hpp index a8743288..40b5720d 100644 --- a/include/rfl/internal/has_custom_parser.hpp +++ b/include/rfl/internal/has_custom_parser.hpp @@ -3,7 +3,7 @@ #include -//#include "../parsing/Parser.hpp" +#include "../parsing/Parser.hpp" namespace rfl::internal { diff --git a/include/rfl/internal/is_add_tags_to_variants_v.hpp b/include/rfl/internal/is_add_tags_to_variants_v.hpp index 9086a6f0..4385b1d2 100644 --- a/include/rfl/internal/is_add_tags_to_variants_v.hpp +++ b/include/rfl/internal/is_add_tags_to_variants_v.hpp @@ -3,7 +3,7 @@ #include -//#include "../AddTagsToVariants.hpp" +#include "../AddTagsToVariants.hpp" namespace rfl ::internal { @@ -27,12 +27,13 @@ template class is_add_namespaced_tags_to_variants : public std::false_type {}; template <> -class is_add_namespaced_tags_to_variants : public std::true_type {}; +class is_add_namespaced_tags_to_variants + : public std::true_type {}; template -constexpr bool is_add_namespaced_tags_to_variants_v = is_add_namespaced_tags_to_variants< - std::remove_cvref_t>>::value; - +constexpr bool is_add_namespaced_tags_to_variants_v = + is_add_namespaced_tags_to_variants< + std::remove_cvref_t>>::value; } // namespace rfl::internal diff --git a/include/rfl/internal/is_default_if_missing_v.hpp b/include/rfl/internal/is_default_if_missing_v.hpp index 72e5c208..836ca7e0 100644 --- a/include/rfl/internal/is_default_if_missing_v.hpp +++ b/include/rfl/internal/is_default_if_missing_v.hpp @@ -3,10 +3,9 @@ #include -//#include "../DefaultIfMissing.hpp" +#include "../DefaultIfMissing.hpp" -namespace rfl { -namespace internal { +namespace rfl::internal { template class is_default_if_missing; @@ -21,7 +20,6 @@ template constexpr bool is_default_if_missing_v = is_default_if_missing>>::value; -} // namespace internal -} // namespace rfl +} // namespace rfl::internal #endif diff --git a/include/rfl/internal/is_empty.hpp b/include/rfl/internal/is_empty.hpp index 49e018b5..7434710b 100644 --- a/include/rfl/internal/is_empty.hpp +++ b/include/rfl/internal/is_empty.hpp @@ -5,6 +5,7 @@ #include "../Tuple.hpp" #include "is_named_tuple.hpp" +#include "ptr_tuple_t.hpp" namespace rfl::internal { diff --git a/include/rfl/internal/is_no_field_names_v.hpp b/include/rfl/internal/is_no_field_names_v.hpp index 2b00b704..9c0cbee5 100644 --- a/include/rfl/internal/is_no_field_names_v.hpp +++ b/include/rfl/internal/is_no_field_names_v.hpp @@ -3,10 +3,9 @@ #include -//#include "../NoFieldNames.hpp" +#include "../NoFieldNames.hpp" -namespace rfl { -namespace internal { +namespace rfl::internal { template class is_no_field_names; @@ -21,7 +20,6 @@ template constexpr bool is_no_field_names_v = is_no_field_names>>::value; -} // namespace internal -} // namespace rfl +} // namespace rfl::internal #endif diff --git a/include/rfl/internal/remove_ptrs_nt.hpp b/include/rfl/internal/remove_ptrs_nt.hpp index 97a3d16a..cc503aae 100644 --- a/include/rfl/internal/remove_ptrs_nt.hpp +++ b/include/rfl/internal/remove_ptrs_nt.hpp @@ -4,6 +4,7 @@ #include #include "../Field.hpp" +#include "../NamedTuple.hpp" #include "StringLiteral.hpp" #include "wrap_in_rfl_array_t.hpp" diff --git a/include/rfl/internal/to_std_array.hpp b/include/rfl/internal/to_std_array.hpp index 4d9a936e..509416c1 100644 --- a/include/rfl/internal/to_std_array.hpp +++ b/include/rfl/internal/to_std_array.hpp @@ -2,6 +2,7 @@ #define RFL_INTERNAL_TO_STD_ARRAY_HPP_ #include +#include #include namespace rfl::internal { diff --git a/include/rfl/internal/wrap_in_fields.hpp b/include/rfl/internal/wrap_in_fields.hpp index 93838f2c..f536779d 100644 --- a/include/rfl/internal/wrap_in_fields.hpp +++ b/include/rfl/internal/wrap_in_fields.hpp @@ -3,6 +3,7 @@ #include +#include "../Field.hpp" #include "../Tuple.hpp" #include "flattened_ptr_tuple_t.hpp" #include "is_flatten_field.hpp" diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index ac75f738..b358e71f 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -8,6 +8,7 @@ #endif #include +#include #include #include #include diff --git a/include/rfl/json/schema/Type.hpp b/include/rfl/json/schema/Type.hpp index 4630a296..32e0dcfb 100644 --- a/include/rfl/json/schema/Type.hpp +++ b/include/rfl/json/schema/Type.hpp @@ -7,6 +7,7 @@ #include "../../Literal.hpp" #include "../../Object.hpp" +#include "../../Ref.hpp" #include "../../Rename.hpp" #include "../../Variant.hpp" diff --git a/include/rfl/msgpack/Reader.hpp b/include/rfl/msgpack/Reader.hpp index 2a0bd625..c42c09f4 100644 --- a/include/rfl/msgpack/Reader.hpp +++ b/include/rfl/msgpack/Reader.hpp @@ -5,14 +5,15 @@ #include #include +#include #include #include -//#include "../Bytestring.hpp" +#include "../Bytestring.hpp" #include "../Result.hpp" -//#include "../Vectorstring.hpp" +#include "../Vectorstring.hpp" #include "../always_false.hpp" -//#include "../internal/ptr_cast.hpp" +#include "../internal/ptr_cast.hpp" namespace rfl { namespace msgpack { diff --git a/include/rfl/msgpack/Writer.hpp b/include/rfl/msgpack/Writer.hpp index 2e58828f..dbf980ec 100644 --- a/include/rfl/msgpack/Writer.hpp +++ b/include/rfl/msgpack/Writer.hpp @@ -3,14 +3,13 @@ #include +#include +#include #include #include #include -//#include "../Box.hpp" #include "../Bytestring.hpp" -//#include "../Ref.hpp" -//#include "../Result.hpp" #include "../Vectorstring.hpp" #include "../always_false.hpp" #include "../common.hpp" @@ -47,27 +46,27 @@ class RFL_API Writer { OutputArrayType add_array_to_array(const size_t _size, OutputArrayType* _parent) const noexcept; - OutputArrayType add_array_to_object( - const std::string_view& _name, const size_t _size, - OutputObjectType* _parent) const noexcept; + OutputArrayType add_array_to_object(const std::string_view& _name, + const size_t _size, + OutputObjectType* _parent) const noexcept; - OutputObjectType add_object_to_array( - const size_t _size, OutputArrayType* _parent) const noexcept; + OutputObjectType add_object_to_array(const size_t _size, + OutputArrayType* _parent) const noexcept; OutputObjectType add_object_to_object( const std::string_view& _name, const size_t _size, OutputObjectType* _parent) const noexcept; template - OutputVarType add_value_to_array(const T& _var, - OutputArrayType* /*_parent*/) const noexcept { + OutputVarType add_value_to_array( + const T& _var, OutputArrayType* /*_parent*/) const noexcept { return new_value(_var); } template - OutputVarType add_value_to_object(const std::string_view& _name, - const T& _var, - OutputObjectType* /*_parent*/) const noexcept { + OutputVarType add_value_to_object( + const std::string_view& _name, const T& _var, + OutputObjectType* /*_parent*/) const noexcept { msgpack_pack_str(pk_, _name.size()); msgpack_pack_str_body(pk_, _name.data(), _name.size()); return new_value(_var); @@ -93,7 +92,8 @@ class RFL_API Writer { if constexpr (std::is_same()) { msgpack_pack_str(pk_, _var.size()); msgpack_pack_str_body(pk_, _var.c_str(), _var.size()); - } else if constexpr (std::is_same() || std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { msgpack_pack_bin(pk_, _var.size()); msgpack_pack_bin_body(pk_, _var.data(), _var.size()); } else if constexpr (std::is_same()) { diff --git a/include/rfl/parsing/FieldVariantReader.hpp b/include/rfl/parsing/FieldVariantReader.hpp index e16ea35f..8014fb5b 100644 --- a/include/rfl/parsing/FieldVariantReader.hpp +++ b/include/rfl/parsing/FieldVariantReader.hpp @@ -11,6 +11,7 @@ #include "../Variant.hpp" #include "../internal/is_array.hpp" #include "../internal/nth_element_t.hpp" +#include "Parser_base.hpp" namespace rfl::parsing { diff --git a/include/rfl/parsing/MapReader.hpp b/include/rfl/parsing/MapReader.hpp index 5fe07902..6e932a61 100644 --- a/include/rfl/parsing/MapReader.hpp +++ b/include/rfl/parsing/MapReader.hpp @@ -9,6 +9,8 @@ #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/has_reflection_type_v.hpp" +#include "Parser_base.hpp" namespace rfl::parsing { @@ -56,7 +58,8 @@ class MapReader { } Result> make_key(auto&& _pair) const noexcept { - static_assert(std::is_rvalue_reference_v, "Expected an rvalue"); + static_assert(std::is_rvalue_reference_v, + "Expected an rvalue"); const auto to_pair = [&](auto&& _key) -> Result> { try { diff --git a/include/rfl/parsing/Parser_bytestring.hpp b/include/rfl/parsing/Parser_bytestring.hpp index 93a7499b..18980d09 100644 --- a/include/rfl/parsing/Parser_bytestring.hpp +++ b/include/rfl/parsing/Parser_bytestring.hpp @@ -5,6 +5,7 @@ #include "../Bytestring.hpp" #include "../Result.hpp" +#include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" diff --git a/include/rfl/parsing/Parser_filepath.hpp b/include/rfl/parsing/Parser_filepath.hpp index eecf5763..0c067cd8 100644 --- a/include/rfl/parsing/Parser_filepath.hpp +++ b/include/rfl/parsing/Parser_filepath.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_PARSER_FILEPATH_HPP_ #include +#include #include "../Result.hpp" #include "Parser_base.hpp" diff --git a/include/rfl/parsing/Parser_result.hpp b/include/rfl/parsing/Parser_result.hpp index c6e46104..1aa96d0a 100644 --- a/include/rfl/parsing/Parser_result.hpp +++ b/include/rfl/parsing/Parser_result.hpp @@ -4,9 +4,12 @@ #include #include +#include "../Field.hpp" +#include "../NamedTuple.hpp" #include "../Result.hpp" #include "../always_false.hpp" #include "../internal/StringLiteral.hpp" +#include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -44,17 +47,6 @@ struct Parser, ProcessorsType> { template static void write(const W& _w, const Result& _r, const P& _parent) noexcept { - // const auto write_t = [&](const auto& _t) -> Nothing { - // Parser, ProcessorsType>::write(_w, _t, - // _parent); - // return Nothing{}; - // }; - - // const auto write_err = [&](const auto& _err) -> Nothing { - // Parser::write( - // _w, ErrorType(make_field<"error">(_err.what())), _parent); - // return Nothing{}; - // }; if (_r) { Parser, ProcessorsType>::write( _w, _r.value(), _parent); @@ -62,8 +54,6 @@ struct Parser, ProcessorsType> { Parser::write( _w, ErrorType(make_field<"error">(_r.error().what())), _parent); } - - // _r.transform(write_t).transform_error(write_err); } static schema::Type to_schema( diff --git a/include/rfl/parsing/Parser_rfl_variant.hpp b/include/rfl/parsing/Parser_rfl_variant.hpp index d0f698bd..5de448fc 100644 --- a/include/rfl/parsing/Parser_rfl_variant.hpp +++ b/include/rfl/parsing/Parser_rfl_variant.hpp @@ -7,15 +7,17 @@ #include "../Result.hpp" #include "../Variant.hpp" #include "../always_false.hpp" -#include "../internal/nth_element_t.hpp" #include "../internal/all_fields.hpp" +#include "../internal/nth_element_t.hpp" #include "FieldVariantParser.hpp" +#include "Parent.hpp" #include "Parser_base.hpp" #include "VariantAlternativeWrapper.hpp" #include "schema/Type.hpp" #include "schemaful/IsSchemafulReader.hpp" #include "schemaful/IsSchemafulWriter.hpp" #include "schemaful/VariantReader.hpp" +#include "to_single_error_message.hpp" namespace rfl::parsing { @@ -53,11 +55,11 @@ class Parser, ProcessorsType> { return _r.template read_union, V>(_u); }); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; - using FieldVariantType = - rfl::Variant...>; + using FieldVariantType = rfl::Variant< + VariantAlternativeWrapper...>; const auto from_field_variant = [](auto&& _field) -> rfl::Variant { return std::move(_field.value()); @@ -121,11 +123,12 @@ class Parser, ProcessorsType> { }, _variant); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; using FieldVariantType = - rfl::Variant...>; + rfl::Variant...>; const auto to_field_variant = [](const T& _t) -> FieldVariantType { return VariantAlternativeWrapper(&_t); @@ -148,11 +151,11 @@ class Parser, ProcessorsType> { return FieldVariantParser::to_schema(_definitions); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || + } else if constexpr (ProcessorsType::add_tags_to_variants_ || ProcessorsType::add_namespaced_tags_to_variants_) { constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; - using FieldVariantType = - rfl::Variant...>; + using FieldVariantType = rfl::Variant< + VariantAlternativeWrapper...>; return Parser::to_schema( _definitions); diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index 35adc902..ce4622d3 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -10,6 +10,7 @@ #include "../always_false.hpp" #include "../internal/strings/strings.hpp" #include "../named_tuple_t.hpp" +#include "../visit.hpp" #include "Parser_base.hpp" #include "TaggedUnionWrapper.hpp" #include "is_tagged_union_wrapper.hpp" @@ -157,13 +158,13 @@ struct Parser, using T = tagged_union_wrapper_no_ptr_t), AlternativeType>>; *_result = Parser::read(_r, _var) - .transform(get_fields) - .transform(to_tagged_union) - .transform_error(embellish_error); + .transform(get_fields) + .transform(to_tagged_union) + .transform_error(embellish_error); } else { *_result = Parser::read(_r, _var) - .transform(to_tagged_union) - .transform_error(embellish_error); + .transform(to_tagged_union) + .transform_error(embellish_error); } *_match_found = true; diff --git a/include/rfl/parsing/Parser_vectorstring.hpp b/include/rfl/parsing/Parser_vectorstring.hpp index 480e77bc..474473da 100644 --- a/include/rfl/parsing/Parser_vectorstring.hpp +++ b/include/rfl/parsing/Parser_vectorstring.hpp @@ -3,8 +3,9 @@ #include -#include "../Vectorstring.hpp" #include "../Result.hpp" +#include "../Vectorstring.hpp" +#include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -17,7 +18,7 @@ struct Parser { using ParentType = Parent; static Result read(const R& _r, - const InputVarType& _var) noexcept { + const InputVarType& _var) noexcept { return _r.template to_basic_type(_var); } diff --git a/include/rfl/parsing/TaggedUnionWrapper.hpp b/include/rfl/parsing/TaggedUnionWrapper.hpp index feffceea..2335f8e0 100644 --- a/include/rfl/parsing/TaggedUnionWrapper.hpp +++ b/include/rfl/parsing/TaggedUnionWrapper.hpp @@ -3,6 +3,7 @@ #include +#include "../Field.hpp" #include "../Flatten.hpp" #include "../Rename.hpp" #include "../internal/StringLiteral.hpp" diff --git a/include/rfl/parsing/TupleReader.hpp b/include/rfl/parsing/TupleReader.hpp index 0a5f5dc1..c4304450 100644 --- a/include/rfl/parsing/TupleReader.hpp +++ b/include/rfl/parsing/TupleReader.hpp @@ -7,6 +7,9 @@ #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "AreReaderAndWriter.hpp" +#include "Parser_base.hpp" +#include "is_required.hpp" namespace rfl::parsing { diff --git a/include/rfl/parsing/VectorReader.hpp b/include/rfl/parsing/VectorReader.hpp index 87dfe32c..90824346 100644 --- a/include/rfl/parsing/VectorReader.hpp +++ b/include/rfl/parsing/VectorReader.hpp @@ -1,9 +1,11 @@ #ifndef RFL_PARSING_VECTORREADER_HPP_ #define RFL_PARSING_VECTORREADER_HPP_ +#include #include #include "../Result.hpp" +#include "Parser_base.hpp" #include "is_map_like.hpp" #include "is_set_like.hpp" diff --git a/include/rfl/parsing/ViewReaderWithDefault.hpp b/include/rfl/parsing/ViewReaderWithDefault.hpp index c498c620..a5a56563 100644 --- a/include/rfl/parsing/ViewReaderWithDefault.hpp +++ b/include/rfl/parsing/ViewReaderWithDefault.hpp @@ -8,9 +8,11 @@ #include #include +#include "../Ref.hpp" #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "Parser_base.hpp" namespace rfl::parsing { diff --git a/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp b/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp index e93018ee..697060ab 100644 --- a/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp +++ b/include/rfl/parsing/ViewReaderWithDefaultAndStrippedFieldNames.hpp @@ -1,6 +1,7 @@ #ifndef RFL_PARSING_VIEWREADERWITHDEFAULTANDSTRIPPEDFIELDNAMES_HPP_ #define RFL_PARSING_VIEWREADERWITHDEFAULTANDSTRIPPEDFIELDNAMES_HPP_ +#include #include #include #include @@ -9,6 +10,7 @@ #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "Parser_base.hpp" namespace rfl::parsing { diff --git a/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp b/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp index c4ab784d..5787a1e0 100644 --- a/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp +++ b/include/rfl/parsing/ViewReaderWithStrippedFieldNames.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_VIEWREADERWITHSTRIPPEDFIELDNAMES_HPP_ #include +#include #include #include #include @@ -10,6 +11,7 @@ #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "Parser_base.hpp" namespace rfl::parsing { diff --git a/include/rfl/parsing/is_required.hpp b/include/rfl/parsing/is_required.hpp index befa2545..bc4cb543 100644 --- a/include/rfl/parsing/is_required.hpp +++ b/include/rfl/parsing/is_required.hpp @@ -8,6 +8,7 @@ #include "../Generic.hpp" #include "../Rename.hpp" #include "../internal/StringLiteral.hpp" +#include "../internal/has_reflection_type_v.hpp" #include "../internal/is_rename.hpp" #include "is_map_like.hpp" #include "is_vector_like.hpp" diff --git a/include/rfl/parsing/schema/to_numeric_type.hpp b/include/rfl/parsing/schema/to_numeric_type.hpp deleted file mode 100644 index cb9e4d47..00000000 --- a/include/rfl/parsing/schema/to_numeric_type.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef RFL_PARSING_SCHEMA_TONUMERICTYPE_HPP_ -#define RFL_PARSING_SCHEMA_TONUMERICTYPE_HPP_ - -#include - -#include "../../always_false.hpp" -#include "Type.hpp" - -namespace rfl::parsing::schema { - -template -inline schema::Type::NumericType to_numeric_type() { - using U = std::remove_cvref_t; - - if constexpr (std::is_same()) { - return Type::NumericType(Type::Int32{}); - - } else if constexpr (std::is_same()) { - return Type::NumericType(Type::Int64{}); - - } else if constexpr (std::is_same()) { - return Type::NumericType(Type::UInt32{}); - - } else if constexpr (std::is_same()) { - return Type::NumericType(Type::UInt64{}); - - } else if constexpr (std::is_integral()) { - return Type::NumericType(Type::Integer{}); - - } else if constexpr (std::is_same()) { - return Type::NumericType(Type::Float{}); - - } else if constexpr (std::is_floating_point_v) { - return Type::NumericType(Type::Double{}); - - } else { - static_assert(always_false_v, "Not a numeric value."); - } -} - -} // namespace rfl::parsing::schema - -#endif diff --git a/include/rfl/parsing/schemaful/IsSchemafulReader.hpp b/include/rfl/parsing/schemaful/IsSchemafulReader.hpp index c78ae7bd..19ecdc8c 100644 --- a/include/rfl/parsing/schemaful/IsSchemafulReader.hpp +++ b/include/rfl/parsing/schemaful/IsSchemafulReader.hpp @@ -2,9 +2,12 @@ #define RFL_PARSING_SCHEMAFUL_ISSCHEMAFULREADER_HPP_ #include +#include #include #include +#include "../../Result.hpp" + namespace rfl::parsing::schemaful { using MockVariantType = std::variant; diff --git a/include/rfl/parsing/schemaful/OptionalReader.hpp b/include/rfl/parsing/schemaful/OptionalReader.hpp index 2753f614..6f423c54 100644 --- a/include/rfl/parsing/schemaful/OptionalReader.hpp +++ b/include/rfl/parsing/schemaful/OptionalReader.hpp @@ -5,6 +5,7 @@ #include #include "../../Result.hpp" +#include "../Parser_base.hpp" namespace rfl::parsing::schemaful { diff --git a/include/rfl/parsing/schemaful/SharedPtrReader.hpp b/include/rfl/parsing/schemaful/SharedPtrReader.hpp index baad5e53..154e5b52 100644 --- a/include/rfl/parsing/schemaful/SharedPtrReader.hpp +++ b/include/rfl/parsing/schemaful/SharedPtrReader.hpp @@ -5,6 +5,7 @@ #include #include "../../Result.hpp" +#include "../Parser_base.hpp" namespace rfl::parsing::schemaful { diff --git a/include/rfl/parsing/schemaful/UniquePtrReader.hpp b/include/rfl/parsing/schemaful/UniquePtrReader.hpp index 888cf634..b27fa23e 100644 --- a/include/rfl/parsing/schemaful/UniquePtrReader.hpp +++ b/include/rfl/parsing/schemaful/UniquePtrReader.hpp @@ -5,6 +5,7 @@ #include #include "../../Result.hpp" +#include "../Parser_base.hpp" namespace rfl::parsing::schemaful { diff --git a/include/rfl/parsing/schemaful/VariantReader.hpp b/include/rfl/parsing/schemaful/VariantReader.hpp index 00857f8e..5b6656e4 100644 --- a/include/rfl/parsing/schemaful/VariantReader.hpp +++ b/include/rfl/parsing/schemaful/VariantReader.hpp @@ -6,6 +6,7 @@ #include "../../Result.hpp" #include "../../internal/nth_element_t.hpp" +#include "../Parser_base.hpp" namespace rfl::parsing::schemaful { diff --git a/include/rfl/parsing/to_single_error_message.hpp b/include/rfl/parsing/to_single_error_message.hpp index e4669ac4..b56837b6 100644 --- a/include/rfl/parsing/to_single_error_message.hpp +++ b/include/rfl/parsing/to_single_error_message.hpp @@ -6,6 +6,7 @@ #include #include +#include "../Result.hpp" #include "../internal/strings/strings.hpp" namespace rfl::parsing { diff --git a/include/rfl/yaml/Reader.hpp b/include/rfl/yaml/Reader.hpp index e6c2cfd2..505339e2 100644 --- a/include/rfl/yaml/Reader.hpp +++ b/include/rfl/yaml/Reader.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include