Go to the documentation of this file.00001
00009
00010
00011
00012
00013 #include <iostream>
00014 #include "../../include/ecl/sigslots.hpp"
00015
00016
00017
00018
00019
00020 using ecl::Signal;
00021 using ecl::Slot;
00022 using ecl::SigSlotsManager;
00023
00028
00029
00030
00031
00032 void f() {
00033 std::cout << " ---> Hey Dude" << std::endl;
00034 }
00035
00036 void g() {
00037 std::cout << " ---> Hey Chained Dude" << std::endl;
00038 }
00039
00040 void h(const int& i) {
00041 std::cout << " ---> Hey Data Dude: " << i << std::endl;
00042 }
00043
00044
00045
00046
00047
00048 class A {
00049 public:
00050 A() : slot(&A::f,*this), slot_data(&A::g,*this) {
00051 slot.connect("Dudette");
00052 slot_data.connect("DataDudette");
00053 };
00054
00055 void f() {
00056 std::cout << " ---> Hey Dudette" << std::endl;
00057 }
00058 void g(const int& i) {
00059 std::cout << " ---> Hey Data Dudette: " << i << std::endl;
00060 }
00061 Slot<> slot;
00062 Slot<const int&> slot_data;
00063 };
00064
00068
00069
00070
00071
00072 int main(int argc, char **argv) {
00073
00074 std::cout << "Hello dude" << std::endl;
00075
00076 std::cout << std::endl;
00077 std::cout << "***************************************************************" << std::endl;
00078 std::cout << "* Global Function" << std::endl;
00079 std::cout << "***************************************************************" << std::endl;
00080 std::cout << std::endl;
00081 Slot<> slot1(&f);
00082 Slot<> slot2(&f);
00083 std::cout << "Connecting 1 signal and two slots to 'Dude'" << std::endl;
00084 slot1.connect("Dude");
00085 slot2.connect("Dude");
00086 Signal<> signal;
00087 signal.connect("Dude");
00088 std::cout << "Emitting" << std::endl;
00089 signal.emit();
00090 std::cout << std::endl;
00091 SigSlotsManager<>::printStatistics();
00092 std::cout << std::endl;
00093
00094 std::cout << "Connecting a data slot-signal pair to 'DataDude'" << std::endl;
00095 Slot<const int&> slot_data_1(&h);
00096 Signal<const int&> sig_data_1;
00097 slot_data_1.connect("DataDude");
00098 sig_data_1.connect("DataDude");
00099 std::cout << "Emitting" << std::endl;
00100 sig_data_1.emit(2);
00101 std::cout << std::endl;
00102 SigSlotsManager<const int&>::printStatistics();
00103
00104 std::cout << std::endl;
00105 std::cout << "***************************************************************" << std::endl;
00106 std::cout << "* Disconnects" << std::endl;
00107 std::cout << "***************************************************************" << std::endl;
00108 std::cout << std::endl;
00109
00110 std::cout << "Disconnecting second slot" << std::endl;
00111 slot2.disconnect();
00112 std::cout << "Emitting" << std::endl;
00113 signal.emit();
00114 std::cout << "Disconnecting signal" << std::endl;
00115 signal.disconnect();
00116 std::cout << "Emitting (to nowhere)" << std::endl;
00117 signal.emit();
00118 std::cout << std::endl;
00119 SigSlotsManager<>::printStatistics();
00120
00121 std::cout << std::endl;
00122 std::cout << "***************************************************************" << std::endl;
00123 std::cout << "* Relays" << std::endl;
00124 std::cout << "***************************************************************" << std::endl;
00125 std::cout << std::endl;
00126
00127 std::cout << "Connecting signal and second slot back to 'Dude'" << std::endl;
00128 slot2.connect("Dude");
00129 signal.connect("Dude");
00130 std::cout << std::endl;
00131 SigSlotsManager<>::printStatistics();
00132 std::cout << std::endl;
00133
00134 Signal<> signal_relay;
00135 std::cout << "Connecting relay as signal to 'ChainedDude'" << std::endl;
00136 signal_relay.connect("ChainedDude");
00137 std::cout << "Connecting relay as slot to 'Dude'." << std::endl;
00138 signal_relay.connectAsSlot("Dude");
00139 Slot<> slot3(&g);
00140 std::cout << "Connecting slot to 'ChainedDude'" << std::endl;
00141 slot3.connect("ChainedDude");
00142 std::cout << "Emitting" << std::endl;
00143 signal.emit();
00144 std::cout << std::endl;
00145 SigSlotsManager<>::printStatistics();
00146
00147 std::cout << std::endl;
00148 std::cout << "***************************************************************" << std::endl;
00149 std::cout << "* Member Functions" << std::endl;
00150 std::cout << "***************************************************************" << std::endl;
00151 std::cout << std::endl;
00152
00153 std::cout << "Creating a member slot and connecting to 'Dudette'" << std::endl;
00154 A a;
00155 std::cout << "Connecting a signal to 'Dudette'" << std::endl;
00156 Signal<> signal_dudette;
00157 signal_dudette.connect("Dudette");
00158 signal_dudette.emit();
00159 SigSlotsManager<>::printStatistics();
00160 std::cout << std::endl;
00161
00162 std::cout << "Creating a member data slot and connecting to 'DataDudette'" << std::endl;
00163 std::cout << "Connecting a data signal to 'DataDudette'" << std::endl;
00164 Signal<const int&> signal_data_dudette;
00165 signal_data_dudette.connect("DataDudette");
00166 signal_data_dudette.emit(3);
00167 std::cout << std::endl;
00168 SigSlotsManager<const int&>::printStatistics();
00169
00170 return 0;
00171 }