Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
test
test_sigslot.cxx
Go to the documentation of this file.
1
#include <boost/signals2.hpp>
2
3
#include <iostream>
4
#include <memory>
5
6
7
8
// http://stackoverflow.com/a/20429450
9
10
typedef
boost::signals2::signal<int ()>
IntSig
;
11
typedef
std::shared_ptr<IntSig>
IntSigPtr
;
12
typedef
IntSig::slot_type
IntSlot
;
13
14
using namespace
std
;
15
16
struct
A
{
17
int
x
;
18
double
dd
;
19
A
(
int
n
,
double
d
) : x(n), dd(d) {}
20
int
operator()
() {
21
cout <<
"A @ "
<< x <<
" "
<< dd <<
endl
;
22
dd *=
x
;
23
return
x++;
24
}
25
};
26
27
struct
B
{
28
int
y
;
29
double
s
;
30
IntSigPtr
sig
;
31
32
B
(
double
scale
) : y(0), s(scale), sig(new
IntSig
) {}
33
void
connect
(
const
IntSlot
& slot) { sig->connect(slot); }
34
int
operator()
() {
35
y = s * *(*sig)();
36
cout <<
"B @ "
<< y <<
endl
;
37
return
y
;
38
}
39
};
40
41
void
test_simple
()
42
{
43
A
a
(42, 1.0);
44
B
b
(1.0);
45
b.
connect
(a);
46
B
b2(2.0);
47
b2.
connect
(b);
48
B
b3(3.0);
49
b3.
connect
(b2);
50
51
b3();
52
b3();
53
}
54
55
struct
MyData
{
56
typedef
std::shared_ptr<MyData>
pointer
;
57
int
x
;
58
MyData
(
int
n
=0) : x(
n
) {}
59
int
next
() {
return
++
x
; }
60
int
get
() {
return
x
; }
61
62
typedef
boost::signals2::signal<pointer ()>
source_signal
;
63
typedef
typename
source_signal::slot_type
source_slot
;
64
};
65
66
struct
SlotA
{
67
MyData::pointer
data
;
68
SlotA
() : data(new
MyData
) {}
69
MyData::pointer
operator()
() {
70
data->next();
71
return
data
;
72
}
73
};
74
75
struct
SigA
{
76
SigA
() {}
77
78
MyData::pointer
operator()
() {
return
*m_input(); }
79
80
void
connect
(
const
MyData::source_slot
&
s
) { m_input.connect(s); }
81
MyData::source_signal
m_input
;
82
};
83
84
void
test_isignal
()
85
{
86
SlotA
slota;
87
SigA
siga, sigaa;
88
siga.
connect
(slota);
89
sigaa.
connect
(boost::ref(siga));
90
cout << sigaa()->get() <<
endl
;;
91
cout << sigaa()->get() <<
endl
;;
92
cout << sigaa()->get() <<
endl
;;
93
}
94
95
96
int
main
()
97
{
98
test_simple
();
99
test_isignal
();
100
return
0;
101
}
MyData
Definition:
test_stream.cxx:12
MyData::next
int next()
Definition:
test_sigslot.cxx:59
B
Definition:
pointersEqual_t.cc:9
IntSigPtr
std::shared_ptr< IntSig > IntSigPtr
Definition:
test_sigslot.cxx:11
A::A
A(int n, double d)
Definition:
test_sigslot.cxx:19
B::y
int y
Definition:
test_sigslot.cxx:28
MyData::x
int x
Definition:
test_sigslot.cxx:57
MyData::source_slot
source_signal::slot_type source_slot
Definition:
test_sigslot.cxx:63
test_isignal
void test_isignal()
Definition:
test_sigslot.cxx:84
bump_copyright.d
string d
Definition:
bump_copyright.py:70
std
STL namespace.
SigA::SigA
SigA()
Definition:
test_sigslot.cxx:76
SigA::m_input
MyData::source_signal m_input
Definition:
test_sigslot.cxx:81
test_simple
void test_simple()
Definition:
test_sigslot.cxx:41
internal::data
basic_data data
Definition:
format.h:764
A::x
int x
Definition:
test_sigslot.cxx:17
MyData::MyData
MyData(int n=0)
Definition:
test_sigslot.cxx:58
y
double y
Definition:
GapWidth_module.cc:109
SlotA
Definition:
test_sigslot.cxx:66
main
int main()
Definition:
test_sigslot.cxx:96
A::operator()
int operator()()
Definition:
test_sigslot.cxx:20
SigA::operator()
MyData::pointer operator()()
Definition:
test_sigslot.cxx:78
IntSlot
IntSig::slot_type IntSlot
Definition:
test_sigslot.cxx:12
SlotA::SlotA
SlotA()
Definition:
test_sigslot.cxx:68
a
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition:
pointer.h:1124
MyData::pointer
std::shared_ptr< MyData > pointer
Definition:
test_sigslot.cxx:56
WireCell::Waveform::scale
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition:
Waveform.h:146
A::dd
double dd
Definition:
test_sigslot.cxx:18
B::s
double s
Definition:
test_sigslot.cxx:29
B::connect
void connect(const IntSlot &slot)
Definition:
test_sigslot.cxx:33
SlotA::data
MyData::pointer data
Definition:
test_sigslot.cxx:67
A
#define A
Definition:
memgrp.cpp:38
b
static bool * b
Definition:
config.cpp:1043
B::sig
IntSigPtr sig
Definition:
test_sigslot.cxx:30
train.x
list x
Definition:
train.py:276
IntSig
boost::signals2::signal< int()> IntSig
Definition:
test_sigslot.cxx:10
B::operator()
int operator()()
Definition:
test_sigslot.cxx:34
MyData::source_signal
boost::signals2::signal< pointer()> source_signal
Definition:
test_sigslot.cxx:62
n
std::size_t n
Definition:
format.h:3399
SlotA::operator()
MyData::pointer operator()()
Definition:
test_sigslot.cxx:69
s
static QCString * s
Definition:
config.cpp:1042
SigA::connect
void connect(const MyData::source_slot &s)
Definition:
test_sigslot.cxx:80
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
B::B
B(double scale)
Definition:
test_sigslot.cxx:32
SigA
Definition:
test_sigslot.cxx:75
Generated by
1.8.11