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 <type_traits>
24#include <utility>
25
26namespace ripple {
27
50namespace RPC {
51
52template <unsigned int Version>
54
55constexpr static auto apiInvalidVersion = apiVersion<0>;
56constexpr static auto apiMinimumSupportedVersion = apiVersion<1>;
57constexpr static auto apiMaximumSupportedVersion = apiVersion<2>;
58constexpr static auto apiVersionIfUnspecified = apiVersion<1>;
59constexpr static auto apiCommandLineVersion =
60 apiVersion<1>; // TODO Bump to 2 later
61constexpr static auto apiBetaVersion = apiVersion<3>;
62constexpr static auto apiMaximumValidVersion = apiBetaVersion;
63
65static_assert(
68static_assert(
74
75} // namespace RPC
76
77template <unsigned minVer, unsigned maxVer, typename Fn, typename... Args>
78void
79forApiVersions(Fn const& fn, Args&&... args)
80 requires //
81 (maxVer >= minVer) && //
82 (minVer >= RPC::apiMinimumSupportedVersion) && //
83 (RPC::apiMaximumValidVersion >= maxVer) && requires {
85 std::forward<Args>(args)...);
87 std::forward<Args>(args)...);
88 }
89{
90 constexpr auto size = maxVer + 1 - minVer;
91 [&]<std::size_t... offset>(std::index_sequence<offset...>) {
92 (((void)fn(
94 std::forward<Args>(args)...)),
95 ...);
97}
98
99template <typename Fn, typename... Args>
100void
101forAllApiVersions(Fn const& fn, Args&&... args)
102 requires requires {
105 RPC::apiMaximumValidVersion>(fn, std::forward<Args>(args)...);
106 }
107{
110 RPC::apiMaximumValidVersion>(fn, std::forward<Args>(args)...);
111}
112
113} // namespace ripple
114
115#endif
static constexpr auto apiMaximumSupportedVersion
Definition: ApiVersion.h:57
static constexpr std::integral_constant< unsigned, Version > apiVersion
Definition: ApiVersion.h:53
static constexpr auto apiMaximumValidVersion
Definition: ApiVersion.h:62
static constexpr auto apiCommandLineVersion
Definition: ApiVersion.h:59
static constexpr auto apiBetaVersion
Definition: ApiVersion.h:61
static constexpr auto apiVersionIfUnspecified
Definition: ApiVersion.h:58
static constexpr auto apiInvalidVersion
Definition: ApiVersion.h:55
static constexpr auto apiMinimumSupportedVersion
Definition: ApiVersion.h:56
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
void forAllApiVersions(Fn const &fn, Args &&... args)
Definition: ApiVersion.h:101
void forApiVersions(Fn const &fn, Args &&... args)
Definition: ApiVersion.h:79