Bitcoin Core  31.0.0
P2P Digital Currency
foo.h
Go to the documentation of this file.
1 // Copyright (c) The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef MP_TEST_FOO_H
6 #define MP_TEST_FOO_H
7 
8 #include <cassert>
9 #include <functional>
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <set>
14 #include <vector>
15 
16 namespace mp {
17 namespace test {
18 
19 struct FooStruct
20 {
21  std::string name;
22  std::set<int> setint;
23  std::vector<bool> vbool;
24 };
25 
26 enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
27 
28 struct FooCustom
29 {
30  std::string v1;
31  int v2;
32 };
33 
34 struct FooEmpty
35 {
36 };
37 
38 struct FooMessage
39 {
40  std::string message;
41 };
42 
43 struct FooMutable
44 {
45  std::string message;
46 };
47 
48 using FooData = std::vector<char>;
49 using FooDataRef = std::shared_ptr<const FooData>;
50 
52 {
53 public:
54  virtual ~FooCallback() = default;
55  virtual int call(int arg) = 0;
56 };
57 
59 {
60 public:
61  virtual int callExtended(int arg) = 0;
62 };
63 
65 {
66 public:
67  int add(int a, int b) { return a + b; }
68  void addOut(int a, int b, int& out) { out = a + b; }
69  void addInOut(int x, int& sum) { sum += x; }
70  int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
71  FooStruct pass(FooStruct foo) { return foo; }
72  void raise(FooStruct foo) { throw foo; }
73  void initThreadMap() {}
74  int callback(FooCallback& callback, int arg) { return callback.call(arg); }
75  int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); }
76  int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param)
77  void saveCallback(std::shared_ptr<FooCallback> callback) { m_callback = std::move(callback); }
78  int callbackSaved(int arg) { return m_callback->call(arg); }
79  int callbackExtended(ExtendedCallback& callback, int arg) { return callback.callExtended(arg); }
80  FooCustom passCustom(FooCustom foo) { return foo; }
81  FooEmpty passEmpty(FooEmpty foo) { return foo; }
82  FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; }
83  void passMutable(FooMutable& foo) { foo.message += " call"; }
84  FooEnum passEnum(FooEnum foo) { return foo; }
85  int passFn(std::function<int()> fn) { return fn(); }
86  std::vector<FooDataRef> passDataPointers(std::vector<FooDataRef> values) { return values; }
87  std::shared_ptr<FooCallback> m_callback;
88  void callFn() { assert(m_fn); m_fn(); }
89  void callFnAsync() { assert(m_fn); m_fn(); }
90  int callIntFnAsync(int arg) { assert(m_int_fn); return m_int_fn(arg); }
91  std::function<void()> m_fn;
92  std::function<int(int)> m_int_fn;
93 };
94 
95 } // namespace test
96 } // namespace mp
97 
98 #endif // MP_TEST_FOO_H
std::function< void()> m_fn
Definition: foo.h:91
assert(!tx.IsCoinBase())
int callbackShared(std::shared_ptr< FooCallback > callback, int arg)
Definition: foo.h:76
int add(int a, int b)
Definition: foo.h:67
int mapSize(const std::map< std::string, std::string > &map)
Definition: foo.h:70
FooEnum
Definition: foo.h:26
std::string message
Definition: foo.h:40
int callbackSaved(int arg)
Definition: foo.h:78
FooEnum passEnum(FooEnum foo)
Definition: foo.h:84
std::shared_ptr< const FooData > FooDataRef
Definition: foo.h:49
int callbackUnique(std::unique_ptr< FooCallback > callback, int arg)
Definition: foo.h:75
std::vector< FooDataRef > passDataPointers(std::vector< FooDataRef > values)
Definition: foo.h:86
virtual int callExtended(int arg)=0
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
FooMessage passMessage(FooMessage foo)
Definition: foo.h:82
std::set< int > setint
Definition: foo.h:22
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
int callIntFnAsync(int arg)
Definition: foo.h:90
volatile double sum
Definition: examples.cpp:10
int passFn(std::function< int()> fn)
Definition: foo.h:85
FooStruct pass(FooStruct foo)
Definition: foo.h:71
void saveCallback(std::shared_ptr< FooCallback > callback)
Definition: foo.h:77
int callback(FooCallback &callback, int arg)
Definition: foo.h:74
void addOut(int a, int b, int &out)
Definition: foo.h:68
FooCustom passCustom(FooCustom foo)
Definition: foo.h:80
virtual ~FooCallback()=default
int callbackExtended(ExtendedCallback &callback, int arg)
Definition: foo.h:79
FooEmpty passEmpty(FooEmpty foo)
Definition: foo.h:81
std::string name
Definition: foo.h:21
std::vector< char > FooData
Definition: foo.h:48
std::string message
Definition: foo.h:45
void addInOut(int x, int &sum)
Definition: foo.h:69
std::function< int(int)> m_int_fn
Definition: foo.h:92
std::vector< bool > vbool
Definition: foo.h:23
std::shared_ptr< FooCallback > m_callback
Definition: foo.h:87
virtual int call(int arg)=0
std::string v1
Definition: foo.h:30
void passMutable(FooMutable &foo)
Definition: foo.h:83