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 {
29
30namespace detail {
31
32template <class Cond, class... Args>
33inline void
34require_args(test::jtx::requires_t& vec, Cond const& cond, Args const&... args)
35{
36 vec.push_back(cond);
37 if constexpr (sizeof...(args) > 0)
38 require_args(vec, args...);
39}
40
41} // namespace detail
42
43namespace test {
44namespace jtx {
45
47template <class... Args>
49required(Args const&... args)
50{
51 requires_t vec;
52 detail::require_args(vec, args...);
53 return [vec](Env& env) {
54 for (auto const& f : vec)
55 f(env);
56 };
57}
58
66{
67private:
69
70public:
71 template <class... Args>
72 require(Args const&... args) : cond_(required(args...))
73 {
74 }
75
76 void
77 operator()(Env&, JTx& jt) const
78 {
80 }
81};
82
83} // namespace jtx
84} // namespace test
85} // namespace ripple
86
87#endif
A transaction testing environment.
Definition Env.h:121
Check a set of conditions.
Definition require.h:66
require(Args const &... args)
Definition require.h:72
void operator()(Env &, JTx &jt) const
Definition require.h:77
T emplace_back(T... args)
void require_args(test::jtx::requires_t &vec, Cond const &cond, Args const &... args)
Definition require.h:34
std::function< void(Env &)> require_t
Definition requires.h:32
require_t required(Args const &... args)
Compose many condition functors into one.
Definition require.h:49
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
T push_back(T... args)
Execution context for applying a JSON transaction.
Definition JTx.h:45
requires_t require
Definition JTx.h:47