Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
ipc
libmultiprocess
test
mp
test
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
51
class
FooCallback
52
{
53
public
:
54
virtual
~FooCallback
() =
default
;
55
virtual
int
call
(
int
arg) = 0;
56
};
57
58
class
ExtendedCallback
:
public
FooCallback
59
{
60
public
:
61
virtual
int
callExtended
(
int
arg) = 0;
62
};
63
64
class
FooImplementation
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
mp::test::ExtendedCallback
Definition
foo.h:59
mp::test::ExtendedCallback::callExtended
virtual int callExtended(int arg)=0
mp::test::FooCallback
Definition
foo.h:52
mp::test::FooCallback::call
virtual int call(int arg)=0
mp::test::FooCallback::~FooCallback
virtual ~FooCallback()=default
mp::test::FooImplementation
Definition
foo.h:65
mp::test::FooImplementation::addOut
void addOut(int a, int b, int &out)
Definition
foo.h:68
mp::test::FooImplementation::m_int_fn
std::function< int(int)> m_int_fn
Definition
foo.h:92
mp::test::FooImplementation::callFn
void callFn()
Definition
foo.h:88
mp::test::FooImplementation::callbackSaved
int callbackSaved(int arg)
Definition
foo.h:78
mp::test::FooImplementation::passMutable
void passMutable(FooMutable &foo)
Definition
foo.h:83
mp::test::FooImplementation::initThreadMap
void initThreadMap()
Definition
foo.h:73
mp::test::FooImplementation::passEmpty
FooEmpty passEmpty(FooEmpty foo)
Definition
foo.h:81
mp::test::FooImplementation::callFnAsync
void callFnAsync()
Definition
foo.h:89
mp::test::FooImplementation::passFn
int passFn(std::function< int()> fn)
Definition
foo.h:85
mp::test::FooImplementation::m_callback
std::shared_ptr< FooCallback > m_callback
Definition
foo.h:87
mp::test::FooImplementation::m_fn
std::function< void()> m_fn
Definition
foo.h:91
mp::test::FooImplementation::callbackShared
int callbackShared(std::shared_ptr< FooCallback > callback, int arg)
Definition
foo.h:76
mp::test::FooImplementation::addInOut
void addInOut(int x, int &sum)
Definition
foo.h:69
mp::test::FooImplementation::raise
void raise(FooStruct foo)
Definition
foo.h:72
mp::test::FooImplementation::callbackUnique
int callbackUnique(std::unique_ptr< FooCallback > callback, int arg)
Definition
foo.h:75
mp::test::FooImplementation::passEnum
FooEnum passEnum(FooEnum foo)
Definition
foo.h:84
mp::test::FooImplementation::add
int add(int a, int b)
Definition
foo.h:67
mp::test::FooImplementation::callIntFnAsync
int callIntFnAsync(int arg)
Definition
foo.h:90
mp::test::FooImplementation::passMessage
FooMessage passMessage(FooMessage foo)
Definition
foo.h:82
mp::test::FooImplementation::callback
int callback(FooCallback &callback, int arg)
Definition
foo.h:74
mp::test::FooImplementation::pass
FooStruct pass(FooStruct foo)
Definition
foo.h:71
mp::test::FooImplementation::passDataPointers
std::vector< FooDataRef > passDataPointers(std::vector< FooDataRef > values)
Definition
foo.h:86
mp::test::FooImplementation::passCustom
FooCustom passCustom(FooCustom foo)
Definition
foo.h:80
mp::test::FooImplementation::saveCallback
void saveCallback(std::shared_ptr< FooCallback > callback)
Definition
foo.h:77
mp::test::FooImplementation::callbackExtended
int callbackExtended(ExtendedCallback &callback, int arg)
Definition
foo.h:79
mp::test::FooImplementation::mapSize
int mapSize(const std::map< std::string, std::string > &map)
Definition
foo.h:70
sum
volatile double sum
Definition
examples.cpp:10
mp::test
Definition
foo-types.h:34
mp::test::FooEnum
FooEnum
Definition
foo.h:26
mp::test::FooEnum::TWO
@ TWO
Definition
foo.h:26
mp::test::FooEnum::ONE
@ ONE
Definition
foo.h:26
mp::test::FooData
std::vector< char > FooData
Definition
foo.h:48
mp::test::FooDataRef
std::shared_ptr< const FooData > FooDataRef
Definition
foo.h:49
mp
Functions to serialize / deserialize common bitcoin types.
Definition
common-types.h:57
values
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
Definition
scriptnum_tests.cpp:17
mp::test::FooCustom
Definition
foo.h:29
mp::test::FooCustom::v2
int v2
Definition
foo.h:31
mp::test::FooCustom::v1
std::string v1
Definition
foo.h:30
mp::test::FooEmpty
Definition
foo.h:35
mp::test::FooMessage
Definition
foo.h:39
mp::test::FooMessage::message
std::string message
Definition
foo.h:40
mp::test::FooMutable
Definition
foo.h:44
mp::test::FooMutable::message
std::string message
Definition
foo.h:45
mp::test::FooStruct
Definition
foo.h:20
mp::test::FooStruct::name
std::string name
Definition
foo.h:21
mp::test::FooStruct::setint
std::set< int > setint
Definition
foo.h:22
mp::test::FooStruct::vbool
std::vector< bool > vbool
Definition
foo.h:23
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0