Bitcoin Core 29.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 <string>
13#include <set>
14#include <vector>
15
16namespace mp {
17namespace test {
18
20{
21 std::string name;
22 std::set<int> setint;
23 std::vector<bool> vbool;
24};
25
26enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
27
29{
30 std::string v1;
31 int v2;
32};
33
35{
36};
37
39{
40 std::string message;
41};
42
44{
45 std::string message;
46};
47
49{
50public:
51 virtual ~FooCallback() = default;
52 virtual int call(int arg) = 0;
53};
54
56{
57public:
58 virtual int callExtended(int arg) = 0;
59};
60
62{
63public:
64 int add(int a, int b) { return a + b; }
65 int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
66 FooStruct pass(FooStruct foo) { return foo; }
67 void raise(FooStruct foo) { throw foo; }
68 void initThreadMap() {}
69 int callback(FooCallback& callback, int arg) { return callback.call(arg); }
70 int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); }
71 int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param)
72 void saveCallback(std::shared_ptr<FooCallback> callback) { m_callback = std::move(callback); }
73 int callbackSaved(int arg) { return m_callback->call(arg); }
74 int callbackExtended(ExtendedCallback& callback, int arg) { return callback.callExtended(arg); }
75 FooCustom passCustom(FooCustom foo) { return foo; }
76 FooEmpty passEmpty(FooEmpty foo) { return foo; }
77 FooMessage passMessage(FooMessage foo) { foo.message += " call"; return foo; }
78 void passMutable(FooMutable& foo) { foo.message += " call"; }
79 FooEnum passEnum(FooEnum foo) { return foo; }
80 int passFn(std::function<int()> fn) { return fn(); }
81 std::shared_ptr<FooCallback> m_callback;
82 void callFn() { assert(m_fn); m_fn(); }
83 void callFnAsync() { assert(m_fn); m_fn(); }
84 std::function<void()> m_fn;
85};
86
87} // namespace test
88} // namespace mp
89
90#endif // MP_TEST_FOO_H
virtual int callExtended(int arg)=0
virtual int call(int arg)=0
virtual ~FooCallback()=default
int callbackSaved(int arg)
Definition: foo.h:73
void passMutable(FooMutable &foo)
Definition: foo.h:78
FooEmpty passEmpty(FooEmpty foo)
Definition: foo.h:76
int passFn(std::function< int()> fn)
Definition: foo.h:80
std::shared_ptr< FooCallback > m_callback
Definition: foo.h:81
std::function< void()> m_fn
Definition: foo.h:84
int callbackShared(std::shared_ptr< FooCallback > callback, int arg)
Definition: foo.h:71
void raise(FooStruct foo)
Definition: foo.h:67
int callbackUnique(std::unique_ptr< FooCallback > callback, int arg)
Definition: foo.h:70
FooEnum passEnum(FooEnum foo)
Definition: foo.h:79
int add(int a, int b)
Definition: foo.h:64
FooMessage passMessage(FooMessage foo)
Definition: foo.h:77
int callback(FooCallback &callback, int arg)
Definition: foo.h:69
FooStruct pass(FooStruct foo)
Definition: foo.h:66
FooCustom passCustom(FooCustom foo)
Definition: foo.h:75
void saveCallback(std::shared_ptr< FooCallback > callback)
Definition: foo.h:72
int callbackExtended(ExtendedCallback &callback, int arg)
Definition: foo.h:74
int mapSize(const std::map< std::string, std::string > &map)
Definition: foo.h:65
FooEnum
Definition: foo.h:26
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
std::string v1
Definition: foo.h:30
std::string message
Definition: foo.h:40
std::string message
Definition: foo.h:45
std::string name
Definition: foo.h:21
std::set< int > setint
Definition: foo.h:22
std::vector< bool > vbool
Definition: foo.h:23
assert(!tx.IsCoinBase())