Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Concepts.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "rpc/Errors.hpp"
23#include "rpc/common/Checkers.hpp"
24#include "rpc/common/Types.hpp"
25
26#include <boost/json/value.hpp>
27#include <boost/json/value_from.hpp>
28#include <boost/json/value_to.hpp>
29
30#include <cstdint>
31#include <optional>
32#include <string>
33
34namespace rpc {
35
36struct RpcSpec;
37
41template <typename T>
42concept SomeRequirement = requires(T a, boost::json::value lval) {
43 { a.verify(lval, std::string{}) } -> std::same_as<MaybeError>;
44};
45
49template <typename T>
50concept SomeModifier = requires(T a, boost::json::value lval) {
51 { a.modify(lval, std::string{}) } -> std::same_as<MaybeError>;
52};
53
57template <typename T>
58concept SomeCheck = requires(T a, boost::json::value lval) {
59 { a.check(lval, std::string{}) } -> std::same_as<std::optional<check::Warning>>;
60};
61
65template <typename T>
67
71template <typename T>
72concept SomeContextProcessWithInput = requires(T a, typename T::Input in, typename T::Output out, Context const& ctx) {
73 { a.process(in, ctx) } -> std::same_as<HandlerReturnType<decltype(out)>>;
74};
75
79template <typename T>
80concept SomeContextProcessWithoutInput = requires(T a, typename T::Output out, Context const& ctx) {
81 { a.process(ctx) } -> std::same_as<HandlerReturnType<decltype(out)>>;
82};
83
87template <typename T>
88concept SomeHandlerWithInput = requires(T a, uint32_t version) {
89 { a.spec(version) } -> std::same_as<RpcSpec const&>;
90} and SomeContextProcessWithInput<T> and boost::json::has_value_to<typename T::Input>::value;
91
95template <typename T>
97
101template <typename T>
102concept SomeHandler =
103 (SomeHandlerWithInput<T> or SomeHandlerWithoutInput<T>) and boost::json::has_value_from<typename T::Output>::value;
104
105} // namespace rpc
Specifies what a check used with rpc::FieldSpec must provide.
Definition Concepts.hpp:58
A process function that expects both some Input and a Context.
Definition Concepts.hpp:72
A process function that expects no Input but does take a Context.
Definition Concepts.hpp:80
Specifies what a Handler with Input must provide.
Definition Concepts.hpp:88
Specifies what a Handler without Input must provide.
Definition Concepts.hpp:96
Specifies what a Handler type must provide.
Definition Concepts.hpp:102
Specifies what a modifier used with rpc::FieldSpec must provide.
Definition Concepts.hpp:50
The requirements of a processor to be used with rpc::FieldSpec.
Definition Concepts.hpp:66
Specifies what a requirement used with rpc::FieldSpec must provide.
Definition Concepts.hpp:42
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:37
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81