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 <test/jtx/Env.h>
24 #include <ripple/protocol/Issue.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,
41  int depth = 7, unsigned int limit = 4)
42  : in_(in)
43  , depth_(depth)
44  , limit_(limit)
45  {
46  }
47 
48  void
49  operator()(Env&, JTx& jt) const;
50 };
51 
52 //------------------------------------------------------------------------------
53 
58 class path
59 {
60 private:
62 
63 public:
64  path();
65 
66  template <class T, class... Args>
67  explicit
68  path (T const& t, Args const&... args);
69 
70  void
71  operator()(Env&, JTx& jt) const;
72 
73 private:
75  create();
76 
77  void
78  append_one(Account const& account);
79 
80  template <class T>
83  append_one(T const& t)
84  {
85  append_one(Account{ t });
86  }
87 
88  void
89  append_one(IOU const& iou);
90 
91  void
92  append_one(BookSpec const& book);
93 
94  template <class T, class... Args>
95  void
96  append (T const& t, Args const&... args);
97 };
98 
99 template <class T, class... Args>
100 path::path (T const& t, Args const&... args)
101  : jv_(Json::arrayValue)
102 {
103  append(t, args...);
104 }
105 
106 template <class T, class... Args>
107 void
108 path::append (T const& t, Args const&... args)
109 {
110  append_one(t);
111  if constexpr (sizeof...(args) > 0)
112  append(args...);
113 }
114 
115 } // jtx
116 } // test
117 } // ripple
118 
119 #endif
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
ripple::test::jtx::path::jv_
Json::Value jv_
Definition: paths.h:61
ripple::test::jtx::path::append_one
void append_one(Account const &account)
Definition: paths.cpp:65
ripple::QualityDirection::in
@ in
ripple::test::jtx::paths::limit_
unsigned int limit_
Definition: paths.h:37
ripple::test::jtx::BookSpec
Definition: amount.h:161
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:26
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:41
ripple::test::jtx::paths
Set Paths, SendMax on a JTx.
Definition: paths.h:32
ripple::test::jtx::path
Add a path.
Definition: paths.h:58
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:312
ripple::test::jtx::path::create
Json::Value & create()
Definition: paths.cpp:59
ripple::test::jtx::path::append
void append(T const &t, Args const &... args)
Definition: paths.h:108
ripple::test::jtx::path::append_one
std::enable_if_t< std::is_constructible< Account, T >::value > append_one(T const &t)
Definition: paths.h:83
std::is_constructible
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:117
Json::Value
Represents a JSON value.
Definition: json_value.h:141
ripple::test::jtx::path::operator()
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:88