forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoo.h
More file actions
92 lines (78 loc) · 2.46 KB
/
Copy pathfoo.h
File metadata and controls
92 lines (78 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MP_TEST_FOO_H
#define MP_TEST_FOO_H
#include <cassert>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <set>
#include <vector>
namespace mp {
namespace test {
struct FooStruct
{
std::string name;
std::set<int> setint;
std::vector<bool> vbool;
};
enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
struct FooCustom
{
std::string v1;
int v2;
};
struct FooEmpty
{
};
struct FooMessage
{
std::string message;
};
struct FooMutable
{
std::string message;
};
class FooCallback
{
public:
virtual ~FooCallback() = default;
virtual int call(int arg) = 0;
};
class ExtendedCallback : public FooCallback
{
public:
virtual int callExtended(int arg) = 0;
};
class FooImplementation
{
public:
int add(int a, int b) { return a + b; }
void addOut(int a, int b, int& out) { out = a + b; }
void addInOut(int x, int& sum) { sum += x; }
int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
FooStruct pass(FooStruct foo) { return foo; }
void raise(FooStruct foo) { throw foo; }
void initThreadMap() {}
int callback(FooCallback& callback, int arg) { return callback.call(arg); }
int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); }
int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param)
void saveCallback(std::shared_ptr<FooCallback> callback) { m_callback = std::move(callback); }
int callbackSaved(int arg) { return m_callback->call(arg); }
int callbackExtended(ExtendedCallback& callback, int arg) { return callback.callExtended(arg); }
FooCustom passCustom(FooCustom foo) { return foo; }
FooEmpty passEmpty(FooEmpty foo) { return foo; }
FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; }
void passMutable(FooMutable& foo) { foo.message += " call"; }
FooEnum passEnum(FooEnum foo) { return foo; }
int passFn(std::function<int()> fn) { return fn(); }
std::shared_ptr<FooCallback> m_callback;
void callFn() { assert(m_fn); m_fn(); }
void callFnAsync() { assert(m_fn); m_fn(); }
std::function<void()> m_fn;
};
} // namespace test
} // namespace mp
#endif // MP_TEST_FOO_H