AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
validation.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2026 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <functional>
23#include <string>
24#include <vector>
25
26#include "mapping.hpp"
27
28#include "val/constraints.hpp"
29
30namespace anch::val::detail {
31
39 template<typename P>
40 constexpr bool validatable();
41
42}
43
44namespace anch::val {
45
60 template<typename T>
62
63 // Attributes +
64 private:
66 std::vector<std::function<void(const T&, anch::val::ValidationContext&)>> _validators;
67 // Attributes -
68
69 // Constructors +
70 public:
75 // Constructors -
76
77 // Methods +
78 public:
85
92 void validate(const T& value, anch::val::ValidationContext& context) const;
93
103 template<typename P, typename... C>
104 ValidationMapper<T>& registerField(const std::string& name, P T::* member, C&&... constraints);
105
115 template<typename P, typename... C>
116 ValidationMapper<T>& registerField(const std::string& name, std::function<P(const T&)> getter, C&&... constraints);
117
127 template<typename P, typename... C>
128 ValidationMapper<T>& registerField(const std::string& name, std::function<void(T&, const P&)> setter, C&&... constraints);
129
140 template<typename P, typename... C>
141 ValidationMapper<T>& registerField(const std::string& name, std::function<P(const T&)> getter,
142 std::function<void(T&, const P&)> setter, C&&... constraints);
143
144 private:
152 template<typename G, typename... C>
153 void add(const std::string& name, G get, C&&... constraints);
154 // Methods -
155
156 };
157
169 template<typename T>
170 concept Validatable = anch::val::detail::validatable<T>();
171
186 template<typename T>
187 std::vector<anch::val::Violation> validate(const T& value);
188
200 template<typename T>
201 bool isValid(const T& value);
202
203}
204
205#include "val/impl/validation.hpp"
Validation context.
Definition constraints.hpp:146
ValidationMapper< T > & registerField(const std::string &name, std::function< P(const T &)> getter, C &&... constraints)
ValidationMapper< T > & registerField(const std::string &name, std::function< void(T &, const P &)> setter, C &&... constraints)
ValidationMapper< T > & registerField(const std::string &name, std::function< P(const T &)> getter, std::function< void(T &, const P &)> setter, C &&... constraints)
void validate(const T &value, anch::val::ValidationContext &context) const
ValidationMapper< T > & registerField(const std::string &name, P T::*member, C &&... constraints)
static const ValidationMapper< T > & instance()
Type which can be validated: scalar ( anch::val::IsScalar ), described object ( anch::Mapping ),...
Definition validation.hpp:170
AnCH validation library namespace.
Definition mapper.hpp:150
std::vector< anch::val::Violation > validate(const T &value)
bool isValid(const T &value)