rippled
Loading...
Searching...
No Matches
ApiVersion.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2023 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#ifndef RIPPLE_PROTOCOL_APIVERSION_H_INCLUDED
21#define RIPPLE_PROTOCOL_APIVERSION_H_INCLUDED
22
23#include <functional>
24#include <type_traits>
25#include <utility>
26
27namespace ripple {
28
51namespace RPC {
52
53template <unsigned int Version>
55
56constexpr static auto apiInvalidVersion = apiVersion<0>;
57constexpr static auto apiMinimumSupportedVersion = apiVersion<1>;
58constexpr static auto apiMaximumSupportedVersion = apiVersion<2>;
59constexpr static auto apiVersionIfUnspecified = apiVersion<1>;
60constexpr static auto apiCommandLineVersion =
61 apiVersion<1>; // TODO Bump to 2 later
62constexpr static auto apiBetaVersion = apiVersion<3>;
63constexpr static auto apiMaximumValidVersion = apiBetaVersion;
64
66static_assert(
69static_assert(
75
76} // namespace RPC
77
78template <unsigned minVer, unsigned maxVer, typename Fn, typename... Args>
79void
80forApiVersions(Fn const& fn, Args&&... args)
81 requires //
82 (maxVer >= minVer) && //
83 (minVer >= RPC::apiMinimumSupportedVersion) && //
84 (RPC::apiMaximumValidVersion >= maxVer) && requires {
86 std::forward<Args>(args)...);
88 std::forward<Args>(args)...);
89 }
90{
91 constexpr auto size = maxVer + 1 - minVer;
92 [&]<std::size_t... offset>(std::index_sequence<offset...>) {
93 (((void)fn(
95 std::forward<Args>(args)...)),
96 ...);
98}
99
100template <typename Fn, typename... Args>
101void
102forAllApiVersions(Fn const& fn, Args&&... args)
103 requires requires {
106 RPC::apiMaximumValidVersion>(fn, std::forward<Args>(args)...);
107 }
108{
111 RPC::apiMaximumValidVersion>(fn, std::forward<Args>(args)...);
112}
113
114} // namespace ripple
115
116#endif
static constexpr auto apiMaximumSupportedVersion
Definition: ApiVersion.h:58
static constexpr std::integral_constant< unsigned, Version > apiVersion
Definition: ApiVersion.h:54
static constexpr auto apiMaximumValidVersion
Definition: ApiVersion.h:63
static constexpr auto apiCommandLineVersion
Definition: ApiVersion.h:60
static constexpr auto apiBetaVersion
Definition: ApiVersion.h:62
static constexpr auto apiVersionIfUnspecified
Definition: ApiVersion.h:59
static constexpr auto apiInvalidVersion
Definition: ApiVersion.h:56
static constexpr auto apiMinimumSupportedVersion
Definition: ApiVersion.h:57
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
void forAllApiVersions(Fn const &fn, Args &&... args)
Definition: ApiVersion.h:102
void forApiVersions(Fn const &fn, Args &&... args)
Definition: ApiVersion.h:80