|
|
|
@ -1,12 +1,12 @@ |
|
|
|
|
// // #define NUM_OF_RUNNERS 2
|
|
|
|
|
|
|
|
|
|
#include "../lib/asynco.hpp" |
|
|
|
|
#include "../lib/event.hpp" |
|
|
|
|
#include "../lib/trigger.hpp" |
|
|
|
|
#include "../lib/filesystem.hpp" |
|
|
|
|
#include "../lib/timers.hpp" |
|
|
|
|
|
|
|
|
|
using namespace marcelb::asynco; |
|
|
|
|
using namespace events; |
|
|
|
|
using namespace triggers; |
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
#include <unistd.h> |
|
|
|
@ -53,9 +53,9 @@ class clm { |
|
|
|
|
|
|
|
|
|
// ------------------ EXTEND OWN CLASS WITH EVENTS -------------------
|
|
|
|
|
|
|
|
|
|
class myOwnClass : public event<int> { |
|
|
|
|
class myOwnClass : public trigger<int> { |
|
|
|
|
public: |
|
|
|
|
myOwnClass() : event() {}; |
|
|
|
|
myOwnClass() : trigger() {}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -216,74 +216,74 @@ int main () { |
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// // --------------- EVENTS -------------------
|
|
|
|
|
// --------------- EVENTS -------------------
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * initialization of typed events
|
|
|
|
|
// */
|
|
|
|
|
/**
|
|
|
|
|
* initialization of typed events |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// event<int, int> ev2int;
|
|
|
|
|
// event<int, string> evintString;
|
|
|
|
|
// event<> evoid;
|
|
|
|
|
trigger<int, int> ev2int; |
|
|
|
|
trigger<int, string> evintString; |
|
|
|
|
trigger<> evoid; |
|
|
|
|
|
|
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
|
// cout << "Sum " << a+b << endl;
|
|
|
|
|
// });
|
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
|
cout << "Sum " << a+b << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// ev2int.on("sum", [](int a, int b) {
|
|
|
|
|
// cout << "Sum done" << endl;
|
|
|
|
|
// });
|
|
|
|
|
ev2int.on("sum", [](int a, int b) { |
|
|
|
|
cout << "Sum done" << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// evintString.on("substract", [](int a, string b) {
|
|
|
|
|
// cout << "Substract " << a-stoi(b) << endl;
|
|
|
|
|
// });
|
|
|
|
|
evintString.on("substract", [](int a, string b) { |
|
|
|
|
cout << "Substract " << a-stoi(b) << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// evoid.on("void", []() {
|
|
|
|
|
// cout << "Void emited" << endl;
|
|
|
|
|
// });
|
|
|
|
|
evoid.on("void", []() { |
|
|
|
|
cout << "Void emited" << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// string emited2 = "2";
|
|
|
|
|
string emited2 = "2"; |
|
|
|
|
|
|
|
|
|
// evoid.on("void", [&]() {
|
|
|
|
|
// cout << "Void emited " << emited2 << endl;
|
|
|
|
|
// });
|
|
|
|
|
evoid.on("void", [&]() { |
|
|
|
|
cout << "Void emited " << emited2 << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// evoid.emit("void");
|
|
|
|
|
// sleep(1);
|
|
|
|
|
evoid.tick("void"); |
|
|
|
|
sleep(1); |
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Emit
|
|
|
|
|
// */
|
|
|
|
|
/**
|
|
|
|
|
* Emit |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// ev2int.emit("sum", 5, 8);
|
|
|
|
|
ev2int.tick("sum", 5, 8); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sleep(1);
|
|
|
|
|
// evintString.emit("substract", 3, to_string(2));
|
|
|
|
|
sleep(1); |
|
|
|
|
evintString.tick("substract", 3, to_string(2)); |
|
|
|
|
|
|
|
|
|
// sleep(1);
|
|
|
|
|
// evoid.off("void");
|
|
|
|
|
// evoid.emit("void");
|
|
|
|
|
sleep(1); |
|
|
|
|
evoid.off("void"); |
|
|
|
|
evoid.tick("void"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners() << endl;
|
|
|
|
|
// cout << "Ukupno evintString " << evintString.listeners() << endl;
|
|
|
|
|
// cout << "Ukupno evoid " << evoid.listeners() << endl;
|
|
|
|
|
// cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl;
|
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners() << endl; |
|
|
|
|
cout << "Ukupno evintString " << evintString.listeners() << endl; |
|
|
|
|
cout << "Ukupno evoid " << evoid.listeners() << endl; |
|
|
|
|
cout << "Ukupno 2 int " << ev2int.listeners("sum") << endl; |
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Own class
|
|
|
|
|
// */
|
|
|
|
|
/**
|
|
|
|
|
* Own class
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
// myOwnClass myclass;
|
|
|
|
|
myOwnClass myclass; |
|
|
|
|
|
|
|
|
|
// delayed t( [&] {
|
|
|
|
|
// myclass.emit("constructed", 1);
|
|
|
|
|
// }, 200);
|
|
|
|
|
delayed t( [&] { |
|
|
|
|
myclass.tick("constructed", 1); |
|
|
|
|
}, 200); |
|
|
|
|
|
|
|
|
|
// myclass.on("constructed", [] (int i) {
|
|
|
|
|
// cout << "Constructed " << i << endl;
|
|
|
|
|
// });
|
|
|
|
|
myclass.on("constructed", [] (int i) { |
|
|
|
|
cout << "Constructed " << i << endl; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|