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
25#include <functional>
26#include <vector>
27
28namespace ripple {
29namespace test {
30namespace jtx {
31
32namespace detail {
33
34template <class Cond, class... Args>
35inline void
36require_args(requires_t& vec, Cond const& cond, Args const&... args)
37{
38 vec.push_back(cond);
39 if constexpr (sizeof...(args) > 0)
40 require_args(vec, args...);
41}
42
43} // namespace detail
44
46template <class... Args>
48required(Args const&... args)
49{
50 requires_t vec;
51 detail::require_args(vec, args...);
52 return [vec](Env& env) {
53 for (auto const& f : vec)
54 f(env);
55 };
56}
57
65{
66private:
68
69public:
70 template <class... Args>
71 require(Args const&... args) : cond_(required(args...))
72 {
73 }
74
75 void
76 operator()(Env&, JTx& jt) const
77 {
79 }
80};
81
82} // namespace jtx
83} // namespace test
84} // namespace ripple
85
86#endif
A transaction testing environment.
Definition: Env.h:121
Check a set of conditions.
Definition: require.h:65
require(Args const &... args)
Definition: require.h:71
void operator()(Env &, JTx &jt) const
Definition: require.h:76
T emplace_back(T... args)
void require_args(requires_t &vec, Cond const &cond, Args const &... args)
Definition: require.h:36
require_t required(Args const &... args)
Compose many condition functors into one.
Definition: require.h:48
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:45
requires_t require
Definition: JTx.h:47