rippled
paths.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_PATHS_H_INCLUDED
21 #define RIPPLE_TEST_JTX_PATHS_H_INCLUDED
22 
23 #include <ripple/protocol/Issue.h>
24 #include <test/jtx/Env.h>
25 #include <type_traits>
26 
27 namespace ripple {
28 namespace test {
29 namespace jtx {
30 
32 class paths
33 {
34 private:
36  int depth_;
37  unsigned int limit_;
38 
39 public:
40  paths(Issue const& in, int depth = 7, unsigned int limit = 4)
41  : in_(in), depth_(depth), limit_(limit)
42  {
43  }
44 
45  void
46  operator()(Env&, JTx& jt) const;
47 };
48 
49 //------------------------------------------------------------------------------
50 
55 class path
56 {
57 private:
59 
60 public:
61  path();
62 
63  template <class T, class... Args>
64  explicit path(T const& t, Args const&... args);
65 
66  void
67  operator()(Env&, JTx& jt) const;
68 
69 private:
71  create();
72 
73  void
74  append_one(Account const& account);
75 
76  template <class T>
78  append_one(T const& t)
79  {
80  append_one(Account{t});
81  }
82 
83  void
84  append_one(IOU const& iou);
85 
86  void
87  append_one(BookSpec const& book);
88 
89  template <class T, class... Args>
90  void
91  append(T const& t, Args const&... args);
92 };
93 
94 template <class T, class... Args>
95 path::path(T const& t, Args const&... args) : jv_(Json::arrayValue)
96 {
97  append(t, args...);
98 }
99 
100 template <class T, class... Args>
101 void
102 path::append(T const& t, Args const&... args)
103 {
104  append_one(t);
105  if constexpr (sizeof...(args) > 0)
106  append(args...);
107 }
108 
109 } // namespace jtx
110 } // namespace test
111 } // namespace ripple
112 
113 #endif
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
ripple::test::jtx::path::jv_
Json::Value jv_
Definition: paths.h:58
ripple::test::jtx::path::append_one
std::enable_if_t< std::is_constructible< Account, T >::value > append_one(T const &t)
Definition: paths.h:78
ripple::test::jtx::path::append_one
void append_one(Account const &account)
Definition: paths.cpp:67
ripple::QualityDirection::in
@ in
ripple::test::jtx::paths::limit_
unsigned int limit_
Definition: paths.h:37
ripple::test::jtx::BookSpec
Definition: amount.h:155
ripple::test::jtx::paths::depth_
int depth_
Definition: paths.h:36
ripple::test::jtx::paths::operator()
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:29
ripple::test::jtx::paths::in_
Issue in_
Definition: paths.h:35
ripple::test::jtx::path::path
path()
Json
JSON (JavaScript Object Notation).
Definition: json_reader.cpp:27
std::enable_if_t
ripple::test::jtx::paths::paths
paths(Issue const &in, int depth=7, unsigned int limit=4)
Definition: paths.h:40
ripple::test::jtx::JTx
Execution context for applying a JSON transaction.
Definition: JTx.h:42
ripple::test::jtx::paths
Set Paths, SendMax on a JTx.
Definition: paths.h:32
ripple::test::jtx::path
Add a path.
Definition: paths.h:55
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::jtx::IOU
Converts to IOU Issue or STAmount.
Definition: amount.h:291
ripple::test::jtx::path::create
Json::Value & create()
Definition: paths.cpp:61
ripple::test::jtx::path::append
void append(T const &t, Args const &... args)
Definition: paths.h:102
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
type_traits
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::test::jtx::path::operator()
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:90