Bitcoin Core 31.99.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 <optional>
13#include <string>
14#include <set>
15#include <unordered_set>
16#include <vector>
17
18namespace mp {
19namespace test {
20
22{
23 std::string name;
24 std::set<int> set_int;
25 std::vector<bool> vector_bool;
26 std::optional<int> optional_int;
27 std::unordered_set<int> unordered_set_int;
28 std::map<std::string, int> map_string_int;
29};
30
31enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
32
34{
35 std::string v1;
36 int v2;
37};
38
40{
41};
42
44{
45 std::string message;
46};
47
49{
50 std::string message;
51};
52
53using FooData = std::vector<char>;
54using FooDataRef = std::shared_ptr<const FooData>;
55
57{
58public:
59 virtual ~FooCallback() = default;
60 virtual int call(int arg) = 0;
61};
62
64{
65public:
66 virtual int callExtended(int arg) = 0;
67};
68
70{
71public:
72 int add(int a, int b) { return a + b; }
73 void addOut(int a, int b, int& out) { out = a + b; }
74 void addInOut(int x, int& sum) { sum += x; }
75 int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
76 FooStruct pass(FooStruct foo) { return foo; }
77 void raise(FooStruct foo) { throw foo; }
78 void initThreadMap() {}
79 int callback(FooCallback& callback, int arg) { return callback.call(arg); }
80 int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); }
81 int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param)
82 void saveCallback(std::shared_ptr<FooCallback> callback) { m_callback = std::move(callback); }
83 int callbackSaved(int arg) { return m_callback->call(arg); }
84 int callbackExtended(ExtendedCallback& callback, int arg) { return callback.callExtended(arg); }
85 FooCustom passCustom(FooCustom foo) { return foo; }
86 FooEmpty passEmpty(FooEmpty foo) { return foo; }
87 FooData passData(FooData foo) { return foo; }
88 FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; }
89 void passMutable(FooMutable& foo) { foo.message += " call"; }
90 FooEnum passEnum(FooEnum foo) { return foo; }
91 double passDouble(double value) { return value; }
92 int passFn(std::function<int()> fn) { return fn(); }
93 std::vector<FooDataRef> passDataPointers(std::vector<FooDataRef> values) { return values; }
94 std::shared_ptr<FooCallback> m_callback;
95 void callFn() { assert(m_fn); m_fn(); }
96 void callFnAsync() { assert(m_fn); m_fn(); }
97 int callIntFnAsync(int arg) { assert(m_int_fn); return m_int_fn(arg); }
98 std::function<void()> m_fn;
99 std::function<int(int)> m_int_fn;
100};
101
102} // namespace test
103} // namespace mp
104
105#endif // MP_TEST_FOO_H
virtual int callExtended(int arg)=0
virtual int call(int arg)=0
virtual ~FooCallback()=default
void addOut(int a, int b, int &out)
Definition: foo.h:73
std::function< int(int)> m_int_fn
Definition: foo.h:99
int callbackSaved(int arg)
Definition: foo.h:83
void passMutable(FooMutable &foo)
Definition: foo.h:89
FooEmpty passEmpty(FooEmpty foo)
Definition: foo.h:86
int passFn(std::function< int()> fn)
Definition: foo.h:92
std::shared_ptr< FooCallback > m_callback
Definition: foo.h:94
std::function< void()> m_fn
Definition: foo.h:98
int callbackShared(std::shared_ptr< FooCallback > callback, int arg)
Definition: foo.h:81
void addInOut(int x, int &sum)
Definition: foo.h:74
void raise(FooStruct foo)
Definition: foo.h:77
int callbackUnique(std::unique_ptr< FooCallback > callback, int arg)
Definition: foo.h:80
FooEnum passEnum(FooEnum foo)
Definition: foo.h:90
int add(int a, int b)
Definition: foo.h:72
double passDouble(double value)
Definition: foo.h:91
int callIntFnAsync(int arg)
Definition: foo.h:97
FooMessage passMessage(FooMessage foo)
Definition: foo.h:88
int callback(FooCallback &callback, int arg)
Definition: foo.h:79
FooStruct pass(FooStruct foo)
Definition: foo.h:76
std::vector< FooDataRef > passDataPointers(std::vector< FooDataRef > values)
Definition: foo.h:93
FooCustom passCustom(FooCustom foo)
Definition: foo.h:85
void saveCallback(std::shared_ptr< FooCallback > callback)
Definition: foo.h:82
FooData passData(FooData foo)
Definition: foo.h:87
int callbackExtended(ExtendedCallback &callback, int arg)
Definition: foo.h:84
int mapSize(const std::map< std::string, std::string > &map)
Definition: foo.h:75
volatile double sum
Definition: examples.cpp:10
std::shared_ptr< const FooData > FooDataRef
Definition: foo.h:54
FooEnum
Definition: foo.h:31
std::vector< char > FooData
Definition: foo.h:53
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
std::string v1
Definition: foo.h:35
std::string message
Definition: foo.h:45
std::string message
Definition: foo.h:50
std::string name
Definition: foo.h:23
std::map< std::string, int > map_string_int
Definition: foo.h:28
std::unordered_set< int > unordered_set_int
Definition: foo.h:27
std::optional< int > optional_int
Definition: foo.h:26
std::vector< bool > vector_bool
Definition: foo.h:25
std::set< int > set_int
Definition: foo.h:24
assert(!tx.IsCoinBase())