Make sure that the headers are self-contained; fixes #528 (#531)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-10-25 13:03:12 +02:00
committed by GitHub
parent 72a721404f
commit d0f60b214f
59 changed files with 272 additions and 227 deletions
+4 -2
View File
@@ -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
+3 -5
View File
@@ -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
+8 -2
View File
@@ -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
+56 -30
View File
@@ -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 $<IF:$<TARGET_EXISTS:mongo::bson_static>,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")
+4 -3
View File
@@ -2,6 +2,7 @@
#define RFL_INTERNAL_PROCESSORS_HPP_
#include <type_traits>
#include <utility>
#include "internal/is_add_tags_to_variants_v.hpp"
#include "internal/is_allow_raw_ptrs_v.hpp"
@@ -69,9 +70,9 @@ struct Processors<Head, Tail...> {
template <class T, class NamedTupleType>
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<Tail...>::template process<T>(
Head::template process<T>(std::move(_named_tuple)));
}
+1
View File
@@ -7,6 +7,7 @@
#include <stdexcept>
#include <string>
#include "Literal.hpp"
#include "Result.hpp"
#include "internal/StringLiteral.hpp"
+3 -5
View File
@@ -2,6 +2,7 @@
#define RFL_TUPLE_HPP_
#include <array>
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <utility>
@@ -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 <int... _is>
void move_from_other(Tuple&& _other,
std::integer_sequence<int, _is...>) {
void move_from_other(Tuple&& _other, std::integer_sequence<int, _is...>) {
const auto move_one = [this]<int _i>(auto&& _other,
std::integral_constant<int, _i>) {
using Type = internal::nth_element_t<_i, Types...>;
+3 -1
View File
@@ -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"
+1 -2
View File
@@ -5,8 +5,7 @@
#include <string>
//#include "../Box.hpp"
//#include "../Result.hpp"
#include "../Box.hpp"
#include "../common.hpp"
namespace rfl::avro {
+48 -24
View File
@@ -1,21 +1,22 @@
#ifndef RFL_AVRO_WRITER_HPP_
#define RFL_AVRO_WRITER_HPP_
#include <avro.h>
#include <climits>
#include <cstdint>
#include <string>
#include <string_view>
#include <type_traits>
#include <avro.h>
//#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<int>(_index), &new_value);
int result = avro_value_set_branch(&_parent->val_, static_cast<int>(_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 <class T>
void set_value(const T& _var, avro_value_t* _val) const {
if constexpr (std::is_same<std::remove_cvref_t<T>, 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<std::remove_cvref_t<T>,
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<std::remove_cvref_t<T>, 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<std::remove_cvref_t<T>>()) {
/*int result = avro_value_set_double(_val, static_cast<double>(_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<double>(_var));
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
/*int result = avro_value_set_long(_val, static_cast<std::int64_t>(_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<std::int64_t>(_var));
} else if constexpr (internal::is_literal_v<T>) {
int result = avro_value_set_enum(_val, static_cast<int>(_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<T>) {
using ValueType = std::remove_cvref_t<typename T::ReflectionType>;
const auto val = _var.value();
set_value<ValueType>(val, _val);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Timestamp<"%Y-%m-%d">>()) {
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Timestamp<"%Y-%m-%d">>()) {
const auto str = _var.to_string();
set_value<std::string>(str, _val);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Email>()) {
+3 -2
View File
@@ -3,7 +3,8 @@
#include <bson/bson.h>
//#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 <class R, class W, class ProcessorsType>
requires AreReaderAndWriter<R, W, bson_oid_t>
requires AreReaderAndWriter<R, W, bson_oid_t>
struct Parser<R, W, ProcessorsType, bson_oid_t> {
using InputVarType = typename R::InputVarType;
+5 -8
View File
@@ -9,12 +9,11 @@
#include <string>
#include <type_traits>
//#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<T>;
using ValueType = typename VectorType::value_type;
if (btype != BSON_TYPE_BINARY) {
if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, 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<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Bytestring>()) {
return error(
"The BSON subtype must be a binary in order to read into a "
"bytestring.");
+3 -2
View File
@@ -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"
+3 -3
View File
@@ -4,6 +4,7 @@
#include <capnp/dynamic.h>
#include <exception>
#include <optional>
#include <string>
#include <type_traits>
@@ -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<T>;
using ValueType = typename VectorType::value_type;
if (type != capnp::DynamicValue::DATA) {
if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Bytestring>()) {
return error("Could not cast to bytestring.");
} else {
return error("Could not cast to vectorstring.");
+1 -2
View File
@@ -5,8 +5,7 @@
#include <string>
//#include "../Box.hpp"
//#include "../Result.hpp"
#include "../Box.hpp"
#include "../common.hpp"
namespace rfl::capnproto {
+2
View File
@@ -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) {
@@ -3,6 +3,7 @@
#include <map>
#include "../../internal/strings/strings.hpp"
#include "Type.hpp"
namespace rfl::capnproto::schema {
+10 -10
View File
@@ -3,20 +3,20 @@
#include <string>
//#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 {
+1 -2
View File
@@ -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"
+5 -5
View File
@@ -9,11 +9,12 @@
#include <string_view>
#include <type_traits>
//#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<T>;
using ValueType = typename VectorType::value_type;
if (!_var.IsBlob()) {
if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Bytestring>()) {
return error("Could not cast to bytestring.");
} else {
return error("Could not cast to vectorstring.");
+11 -12
View File
@@ -9,8 +9,7 @@
#include <type_traits>
#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 <class T>
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 <class T>
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);
}
+2 -1
View File
@@ -1,6 +1,7 @@
#ifndef RFL_INTERNAL_ARRAY_HPP_
#define RFL_INTERNAL_ARRAY_HPP_
#include <cstddef>
#include <type_traits>
#include "to_std_array.hpp"
@@ -9,7 +10,7 @@ namespace rfl {
namespace internal {
template <class T>
requires std::is_array_v<T>
requires std::is_array_v<T>
struct Array {
using Type = T;
using StdArrayType = to_std_array_t<T>;
+3
View File
@@ -2,6 +2,9 @@
#define RFL_INTERNAL_SKIP_HPP_
#include <optional>
#include <type_traits>
#include "../default.hpp"
namespace rfl::internal {
+1
View File
@@ -1,6 +1,7 @@
#ifndef RFL_FIND_INDEX_HPP_
#define RFL_FIND_INDEX_HPP_
#include "../Tuple.hpp"
#include "StringLiteral.hpp"
namespace rfl {
+1 -1
View File
@@ -3,7 +3,7 @@
#include <type_traits>
//#include "../parsing/Parser.hpp"
#include "../parsing/Parser.hpp"
namespace rfl::internal {
@@ -3,7 +3,7 @@
#include <type_traits>
//#include "../AddTagsToVariants.hpp"
#include "../AddTagsToVariants.hpp"
namespace rfl ::internal {
@@ -27,12 +27,13 @@ template <class T>
class is_add_namespaced_tags_to_variants : public std::false_type {};
template <>
class is_add_namespaced_tags_to_variants<AddNamespacedTagsToVariants> : public std::true_type {};
class is_add_namespaced_tags_to_variants<AddNamespacedTagsToVariants>
: public std::true_type {};
template <class T>
constexpr bool is_add_namespaced_tags_to_variants_v = is_add_namespaced_tags_to_variants<
std::remove_cvref_t<std::remove_pointer_t<T>>>::value;
constexpr bool is_add_namespaced_tags_to_variants_v =
is_add_namespaced_tags_to_variants<
std::remove_cvref_t<std::remove_pointer_t<T>>>::value;
} // namespace rfl::internal
@@ -3,10 +3,9 @@
#include <type_traits>
//#include "../DefaultIfMissing.hpp"
#include "../DefaultIfMissing.hpp"
namespace rfl {
namespace internal {
namespace rfl::internal {
template <class T>
class is_default_if_missing;
@@ -21,7 +20,6 @@ template <class T>
constexpr bool is_default_if_missing_v =
is_default_if_missing<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;
} // namespace internal
} // namespace rfl
} // namespace rfl::internal
#endif
+1
View File
@@ -5,6 +5,7 @@
#include "../Tuple.hpp"
#include "is_named_tuple.hpp"
#include "ptr_tuple_t.hpp"
namespace rfl::internal {
+3 -5
View File
@@ -3,10 +3,9 @@
#include <type_traits>
//#include "../NoFieldNames.hpp"
#include "../NoFieldNames.hpp"
namespace rfl {
namespace internal {
namespace rfl::internal {
template <class T>
class is_no_field_names;
@@ -21,7 +20,6 @@ template <class T>
constexpr bool is_no_field_names_v =
is_no_field_names<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;
} // namespace internal
} // namespace rfl
} // namespace rfl::internal
#endif
+1
View File
@@ -4,6 +4,7 @@
#include <type_traits>
#include "../Field.hpp"
#include "../NamedTuple.hpp"
#include "StringLiteral.hpp"
#include "wrap_in_rfl_array_t.hpp"
+1
View File
@@ -2,6 +2,7 @@
#define RFL_INTERNAL_TO_STD_ARRAY_HPP_
#include <array>
#include <cstddef>
#include <type_traits>
namespace rfl::internal {
+1
View File
@@ -3,6 +3,7 @@
#include <type_traits>
#include "../Field.hpp"
#include "../Tuple.hpp"
#include "flattened_ptr_tuple_t.hpp"
#include "is_flatten_field.hpp"
+1
View File
@@ -8,6 +8,7 @@
#endif
#include <exception>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
+1
View File
@@ -7,6 +7,7 @@
#include "../../Literal.hpp"
#include "../../Object.hpp"
#include "../../Ref.hpp"
#include "../../Rename.hpp"
#include "../../Variant.hpp"
+4 -3
View File
@@ -5,14 +5,15 @@
#include <cstddef>
#include <exception>
#include <optional>
#include <string>
#include <string_view>
//#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 {
+14 -14
View File
@@ -3,14 +3,13 @@
#include <msgpack.h>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
//#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 <class T>
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 <class T>
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<Type, std::string>()) {
msgpack_pack_str(pk_, _var.size());
msgpack_pack_str_body(pk_, _var.c_str(), _var.size());
} else if constexpr (std::is_same<Type, rfl::Bytestring>() || std::is_same<Type, rfl::Vectorstring>()) {
} else if constexpr (std::is_same<Type, rfl::Bytestring>() ||
std::is_same<Type, rfl::Vectorstring>()) {
msgpack_pack_bin(pk_, _var.size());
msgpack_pack_bin_body(pk_, _var.data(), _var.size());
} else if constexpr (std::is_same<Type, bool>()) {
@@ -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 {
+4 -1
View File
@@ -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<std::pair<KeyType, ValueType>> make_key(auto&& _pair) const noexcept {
static_assert(std::is_rvalue_reference_v<decltype(_pair)>, "Expected an rvalue");
static_assert(std::is_rvalue_reference_v<decltype(_pair)>,
"Expected an rvalue");
const auto to_pair =
[&](auto&& _key) -> Result<std::pair<KeyType, ValueType>> {
try {
@@ -5,6 +5,7 @@
#include "../Bytestring.hpp"
#include "../Result.hpp"
#include "Parent.hpp"
#include "Parser_base.hpp"
#include "schema/Type.hpp"
+1
View File
@@ -2,6 +2,7 @@
#define RFL_PARSING_PARSER_FILEPATH_HPP_
#include <filesystem>
#include <map>
#include "../Result.hpp"
#include "Parser_base.hpp"
+3 -13
View File
@@ -4,9 +4,12 @@
#include <map>
#include <type_traits>
#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<R, W, Result<T>, ProcessorsType> {
template <class P>
static void write(const W& _w, const Result<T>& _r,
const P& _parent) noexcept {
// const auto write_t = [&](const auto& _t) -> Nothing {
// Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(_w, _t,
// _parent);
// return Nothing{};
// };
// const auto write_err = [&](const auto& _err) -> Nothing {
// Parser<R, W, ErrorType, ProcessorsType>::write(
// _w, ErrorType(make_field<"error">(_err.what())), _parent);
// return Nothing{};
// };
if (_r) {
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(
_w, _r.value(), _parent);
@@ -62,8 +54,6 @@ struct Parser<R, W, Result<T>, ProcessorsType> {
Parser<R, W, ErrorType, ProcessorsType>::write(
_w, ErrorType(make_field<"error">(_r.error().what())), _parent);
}
// _r.transform(write_t).transform_error(write_err);
}
static schema::Type to_schema(
+12 -9
View File
@@ -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<R, W, rfl::Variant<AlternativeTypes...>, ProcessorsType> {
return _r.template read_union<Variant<AlternativeTypes...>, 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<VariantAlternativeWrapper<AlternativeTypes, remove_namespaces>...>;
using FieldVariantType = rfl::Variant<
VariantAlternativeWrapper<AlternativeTypes, remove_namespaces>...>;
const auto from_field_variant =
[](auto&& _field) -> rfl::Variant<AlternativeTypes...> {
return std::move(_field.value());
@@ -121,11 +123,12 @@ class Parser<R, W, rfl::Variant<AlternativeTypes...>, 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<VariantAlternativeWrapper<const AlternativeTypes*, remove_namespaces>...>;
rfl::Variant<VariantAlternativeWrapper<const AlternativeTypes*,
remove_namespaces>...>;
const auto to_field_variant =
[]<class T>(const T& _t) -> FieldVariantType {
return VariantAlternativeWrapper<const T*, remove_namespaces>(&_t);
@@ -148,11 +151,11 @@ class Parser<R, W, rfl::Variant<AlternativeTypes...>, ProcessorsType> {
return FieldVariantParser<R, W, ProcessorsType,
AlternativeTypes...>::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<VariantAlternativeWrapper<AlternativeTypes, remove_namespaces>...>;
using FieldVariantType = rfl::Variant<
VariantAlternativeWrapper<AlternativeTypes, remove_namespaces>...>;
return Parser<R, W, FieldVariantType, ProcessorsType>::to_schema(
_definitions);
+6 -5
View File
@@ -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<R, W, TaggedUnion<_discriminator, AlternativeTypes...>,
using T = tagged_union_wrapper_no_ptr_t<std::invoke_result_t<
decltype(wrap_if_necessary<AlternativeType>), AlternativeType>>;
*_result = Parser<R, W, T, ProcessorsType>::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<R, W, AlternativeType, ProcessorsType>::read(_r, _var)
.transform(to_tagged_union)
.transform_error(embellish_error);
.transform(to_tagged_union)
.transform_error(embellish_error);
}
*_match_found = true;
+3 -2
View File
@@ -3,8 +3,9 @@
#include <map>
#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<R, W, Vectorstring, ProcessorsType> {
using ParentType = Parent<W>;
static Result<Vectorstring> read(const R& _r,
const InputVarType& _var) noexcept {
const InputVarType& _var) noexcept {
return _r.template to_basic_type<Vectorstring>(_var);
}
@@ -3,6 +3,7 @@
#include <type_traits>
#include "../Field.hpp"
#include "../Flatten.hpp"
#include "../Rename.hpp"
#include "../internal/StringLiteral.hpp"
+3
View File
@@ -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 {
+2
View File
@@ -1,9 +1,11 @@
#ifndef RFL_PARSING_VECTORREADER_HPP_
#define RFL_PARSING_VECTORREADER_HPP_
#include <optional>
#include <type_traits>
#include "../Result.hpp"
#include "Parser_base.hpp"
#include "is_map_like.hpp"
#include "is_set_like.hpp"
@@ -8,9 +8,11 @@
#include <utility>
#include <vector>
#include "../Ref.hpp"
#include "../Result.hpp"
#include "../Tuple.hpp"
#include "../internal/is_array.hpp"
#include "Parser_base.hpp"
namespace rfl::parsing {
@@ -1,6 +1,7 @@
#ifndef RFL_PARSING_VIEWREADERWITHDEFAULTANDSTRIPPEDFIELDNAMES_HPP_
#define RFL_PARSING_VIEWREADERWITHDEFAULTANDSTRIPPEDFIELDNAMES_HPP_
#include <optional>
#include <sstream>
#include <type_traits>
#include <utility>
@@ -9,6 +10,7 @@
#include "../Result.hpp"
#include "../Tuple.hpp"
#include "../internal/is_array.hpp"
#include "Parser_base.hpp"
namespace rfl::parsing {
@@ -2,6 +2,7 @@
#define RFL_PARSING_VIEWREADERWITHSTRIPPEDFIELDNAMES_HPP_
#include <array>
#include <optional>
#include <sstream>
#include <type_traits>
#include <utility>
@@ -10,6 +11,7 @@
#include "../Result.hpp"
#include "../Tuple.hpp"
#include "../internal/is_array.hpp"
#include "Parser_base.hpp"
namespace rfl::parsing {
+1
View File
@@ -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"
@@ -1,43 +0,0 @@
#ifndef RFL_PARSING_SCHEMA_TONUMERICTYPE_HPP_
#define RFL_PARSING_SCHEMA_TONUMERICTYPE_HPP_
#include <type_traits>
#include "../../always_false.hpp"
#include "Type.hpp"
namespace rfl::parsing::schema {
template <class T>
inline schema::Type::NumericType to_numeric_type() {
using U = std::remove_cvref_t<T>;
if constexpr (std::is_same<U, std::int32_t>()) {
return Type::NumericType(Type::Int32{});
} else if constexpr (std::is_same<U, std::int64_t>()) {
return Type::NumericType(Type::Int64{});
} else if constexpr (std::is_same<U, std::uint32_t>()) {
return Type::NumericType(Type::UInt32{});
} else if constexpr (std::is_same<U, std::uint64_t>()) {
return Type::NumericType(Type::UInt64{});
} else if constexpr (std::is_integral<U>()) {
return Type::NumericType(Type::Integer{});
} else if constexpr (std::is_same<U, float>()) {
return Type::NumericType(Type::Float{});
} else if constexpr (std::is_floating_point_v<U>) {
return Type::NumericType(Type::Double{});
} else {
static_assert(always_false_v<U>, "Not a numeric value.");
}
}
} // namespace rfl::parsing::schema
#endif
@@ -2,9 +2,12 @@
#define RFL_PARSING_SCHEMAFUL_ISSCHEMAFULREADER_HPP_
#include <concepts>
#include <optional>
#include <string>
#include <variant>
#include "../../Result.hpp"
namespace rfl::parsing::schemaful {
using MockVariantType = std::variant<std::string, int>;
@@ -5,6 +5,7 @@
#include <type_traits>
#include "../../Result.hpp"
#include "../Parser_base.hpp"
namespace rfl::parsing::schemaful {
@@ -5,6 +5,7 @@
#include <type_traits>
#include "../../Result.hpp"
#include "../Parser_base.hpp"
namespace rfl::parsing::schemaful {
@@ -5,6 +5,7 @@
#include <type_traits>
#include "../../Result.hpp"
#include "../Parser_base.hpp"
namespace rfl::parsing::schemaful {
@@ -6,6 +6,7 @@
#include "../../Result.hpp"
#include "../../internal/nth_element_t.hpp"
#include "../Parser_base.hpp"
namespace rfl::parsing::schemaful {
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include "../Result.hpp"
#include "../internal/strings/strings.hpp"
namespace rfl::parsing {
+1
View File
@@ -7,6 +7,7 @@
#include <exception>
#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>