AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
mapping.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 <concepts>
23#include <functional>
24#include <string>
25#include <type_traits>
26
27namespace anch {
28
52 template<typename T>
53 struct Mapping {
55 using Undescribed = void;
56 };
57
65 template<typename T>
66 concept Described = !requires { typename anch::Mapping<T>::Undescribed; };
67
87 template<typename M, typename T>
88 concept ObjectMapper = std::is_class_v<T>
89 && requires(M& mapper, const std::string& name, int T::* member, std::function<int(const T&)> getter,
90 std::function<void(T&, const int&)> setter) {
91 { mapper.registerField(name, member) } -> std::same_as<M&>;
92 { mapper.registerField(name, getter) } -> std::same_as<M&>;
93 { mapper.registerField(name, setter) } -> std::same_as<M&>;
94 { mapper.registerField(name, getter, setter) } -> std::same_as<M&>;
95 };
96
107 template<anch::Described T, anch::ObjectMapper<T> M>
108 void describe(M& mapper);
109
110}
111
112#include "impl/mapping.hpp"
Type described by an anch::Mapping specialization.
Definition mapping.hpp:66
Mapper of a format on which anch::Mapping registers the fields of T.
Definition mapping.hpp:88
AnCH framework base namespace.
Definition app.hpp:30
void describe(M &mapper)
Description of an object for every format (anch-json, ...).
Definition mapping.hpp:53
void Undescribed
Definition mapping.hpp:55