分离 json magic_enum 依赖
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "adminive/adapter.hpp"
|
||||
#include <concepts>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
namespace adminive {
|
||||
@@ -85,4 +87,38 @@ template <class T, class Validator>
|
||||
struct Unwrapped_Value<Validated_Value<T, Validator>> : Unwrapped_Value<T> {};
|
||||
template <class T>
|
||||
using Unwrapped_Value_Type = typename Unwrapped_Value<std::remove_cvref_t<T>>::type;
|
||||
template <class T, T Minimum, T Maximum, class Json>
|
||||
struct Value_Adapter<Range_Value<T, Minimum, Maximum>, Json> {
|
||||
using value_type = T;
|
||||
static constexpr T minimum = Minimum;
|
||||
static constexpr T maximum = Maximum;
|
||||
static const T& read(const Range_Value<T, Minimum, Maximum>& value) noexcept {
|
||||
return value.value();
|
||||
}
|
||||
static void write(Range_Value<T, Minimum, Maximum>& target, T value) {
|
||||
target = value;
|
||||
}
|
||||
};
|
||||
template <class Validator, class = void>
|
||||
struct Validator_Multiple_Of_Metadata {};
|
||||
template <class Validator>
|
||||
struct Validator_Multiple_Of_Metadata<Validator, std::void_t<decltype(Validator::multiple_of)>> {
|
||||
static constexpr auto multiple_of = Validator::multiple_of;
|
||||
};
|
||||
template <class Validator, class = void>
|
||||
struct Validator_Message_Metadata {};
|
||||
template <class Validator>
|
||||
struct Validator_Message_Metadata<Validator, std::void_t<decltype(Validator::message)>> {
|
||||
static constexpr std::string_view validation_message = Validator::message;
|
||||
};
|
||||
template <class T, class Validator, class Json>
|
||||
struct Value_Adapter<Validated_Value<T, Validator>, Json> : Validator_Multiple_Of_Metadata<Validator>, Validator_Message_Metadata<Validator> {
|
||||
using value_type = T;
|
||||
static const T& read(const Validated_Value<T, Validator>& value) noexcept {
|
||||
return value.value();
|
||||
}
|
||||
static void write(Validated_Value<T, Validator>& target, T value) {
|
||||
target = value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user