rippled
Loading...
Searching...
No Matches
require.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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_TEST_JTX_REQUIRE_H_INCLUDED
21#define RIPPLE_TEST_JTX_REQUIRE_H_INCLUDED
22
23#include <test/jtx/requires.h>
24#include <functional>
25#include <vector>
26
27namespace ripple {
28namespace test {
29namespace jtx {
30
31namespace detail {
32
33template <class Cond, class... Args>
34inline void
35require_args(requires_t& vec, Cond const& cond, Args const&... args)
36{
37 vec.push_back(cond);
38 if constexpr (sizeof...(args) > 0)
39 require_args(vec, args...);
40}
41
42} // namespace detail
43
45template <class... Args>
47required(Args const&... args)
48{
49 requires_t vec;
50 detail::require_args(vec, args...);
51 return [vec](Env& env) {
52 for (auto const& f : vec)
53 f(env);
54 };
55}
56
64{
65private:
67
68public:
69 template <class... Args>
70 require(Args const&... args) : cond_(required(args...))
71 {
72 }
73
74 void
75 operator()(Env&, JTx& jt) const
76 {
78 }
79};
80
81} // namespace jtx
82} // namespace test
83} // namespace ripple
84
85#endif
A transaction testing environment.
Definition: Env.h:117
Check a set of conditions.
Definition: require.h:64
require(Args const &... args)
Definition: require.h:70
void operator()(Env &, JTx &jt) const
Definition: require.h:75
T emplace_back(T... args)
void require_args(requires_t &vec, Cond const &cond, Args const &... args)
Definition: require.h:35
require_t required(Args const &... args)
Compose many condition functors into one.
Definition: require.h:47
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
T push_back(T... args)
Execution context for applying a JSON transaction.
Definition: JTx.h:44
requires_t require
Definition: JTx.h:46