Samchon Framework for CPP  1.0.0
samchon::library::ErrorEvent Class Reference

Event representing an error. More...

#include <ErrorEvent.hpp>

Collaboration diagram for samchon::library::ErrorEvent:

Public Member Functions

 ErrorEvent (EventDispatcher *, const std::string &)
 Construct from source and error-id. More...
 
auto getMessage () const -> std::string
 Get error-id. More...
 
- Public Member Functions inherited from samchon::library::Event
 Event (EventDispatcher *, int)
 Construct from source and type. More...
 
auto getSource () const -> EventDispatcher *
 Get source of the Event. More...
 
auto getType () const -> int
 Get type of the Event. More...
 

Protected Attributes

std::string message
 Error message. More...
 
- Protected Attributes inherited from samchon::library::Event
EventDispatchersource
 Source of the event. More...
 
int type
 Type of the event. More...
 

Detailed Description

Event representing an error.

[Inherited]

The Event class is used as the base class for the creation of Event objects, which are passed as parameters to event listeners when an event occurs.

The properties of the Event class carry basic information about an event, such as the event's type or source (who made the event) of the event.

For many events, such as the events represented by the Event class constants, this basic information is sufficient. Other events, however, may require more detailed information.

library_event.png
Example Source
1 #include <iostream>
2 #include <thread>
3 #include <chrono>
4 
5 #include <samchon/library/EventDispatcher.hpp>
6 #include <samchon/library/Event.hpp>
7 #include <samchon/library/ProgressEvent.hpp>
8 
9 #ifdef _WIN64
10 # ifdef _DEBUG
11 # pragma comment(lib, "x64/Debug/SamchonFramework.lib")
12 # else
13 # pragma comment(lib, "x64/Release/SamchonFramework.lib")
14 # endif
15 #else
16 # ifdef _DEBUG
17 # pragma comment(lib, "Debug/SamchonFramework.lib")
18 # else
19 # pragma comment(lib, "Release/SamchonFramework.lib")
20 # endif
21 #endif
22 
23 using namespace std;
24 using namespace samchon::library;
25 
26 class Process
27  : public EventDispatcher
28 {
29 public:
30  Process()
31  {
32 
33  };
34 
35  void run()
36  {
37  dispatchEvent(shared_ptr<Event>(new Event(this, Event::ACTIVATE)));
38 
39  for (size_t i = 0; i < 100; i++)
40  {
41  this_thread::sleep_for(chrono::seconds(1));
42  dispatchEvent(shared_ptr<Event>(new ProgressEvent(this, i + 1, 100)));
43  }
44 
45  dispatchEvent(shared_ptr<Event>(new Event(this, Event::COMPLETE)));
46  };
47 };
48 
49 void handleActivate(shared_ptr<Event> event)
50 {
51  cout << "Activated" << endl;
52 }
53 void handleComplete(shared_ptr<Event> event)
54 {
55  cout << "Completed" << endl;
56 }
57 void handleProgress(shared_ptr<Event> event)
58 {
59  cout << dynamic_pointer_cast<ProgressEvent>(event)->getPercent() * 100.0 << "%" << endl;
60 }
61 
62 void main()
63 {
64  Process process;
65 
66  process.addEventListener(Event::ACTIVATE, handleActivate);
67  process.addEventListener(Event::COMPLETE, handleComplete);
68  process.addEventListener(ProgressEvent::PROGRESS, handleProgress);
69 
70  process.run();
71  system("pause");
72 }
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
Event(EventDispatcher *, int)
Construct from source and type.
Definition: Event.cpp:5
Event representing a progress.
Abstract class for dispatching Event.
Deprecated:

Event is a candidate to be deprecated.

Since C++11, calling member method of a class by a new thread passing by static method and using void pointer are recommeded to avoid. As the reason, using std::thread and std::bind will be better.

See also
samchon::library
Author
Jeongho Nam http://samchon.org

Definition at line 19 of file ErrorEvent.hpp.

Constructor & Destructor Documentation

ErrorEvent::ErrorEvent ( EventDispatcher ,
const std::string &   
)

Construct from source and error-id.

The event object owns its source and type

Parameters
sourceSource of the event; who made the event
idAn error-id

Definition at line 7 of file ErrorEvent.cpp.

References message.

Member Function Documentation

auto ErrorEvent::getMessage ( ) const -> std::string

Get error-id.

Definition at line 12 of file ErrorEvent.cpp.

References message.

Member Data Documentation

std::string samchon::library::ErrorEvent::message
protected

Error message.

Definition at line 36 of file ErrorEvent.hpp.

Referenced by ErrorEvent(), and getMessage().


The documentation for this class was generated from the following files: