AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
constraints.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 "anch-json-export.hpp"
23
24#include <cstdint>
25#include <string>
26#include <string_view>
27#include <vector>
28
29#include "val/constraints.hpp"
30
31namespace anch::json {
32
33 // Reader context early declaration
34 class ReaderContext;
35
36 // Writer context early declaration
37 class WriterContext;
38
39} // anch::json
40
41namespace anch::json::detail {
42
52 ANCH_JSON_EXPORT void checkRequired(const std::vector<std::string>& required, const uint64_t* found, anch::json::ReaderContext& context);
53
61 [[noreturn]] ANCH_JSON_EXPORT void rejectNull(anch::json::ReaderContext& context);
62
71 [[noreturn]] ANCH_JSON_EXPORT void violation(anch::json::ReaderContext& context, const std::string& message);
72
81 [[noreturn]] ANCH_JSON_EXPORT void violation(anch::json::WriterContext& context, const std::string& message);
82
95 template<typename P>
96 bool writeEmptyRequired(const std::string& key, const P& value, anch::json::WriterContext& context);
97
98} // anch::json::detail
99
100namespace anch::val {
101
106 template<>
108
116 static bool enabled(const anch::json::ReaderContext& context);
117
124 [[noreturn]] static void violation(anch::json::ReaderContext& context, const std::string& message);
125
133 template<typename F>
134 static void item(anch::json::ReaderContext& context, std::string_view key, F&& check);
135
143 template<typename F>
144 static void item(anch::json::ReaderContext& context, std::size_t index, F&& check);
145
146 };
147
152 template<>
154
162 static bool enabled(const anch::json::WriterContext& context);
163
170 [[noreturn]] static void violation(anch::json::WriterContext& context, const std::string& message);
171
179 template<typename F>
180 static void item(anch::json::WriterContext& context, std::string_view key, F&& check);
181
189 template<typename F>
190 static void item(anch::json::WriterContext& context, std::size_t index, F&& check);
191
192 };
193
194} // anch::val
195
196#include "json/impl/constraints.hpp"
JSON reader context.
Definition readerContext.hpp:44
JSON writer context.
Definition writerContext.hpp:45
JSON namespace.
Definition constants.hpp:27
AnCH validation library namespace.
Definition mapper.hpp:150
AnCH framework base namespace.
Definition app.hpp:30
static void item(anch::json::ReaderContext &context, std::size_t index, F &&check)
static void violation(anch::json::ReaderContext &context, const std::string &message)
static bool enabled(const anch::json::ReaderContext &context)
static void item(anch::json::ReaderContext &context, std::string_view key, F &&check)
static bool enabled(const anch::json::WriterContext &context)
static void item(anch::json::WriterContext &context, std::size_t index, F &&check)
static void violation(anch::json::WriterContext &context, const std::string &message)
static void item(anch::json::WriterContext &context, std::string_view key, F &&check)
Context in which constraints are checked.
Definition constraints.hpp:331