Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Public Member Functions | Protected Attributes | List of all members
Sharp::EventBase< T > Class Template Reference

#include <Event.hpp>

Inheritance diagram for Sharp::EventBase< T >:
Sharp::Event< T >

Public Member Functions

 EventBase ()
 
virtual ~EventBase ()
 
EventBase< T > & operator+= (EventHandlerImpl< T > *pHandlerToAdd)
 
EventBase< T > & operator-= (EventHandlerImpl< T > *pHandlerToRemove)
 

Protected Attributes

eastl::list< EventHandlerImpl< T > * > m_eventHandlers
 

Detailed Description

template<typename T>
class Sharp::EventBase< T >

Sharp Event provide an event mechanism that is similar to that found in C#

myEvent += EventHandler::Bind(&ThisClass::OnMessage, this);

// called inside ThisClass constructor as recommended

Author
Amer Saffo

Definition at line 413 of file Event.hpp.

Constructor & Destructor Documentation

template<typename T>
Sharp::EventBase< T >::EventBase ( )
inline

Definition at line 416 of file Event.hpp.

template<typename T>
virtual Sharp::EventBase< T >::~EventBase ( )
inlinevirtual

it is by design that Event is the owner of the memory of all the handlers assigned to it so it is the duty of the destructor to erase that memory

See also
Eventhandler Bind function documentation for more details

Definition at line 423 of file Event.hpp.

Member Function Documentation

template<typename T>
EventBase<T>& Sharp::EventBase< T >::operator+= ( EventHandlerImpl< T > *  pHandlerToAdd)
inline

This is how you connect a handler to this event.

myEvent += EventHandler::Bind(&ThisClass::OnMessage, this);

// example of binding inside ThisClass constructor as recommended

myEvent -= EventHandler::Bind(&ThisClass::OnMessage, this);

// example of unbinding in destructor

Note
: You can Bind to a private member function as long as you have access to that private function at the time of binding (i.e binding from within the class).
on memory: As a rule of thumb, always bind in the constructor and unbind in the destructor. However, you can go lazy and rely on the Event destructor to unbind if: [1] if you are passing [this] to EventHandler::Bind() AND the event is a member, which is the most common scenario. as that means the member event object will be automatically destroyed by the class destructor. [2] or if you binded to a non member function, as those are never destroyed. In short, before your binded class instance is destroyed, make sure to unbind it. Otherwise, the binded event might try to make a call through your destroyed instance.
: For completeness, you are warned NOT to store the returned value of Eventhandler::Bind() yourself, as after this call, Event becomes the owner of the implicitly created EventHandlerImpl<T> and it later destroys it.

Definition at line 455 of file Event.hpp.

template<typename T>
EventBase<T>& Sharp::EventBase< T >::operator-= ( EventHandlerImpl< T > *  pHandlerToRemove)
inline

you can use this to remove a handler you previously added.

Note
: removing a handler that was already removed is harmless, as this call does nothing and simply return when it does not find the handler.
myEvent -= EventHandler::Bind(&ThisClass::OnMessage, this);
// example of unbinding in destructor

Definition at line 480 of file Event.hpp.

Member Data Documentation

template<typename T>
eastl::list< EventHandlerImpl<T>* > Sharp::EventBase< T >::m_eventHandlers
protected

Definition at line 537 of file Event.hpp.


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