examples/sigslots.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <iostream>
14 #include "../../include/ecl/sigslots.hpp"
15 
16 /*****************************************************************************
17 ** Using
18 *****************************************************************************/
19 
20 using ecl::Signal;
21 using ecl::Slot;
23 
28 /*****************************************************************************
29 ** Globals
30 *****************************************************************************/
31 
32 void f() {
33  std::cout << " ---> Hey Dude" << std::endl;
34 }
35 
36 void g() {
37  std::cout << " ---> Hey Chained Dude" << std::endl;
38 }
39 
40 void h(const int& i) {
41  std::cout << " ---> Hey Data Dude: " << i << std::endl;
42 }
43 
44 /*****************************************************************************
45 ** Classes
46 *****************************************************************************/
47 
48 class A {
49 public:
50  A() : slot(&A::f,*this), slot_data(&A::g,*this) {
51  slot.connect("Dudette");
52  slot_data.connect("DataDudette");
53  };
54 
55  void f() {
56  std::cout << " ---> Hey Dudette" << std::endl;
57  }
58  void g(const int& i) {
59  std::cout << " ---> Hey Data Dudette: " << i << std::endl;
60  }
61  Slot<> slot;
62  Slot<const int&> slot_data;
63 };
64 
68 /*****************************************************************************
69 ** Main
70 *****************************************************************************/
71 
72 int main(int argc, char **argv) {
73 
74  std::cout << "Hello dude" << std::endl;
75 
76  std::cout << std::endl;
77  std::cout << "***************************************************************" << std::endl;
78  std::cout << "* Global Function" << std::endl;
79  std::cout << "***************************************************************" << std::endl;
80  std::cout << std::endl;
81  Slot<> slot1(&f);
82  Slot<> slot2(&f);
83  std::cout << "Connecting 1 signal and two slots to 'Dude'" << std::endl;
84  slot1.connect("Dude");
85  slot2.connect("Dude");
86  Signal<> signal;
87  signal.connect("Dude");
88  std::cout << "Emitting" << std::endl;
89  signal.emit();
90  std::cout << std::endl;
92  std::cout << std::endl;
93 
94  std::cout << "Connecting a data slot-signal pair to 'DataDude'" << std::endl;
95  Slot<const int&> slot_data_1(&h);
96  Signal<const int&> sig_data_1;
97  slot_data_1.connect("DataDude");
98  sig_data_1.connect("DataDude");
99  std::cout << "Emitting" << std::endl;
100  sig_data_1.emit(2);
101  std::cout << std::endl;
103 
104  std::cout << std::endl;
105  std::cout << "***************************************************************" << std::endl;
106  std::cout << "* Disconnects" << std::endl;
107  std::cout << "***************************************************************" << std::endl;
108  std::cout << std::endl;
109 
110  std::cout << "Disconnecting second slot" << std::endl;
111  slot2.disconnect();
112  std::cout << "Emitting" << std::endl;
113  signal.emit();
114  std::cout << "Disconnecting signal" << std::endl;
115  signal.disconnect();
116  std::cout << "Emitting (to nowhere)" << std::endl;
117  signal.emit();
118  std::cout << std::endl;
120 
121  std::cout << std::endl;
122  std::cout << "***************************************************************" << std::endl;
123  std::cout << "* Relays" << std::endl;
124  std::cout << "***************************************************************" << std::endl;
125  std::cout << std::endl;
126 
127  std::cout << "Connecting signal and second slot back to 'Dude'" << std::endl;
128  slot2.connect("Dude");
129  signal.connect("Dude");
130  std::cout << std::endl;
132  std::cout << std::endl;
133 
134  Signal<> signal_relay;
135  std::cout << "Connecting relay as signal to 'ChainedDude'" << std::endl;
136  signal_relay.connect("ChainedDude");
137  std::cout << "Connecting relay as slot to 'Dude'." << std::endl;
138  signal_relay.connectAsSlot("Dude");
139  Slot<> slot3(&g);
140  std::cout << "Connecting slot to 'ChainedDude'" << std::endl;
141  slot3.connect("ChainedDude");
142  std::cout << "Emitting" << std::endl;
143  signal.emit();
144  std::cout << std::endl;
146 
147  std::cout << std::endl;
148  std::cout << "***************************************************************" << std::endl;
149  std::cout << "* Member Functions" << std::endl;
150  std::cout << "***************************************************************" << std::endl;
151  std::cout << std::endl;
152 
153  std::cout << "Creating a member slot and connecting to 'Dudette'" << std::endl;
154  A a;
155  std::cout << "Connecting a signal to 'Dudette'" << std::endl;
156  Signal<> signal_dudette;
157  signal_dudette.connect("Dudette");
158  signal_dudette.emit();
160  std::cout << std::endl;
161 
162  std::cout << "Creating a member data slot and connecting to 'DataDudette'" << std::endl;
163  std::cout << "Connecting a data signal to 'DataDudette'" << std::endl;
164  Signal<const int&> signal_data_dudette;
165  signal_data_dudette.connect("DataDudette");
166  signal_data_dudette.emit(3);
167  std::cout << std::endl;
169 
170  return 0;
171 }
void g(const int &i)
void connectAsSlot(const std::string &topic)
Connect as a slot, with the emit function loaded.
Definition: signal.hpp:113
The sigslots connection manager.
Definition: manager.hpp:49
int main(int argc, char **argv)
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: slot.hpp:152
void disconnect()
Disconnect the slot from all topics.
Definition: slot.hpp:158
void disconnect()
Disconnect the signal from all topics.
Definition: signal.hpp:119
void f(int i) ecl_debug_throw_decl(StandardException)
Signalling component of a callback system.
Definition: signal.hpp:47
void connect(const std::string &topic)
Make a connection to the specified topic.
Definition: signal.hpp:104
void emit(Data data)
The primary purpose of the signal, to emit!
Definition: signal.hpp:128
Function loading component of a callback system.
Definition: slot.hpp:48


ecl_sigslots
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:48