4#include <crunch/validators/crunch_validators.hpp>
8namespace Crunch::fields {
21template <
class ScalarType,
typename... Validators>
22 requires(Validator<Validators, ScalarType> && ...) &&
23 (
sizeof...(Validators) > 0) && std::regular<ScalarType>
26 using ValueType = ScalarType;
28 constexpr Scalar() =
default;
33 constexpr Scalar(ScalarType v) : value_(v) {}
35 constexpr std::optional<Error> set(ScalarType v)
noexcept {
43 constexpr void set_without_validation(ScalarType v)
noexcept { value_ = v; }
45 [[nodiscard]]
constexpr ScalarType get()
const noexcept {
return value_; }
47 constexpr void clear()
noexcept { value_ = {}; }
53 const Scalar& other)
const noexcept {
54 return value_ == other.value_;
62 [[nodiscard]]
constexpr auto Validate() const noexcept
63 -> std::optional<
Error> {
75 [[nodiscard]]
static constexpr auto Validate(ScalarType v,
77 -> std::optional<
Error> {
78 for (
const auto& result : {Validators::Check(v,
id)...}) {
79 if (result.has_value()) {
93template <
class ScalarType,
typename... Validators>
99template <
typename... Validators>
102template <
typename... Validators>
105template <
typename... Validators>
108template <
typename... Validators>
111template <
typename... Validators>
114template <
typename... Validators>
117template <
typename... Validators>
120template <
typename... Validators>
123template <
typename... Validators>
A validated, typed message field.
Definition: crunch_scalar.hpp:24
static constexpr auto Validate(ScalarType v, FieldId id=0) noexcept -> std::optional< Error >
Validates a value against all validators without setting it.
Definition: crunch_scalar.hpp:75
constexpr bool operator==(const Scalar &other) const noexcept
Checks if two fields are equal.
Definition: crunch_scalar.hpp:52
constexpr auto Validate() const noexcept -> std::optional< Error >
Validates the current value of the field against all validators.
Definition: crunch_scalar.hpp:62
int32_t FieldId
Unique identifier for a field within a Crunch message.
Definition: crunch_types.hpp:11
Represents an error occurred during Crunch operations.
Definition: crunch_types.hpp:75
Definition: crunch_scalar.hpp:91