An example using event module.
More...
An example using event module.
- Example Source
5 #include <samchon/library/EventDispatcher.hpp> 6 #include <samchon/library/Event.hpp> 7 #include <samchon/library/ProgressEvent.hpp> 11 # pragma comment(lib, "x64/Debug/SamchonFramework.lib") 13 # pragma comment(lib, "x64/Release/SamchonFramework.lib") 17 # pragma comment(lib, "Debug/SamchonFramework.lib") 19 # pragma comment(lib, "Release/SamchonFramework.lib") 37 dispatchEvent(shared_ptr<Event>(
new Event(
this, Event::ACTIVATE)));
39 for (
size_t i = 0; i < 100; i++)
41 this_thread::sleep_for(chrono::seconds(1));
42 dispatchEvent(shared_ptr<Event>(
new ProgressEvent(
this, i + 1, 100)));
45 dispatchEvent(shared_ptr<Event>(
new Event(
this, Event::COMPLETE)));
49 void handleActivate(shared_ptr<Event> event)
51 cout <<
"Activated" << endl;
53 void handleComplete(shared_ptr<Event> event)
55 cout <<
"Completed" << endl;
57 void handleProgress(shared_ptr<Event> event)
59 cout << dynamic_pointer_cast<ProgressEvent>(event)->getPercent() * 100.0 <<
"%" << endl;
66 process.addEventListener(Event::ACTIVATE, handleActivate);
67 process.addEventListener(Event::COMPLETE, handleComplete);
68 process.addEventListener(ProgressEvent::PROGRESS, handleProgress);
Represent an event running on background.
Event representing a progress.
Abstract class for dispatching Event.
- See also
- library::Event
-
library::StaticEventDispatcher
- Author
- Jeongho Nam http://samchon.org