EnTT 3.14.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
entt::emitter< Derived, Allocator > Class Template Reference

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.
 
emitteroperator= (const emitter &)=delete
 Default copy assignment operator, deleted on purpose.
 
emitteroperator= (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.
 

Detailed Description

template<typename Derived, typename Allocator>
class entt::emitter< Derived, Allocator >

General purpose event emitter.

To create an emitter type, derived classes must inherit from the base as:

struct my_emitter: emitter<my_emitter> {
// ...
}
General purpose event emitter.
Definition emitter.hpp:36
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219

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.

Template Parameters
DerivedEmitter type.
AllocatorType of allocator used to manage memory and elements.

Definition at line 36 of file emitter.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Derived , typename Allocator >
using entt::emitter< Derived, Allocator >::allocator_type = Allocator

Allocator type.

Definition at line 46 of file emitter.hpp.

◆ size_type

template<typename Derived , typename Allocator >
using entt::emitter< Derived, Allocator >::size_type = std::size_t

Unsigned integer type.

Definition at line 48 of file emitter.hpp.

Constructor & Destructor Documentation

◆ emitter() [1/4]

template<typename Derived , typename Allocator >
entt::emitter< Derived, Allocator >::emitter ( )
inline

Default constructor.

Definition at line 51 of file emitter.hpp.

◆ emitter() [2/4]

template<typename Derived , typename Allocator >
entt::emitter< Derived, Allocator >::emitter ( const allocator_type & allocator)
inlineexplicit

Constructs an emitter with a given allocator.

Parameters
allocatorThe allocator to use.

Definition at line 58 of file emitter.hpp.

◆ emitter() [3/4]

template<typename Derived , typename Allocator >
entt::emitter< Derived, Allocator >::emitter ( emitter< Derived, Allocator > && other)
inlinenoexcept

Move constructor.

Parameters
otherThe instance to move from.

Definition at line 68 of file emitter.hpp.

◆ emitter() [4/4]

template<typename Derived , typename Allocator >
entt::emitter< Derived, Allocator >::emitter ( emitter< Derived, Allocator > && other,
const allocator_type & allocator )
inline

Allocator-extended move constructor.

Parameters
otherThe instance to move from.
allocatorThe allocator to use.

Definition at line 76 of file emitter.hpp.

◆ ~emitter()

template<typename Derived , typename Allocator >
virtual entt::emitter< Derived, Allocator >::~emitter ( )
inlinevirtual

Default destructor.

Definition at line 82 of file emitter.hpp.

Member Function Documentation

◆ clear()

template<typename Derived , typename Allocator >
void entt::emitter< Derived, Allocator >::clear ( )
inlinenoexcept

Disconnects all the listeners.

Definition at line 154 of file emitter.hpp.

◆ contains()

template<typename Derived , typename Allocator >
template<typename Type >
bool entt::emitter< Derived, Allocator >::contains ( ) const
inline

Checks if there are listeners registered for the specific event.

Template Parameters
TypeType of event to test.
Returns
True if there are no listeners registered, false otherwise.

Definition at line 164 of file emitter.hpp.

◆ empty()

template<typename Derived , typename Allocator >
bool entt::emitter< Derived, Allocator >::empty ( ) const
inlinenoexcept

Checks if there are listeners registered with the event emitter.

Returns
True if there are no listeners registered, false otherwise.

Definition at line 172 of file emitter.hpp.

◆ erase()

template<typename Derived , typename Allocator >
template<typename Type >
void entt::emitter< Derived, Allocator >::erase ( )
inline

Disconnects a listener from the event emitter.

Template Parameters
TypeType of event of the listener.

Definition at line 149 of file emitter.hpp.

◆ get_allocator()

template<typename Derived , typename Allocator >
constexpr allocator_type entt::emitter< Derived, Allocator >::get_allocator ( ) const
inlineconstexprnoexcept

Returns the associated allocator.

Returns
The associated allocator.

Definition at line 116 of file emitter.hpp.

◆ on()

template<typename Derived , typename Allocator >
template<typename Type >
void entt::emitter< Derived, Allocator >::on ( std::function< void(Type &, Derived &)> func)
inline

Registers a listener with the event emitter.

Template Parameters
TypeType of event to which to connect the listener.
Parameters
funcThe listener to register.

Definition at line 138 of file emitter.hpp.

◆ operator=() [1/2]

template<typename Derived , typename Allocator >
emitter & entt::emitter< Derived, Allocator >::operator= ( const emitter< Derived, Allocator > & )
delete

Default copy assignment operator, deleted on purpose.

Returns
This emitter.

◆ operator=() [2/2]

template<typename Derived , typename Allocator >
emitter & entt::emitter< Derived, Allocator >::operator= ( emitter< Derived, Allocator > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe instance to move from.
Returns
This emitter.

Definition at line 97 of file emitter.hpp.

◆ publish()

template<typename Derived , typename Allocator >
template<typename Type >
void entt::emitter< Derived, Allocator >::publish ( Type && value)
inline

Publishes a given event.

Template Parameters
TypeType of event to trigger.
Parameters
valueAn instance of the given type of event.

Definition at line 126 of file emitter.hpp.

◆ swap()

template<typename Derived , typename Allocator >
void entt::emitter< Derived, Allocator >::swap ( emitter< Derived, Allocator > & other)
inlinenoexcept

Exchanges the contents with those of a given emitter.

Parameters
otherEmitter to exchange the content with.

Definition at line 107 of file emitter.hpp.


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