General purpose event emitter. More...
#include <emitter.hpp>
Public Types | |
using | allocator_type = Allocator |
Allocator type. | |
using | size_type = std::size_t |
Unsigned integer type. | |
Public Member Functions | |
emitter () | |
Default constructor. | |
emitter (const allocator_type &allocator) | |
Constructs an emitter with a given allocator. | |
emitter (const emitter &)=delete | |
Default copy constructor, deleted on purpose. | |
emitter (emitter &&other) noexcept | |
Move constructor. | |
emitter (emitter &&other, const allocator_type &allocator) | |
Allocator-extended move constructor. | |
virtual | ~emitter () |
Default destructor. | |
emitter & | operator= (const emitter &)=delete |
Default copy assignment operator, deleted on purpose. | |
emitter & | operator= (emitter &&other) noexcept |
Move assignment operator. | |
void | swap (emitter &other) noexcept |
Exchanges the contents with those of a given emitter. | |
constexpr allocator_type | get_allocator () const noexcept |
Returns the associated allocator. | |
template<typename Type > | |
void | publish (Type &&value) |
Publishes a given event. | |
template<typename Type > | |
void | on (std::function< void(Type &, Derived &)> func) |
Registers a listener with the event emitter. | |
template<typename Type > | |
void | erase () |
Disconnects a listener from the event emitter. | |
void | clear () noexcept |
Disconnects all the listeners. | |
template<typename Type > | |
bool | contains () const |
Checks if there are listeners registered for the specific event. | |
bool | empty () const noexcept |
Checks if there are listeners registered with the event emitter. | |
General purpose event emitter.
To create an emitter type, derived classes must inherit from the base as:
Handlers for the different events are created internally on the fly. It's not required to specify in advance the full list of accepted events.
Moreover, whenever an event is published, an emitter also passes a reference to itself to its listeners.
Derived | Emitter type. |
Allocator | Type of allocator used to manage memory and elements. |
Definition at line 36 of file emitter.hpp.
using entt::emitter< Derived, Allocator >::allocator_type = Allocator |
Allocator type.
Definition at line 46 of file emitter.hpp.
using entt::emitter< Derived, Allocator >::size_type = std::size_t |
Unsigned integer type.
Definition at line 48 of file emitter.hpp.
|
inline |
Default constructor.
Definition at line 51 of file emitter.hpp.
|
inlineexplicit |
Constructs an emitter with a given allocator.
allocator | The allocator to use. |
Definition at line 58 of file emitter.hpp.
|
inlinenoexcept |
Move constructor.
other | The instance to move from. |
Definition at line 68 of file emitter.hpp.
|
inline |
Allocator-extended move constructor.
other | The instance to move from. |
allocator | The allocator to use. |
Definition at line 76 of file emitter.hpp.
|
inlinevirtual |
Default destructor.
Definition at line 82 of file emitter.hpp.
|
inlinenoexcept |
Disconnects all the listeners.
Definition at line 154 of file emitter.hpp.
|
inline |
Checks if there are listeners registered for the specific event.
Type | Type of event to test. |
Definition at line 164 of file emitter.hpp.
|
inlinenoexcept |
Checks if there are listeners registered with the event emitter.
Definition at line 172 of file emitter.hpp.
|
inline |
Disconnects a listener from the event emitter.
Type | Type of event of the listener. |
Definition at line 149 of file emitter.hpp.
|
inlineconstexprnoexcept |
Returns the associated allocator.
Definition at line 116 of file emitter.hpp.
|
inline |
Registers a listener with the event emitter.
Type | Type of event to which to connect the listener. |
func | The listener to register. |
Definition at line 138 of file emitter.hpp.
|
delete |
Default copy assignment operator, deleted on purpose.
|
inlinenoexcept |
Move assignment operator.
other | The instance to move from. |
Definition at line 97 of file emitter.hpp.
|
inline |
Publishes a given event.
Type | Type of event to trigger. |
value | An instance of the given type of event. |
Definition at line 126 of file emitter.hpp.
|
inlinenoexcept |
Exchanges the contents with those of a given emitter.
other | Emitter to exchange the content with. |
Definition at line 107 of file emitter.hpp.