AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
formMapper.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 <optional>
23#include <string_view>
24#include <vector>
25
26#include "codec/codec.hpp"
27
28#include "rest/form.hpp"
29#include "rest/paramConverter.hpp"
30
31namespace anch::rest {
32
48 template<typename T>
49 struct FormMapper;
50
58 template<typename T>
59 concept FormMapped = requires(const T& value, T& target, anch::rest::Form& form, const anch::rest::Form& source,
60 anch::codec::Side side) {
61 anch::rest::FormMapper<T>::toForm(value, form, side);
62 anch::rest::FormMapper<T>::fromForm(target, source, side);
63 };
64
74 template<anch::rest::ParameterValue T>
75 void addFormField(anch::rest::Form& form, std::string_view name, const T& value);
76
86 template<anch::rest::ParameterValue T>
87 void addFormField(anch::rest::Form& form, std::string_view name, const std::optional<T>& value);
88
98 template<anch::rest::ParameterValue T>
99 void addFormField(anch::rest::Form& form, std::string_view name, const std::vector<T>& values);
100
110 void addFormFile(anch::rest::Form& form, std::string_view name, const anch::rest::Part& part);
111
121 void addFormFile(anch::rest::Form& form, std::string_view name, const std::optional<anch::rest::Part>& part);
122
132 void addFormFile(anch::rest::Form& form, std::string_view name, const std::vector<anch::rest::Part>& parts);
133
145 template<typename T>
146 void addJsonFormField(anch::rest::Form& form, std::string_view name, const T& value, anch::codec::Side side);
147
160 template<anch::rest::PathParameter T>
161 std::vector<T> formFields(const anch::rest::Form& form, std::string_view name);
162
173 std::optional<anch::rest::Part> formFile(const anch::rest::Form& form, std::string_view name);
174
187 anch::rest::Part requiredFormFile(const anch::rest::Form& form, std::string_view name);
188
199 std::vector<anch::rest::Part> formFiles(const anch::rest::Form& form, std::string_view name);
200
215 template<typename T>
216 std::optional<T> jsonFormField(const anch::rest::Form& form, std::string_view name, anch::codec::Side side);
217
233 template<typename T>
234 T requiredJsonFormField(const anch::rest::Form& form, std::string_view name, anch::codec::Side side);
235
248 template<typename T>
249 void checkFormConstraints(const T& value, anch::codec::Side side);
250
251}
252
253#include "rest/impl/formMapper.hpp"
Definition form.hpp:287
Definition form.hpp:79
Definition formMapper.hpp:59
Side
Definition codec.hpp:48
AnCH REST library namespace.
Definition auth.hpp:29
void addFormField(anch::rest::Form &form, std::string_view name, const T &value)
void addJsonFormField(anch::rest::Form &form, std::string_view name, const T &value, anch::codec::Side side)
anch::rest::Part requiredFormFile(const anch::rest::Form &form, std::string_view name)
std::vector< anch::rest::Part > formFiles(const anch::rest::Form &form, std::string_view name)
void addFormFile(anch::rest::Form &form, std::string_view name, const anch::rest::Part &part)
std::vector< T > formFields(const anch::rest::Form &form, std::string_view name)
std::optional< anch::rest::Part > formFile(const anch::rest::Form &form, std::string_view name)
void checkFormConstraints(const T &value, anch::codec::Side side)
T requiredJsonFormField(const anch::rest::Form &form, std::string_view name, anch::codec::Side side)
std::optional< T > jsonFormField(const anch::rest::Form &form, std::string_view name, anch::codec::Side side)
Definition formMapper.hpp:49