Crunch
A Message Definition Language for Getting Things Right
Loading...
Searching...
No Matches
Crunch::fields::Scalar< ScalarType, Validators > Class Template Reference

A validated, typed message field. More...

#include <crunch_scalar.hpp>

Public Types

using ValueType = ScalarType
 

Public Member Functions

constexpr Scalar (ScalarType v)
 
constexpr std::optional< Errorset (ScalarType v) noexcept
 
constexpr void set_without_validation (ScalarType v) noexcept
 
constexpr ScalarType get () const noexcept
 
constexpr void clear () noexcept
 
constexpr bool operator== (const Scalar &other) const noexcept
 Checks if two fields are equal.
 
constexpr auto Validate () const noexcept -> std::optional< Error >
 Validates the current value of the field against all validators.
 

Static Public Member Functions

static constexpr auto Validate (ScalarType v, FieldId id=0) noexcept -> std::optional< Error >
 Validates a value against all validators without setting it.
 

Detailed Description

template<class ScalarType, typename... Validators>
requires (Validator<Validators, ScalarType> && ...) && (sizeof...(Validators) > 0) && std::regular<ScalarType>
class Crunch::fields::Scalar< ScalarType, Validators >

A validated, typed message field.

Wraps a primitive, fixed-size type with validation and presence logic.

Template Parameters
ScalarTypeThe underlying primitive type (e.g., int32_t). Must satisfy std::regular.
ValidatorsOne or more validators to enforce value constraints. Each must satisfy Validator<V, ScalarType>. At least one validator is required (use None for no validation).

Member Function Documentation

◆ Validate() [1/2]

template<class ScalarType , typename... Validators>
constexpr auto Crunch::fields::Scalar< ScalarType, Validators >::Validate ( ) const -> std::optional<Error>
inlineconstexprnoexcept

Validates the current value of the field against all validators.

Returns
std::nullopt on success, or a validation Error.

◆ Validate() [2/2]

template<class ScalarType , typename... Validators>
static constexpr auto Crunch::fields::Scalar< ScalarType, Validators >::Validate ( ScalarType  v,
FieldId  id = 0 
) -> std::optional<Error>
inlinestaticconstexprnoexcept

Validates a value against all validators without setting it.

Parameters
vThe value to validate.
idThe FieldId for this field within its message. Unused for aggregate fields.
Returns
std::nullopt on success, or a validation Error.

The documentation for this class was generated from the following file: