Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Event_Table< Signature > Class Template Referenceabstract

Abstract base class for type-safe event tables. More...

#include <driven_table.H>

Inheritance diagram for Event_Table< Signature >:
[legend]

Public Types

using Event_Handler = std::function< Signature >
 

Public Member Functions

virtual size_t size () const =0
 Get the number of event slots in the table.
 
virtual ~Event_Table ()=default
 Virtual destructor for proper cleanup in derived classes.
 
template<typename Callable >
void register_event (const size_t index, Callable &&fct)
 Register an event at a specific index.
 
template<typename Callable >
size_t register_event (Callable &&fct)
 Append a new event and return its auto-assigned index.
 
void unregister_event (const size_t index)
 Unregister an event at the given index.
 
bool is_registered (const size_t index) const
 Check if an event is registered at the given index.
 
template<typename F >
bool check (const size_t, F) const
 Legacy check method (for backward compatibility).
 
template<typename... Args>
auto execute_event (const size_t index, Args &&... args) const
 Execute the event at the given index with type-safe arguments.
 

Protected Member Functions

virtual const Event_Handlerread_table (size_t i) const =0
 
virtual void write_table (size_t i, Event_Handler &&event_fct)=0
 
virtual void clear_slot (size_t i)=0
 

Private Member Functions

void append_event_to_table (Event_Handler &&fct)
 Append an event to the end of the table (internal use).
 

Detailed Description

template<typename Signature>
class Event_Table< Signature >

Abstract base class for type-safe event tables.

Provides an interface for registering, unregistering, checking, and executing events with compile-time type safety. Concrete implementations must provide a storage mechanism (static array or dynamic array).

Template Parameters
SignatureFunction signature for events (e.g., void(int), int(double, bool))

Operations

  • register_event(index, fct): Register event at specific index
  • register_event(fct): Append event and return auto-assigned index
  • unregister_event(index): Remove event at index
  • execute_event(index, args...): Execute event with type-safe arguments
  • is_registered(index): Check if an event is registered at index
Thread Safety
Not thread-safe. Use external synchronization if accessing from multiple threads.

Definition at line 136 of file driven_table.H.

Member Typedef Documentation

◆ Event_Handler

template<typename Signature >
using Event_Table< Signature >::Event_Handler = std::function<Signature>

Definition at line 139 of file driven_table.H.

Constructor & Destructor Documentation

◆ ~Event_Table()

template<typename Signature >
virtual Event_Table< Signature >::~Event_Table ( )
virtualdefault

Virtual destructor for proper cleanup in derived classes.

Member Function Documentation

◆ append_event_to_table()

template<typename Signature >
void Event_Table< Signature >::append_event_to_table ( Event_Handler &&  fct)
inlineprivate

Append an event to the end of the table (internal use).

Parameters
fctEvent handler to append

Definition at line 161 of file driven_table.H.

References Aleph::maps(), Event_Table< Signature >::size(), and Event_Table< Signature >::write_table().

Referenced by Event_Table< Signature >::register_event(), and Event_Table< void *(void *)>::register_event().

◆ check()

template<typename Signature >
template<typename F >
bool Event_Table< Signature >::check ( const size_t  ,
F   
) const
inline

Legacy check method (for backward compatibility).

For templated event tables, this always returns false since we cannot compare std::function objects. Use is_registered() instead.

Deprecated:
Use is_registered() instead

Definition at line 233 of file driven_table.H.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ clear_slot()

◆ execute_event()

template<typename Signature >
template<typename... Args>
auto Event_Table< Signature >::execute_event ( const size_t  index,
Args &&...  args 
) const
inline

Execute the event at the given index with type-safe arguments.

Calls the registered event handler with the provided arguments.

Template Parameters
ArgsArgument types (automatically deduced)
Parameters
indexSlot index of event to execute
argsArguments to pass to the event handler
Returns
Result returned by the event handler
Exceptions
range_errorif index is not in use

Definition at line 249 of file driven_table.H.

References ah_range_error_if, Aleph::maps(), Event_Table< Signature >::read_table(), and Event_Table< Signature >::size().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ is_registered()

template<typename Signature >
bool Event_Table< Signature >::is_registered ( const size_t  index) const
inline

Check if an event is registered at the given index.

Parameters
indexSlot index to check
Returns
true if an event is registered at the index, false otherwise

Definition at line 220 of file driven_table.H.

References Aleph::maps(), Event_Table< Signature >::read_table(), and Event_Table< Signature >::size().

Referenced by Event_Table< void *(void *)>::check(), and TEST().

◆ read_table()

◆ register_event() [1/2]

template<typename Signature >
template<typename Callable >
size_t Event_Table< Signature >::register_event ( Callable &&  fct)
inline

Append a new event and return its auto-assigned index.

The event is registered at the next available slot at the end of the table.

Template Parameters
CallableAny callable compatible with Signature (lambda, function, functor)
Parameters
fctEvent handler to register
Returns
Index where the event was registered

Definition at line 194 of file driven_table.H.

References Event_Table< Signature >::append_event_to_table(), Aleph::maps(), and Event_Table< Signature >::size().

◆ register_event() [2/2]

template<typename Signature >
template<typename Callable >
void Event_Table< Signature >::register_event ( const size_t  index,
Callable &&  fct 
)
inline

Register an event at a specific index.

The index must be valid and must not already contain an event.

Template Parameters
CallableAny callable compatible with Signature (lambda, function, functor)
Parameters
indexSlot index where the event will be registered
fctEvent handler to register
Exceptions
range_errorif the index is out of range or already in use

Definition at line 177 of file driven_table.H.

References ah_range_error_if, Aleph::maps(), Event_Table< Signature >::read_table(), Event_Table< Signature >::size(), and Event_Table< Signature >::write_table().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ size()

◆ unregister_event()

template<typename Signature >
void Event_Table< Signature >::unregister_event ( const size_t  index)
inline

Unregister an event at the given index.

The slot is cleared and can be reused later.

Parameters
indexSlot index to clear
Exceptions
range_errorif the index is out of range or slot is not in use

Definition at line 207 of file driven_table.H.

References ah_range_error_if, Event_Table< Signature >::clear_slot(), Event_Table< Signature >::read_table(), and Event_Table< Signature >::size().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ write_table()


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