#include <Pt/Event.h>
Base class for typed events. More...
Inherited by BasicEvent< ActivateEvent >, BasicEvent< CloseEvent >, BasicEvent< EnableEvent >, BasicEvent< EnterEvent >, BasicEvent< FocusEvent >, BasicEvent< InvalidateEvent >, BasicEvent< KeyEvent >, BasicEvent< LayoutEvent >, BasicEvent< LeaveEvent >, BasicEvent< MeasureEvent >, BasicEvent< MouseEvent >, BasicEvent< MoveEvent >, BasicEvent< PaintEvent >, BasicEvent< RescaleEvent >, BasicEvent< ResizeEvent >, BasicEvent< ScrollEvent >, BasicEvent< ShowEvent >, BasicEvent< TouchEvent >, BasicEvent< WindowStateEvent >, and BasicEvent< T >.
Public Member Functions | |
| virtual | ~Event () |
| Destructor. | |
| Event & | clone (Allocator &allocator) const |
| Clones this event using an allocator. | |
| void | destroy (Allocator &allocator) |
| Destroys this event using an allocator. | |
| const std::type_info & | typeInfo () const |
| Returns the type info for this class of events. | |
Static Public Member Functions | |
| template<typename EventT> | |
| static Event & | copyConstruct (const EventT &ev, Allocator &allocator) |
| Copies an event using an allocator. | |
| template<typename EventT> | |
| static void | destruct (EventT &ev, Allocator &allocator) |
| Destructs an event using an allocator. | |
Protected Member Functions | |
| Event () | |
| Constructor. | |
| virtual Event & | onClone (Allocator &allocator) const =0 |
| Clones this event using an allocator. | |
| virtual void | onDestroy (Allocator &allocator)=0 |
| Destroys this event using an allocator. | |
| virtual const std::type_info & | onTypeInfo () const =0 |
| Returns the type info for this class of events. | |
Event is the base of every event that an event loop can copy and dispatch. A loop does not know the concrete type when it stores an event, so the event clones itself into an Allocator, destroys itself from that allocator, and reports a std::type_info that identifies the dynamic type. Slots subscribe to that type.
clone() and destroy() forward to onClone() and onDestroy(). typeInfo() forwards to onTypeInfo(). A derived class that does not use BasicEvent must implement those three hooks. clone() returns a new object of the same dynamic type, allocated from the given allocator. destroy() undoes that allocation. The allocator is the loop's; the event does not own it.
copyConstruct() and destruct() are helpers for those hooks. They placement-new and destroy a concrete EventT through the allocator. Prefer BasicEvent, which already calls them.
Do not slice an Event. Copying the base is not allowed as a value; the type is meant to be cloned through the allocator. Destroy an event only with the allocator that cloned it.