|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Abstract base class for type-safe event tables. More...
#include <driven_table.H>
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_Handler * | read_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). | |
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).
| Signature | Function signature for events (e.g., void(int), int(double, bool)) |
Definition at line 136 of file driven_table.H.
| using Event_Table< Signature >::Event_Handler = std::function<Signature> |
Definition at line 139 of file driven_table.H.
|
virtualdefault |
Virtual destructor for proper cleanup in derived classes.
|
inlineprivate |
Append an event to the end of the table (internal use).
| fct | Event handler to append |
Definition at line 161 of file driven_table.H.
References Aleph::divide_and_conquer_partition_dp(), Event_Table< Signature >::size(), and Event_Table< Signature >::write_table().
Referenced by Event_Table< Signature >::register_event(), and Event_Table< void *(void *)>::register_event().
|
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.
Definition at line 233 of file driven_table.H.
|
protectedpure virtual |
Implemented in Static_Event_Table< Signature >, and Dynamic_Event_Table< Signature >.
Referenced by Event_Table< Signature >::unregister_event(), and Event_Table< void *(void *)>::unregister_event().
|
inline |
Execute the event at the given index with type-safe arguments.
Calls the registered event handler with the provided arguments.
| Args | Argument types (automatically deduced) |
| index | Slot index of event to execute |
| args | Arguments to pass to the event handler |
| range_error | if index is not in use |
Definition at line 249 of file driven_table.H.
References ah_range_error_if, Aleph::divide_and_conquer_partition_dp(), 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().
|
inline |
Check if an event is registered at the given index.
| index | Slot index to check |
Definition at line 220 of file driven_table.H.
References Aleph::and, Event_Table< Signature >::read_table(), and Event_Table< Signature >::size().
Referenced by Event_Table< void *(void *)>::check(), and TEST().
|
protectedpure virtual |
Implemented in Static_Event_Table< Signature >, and Dynamic_Event_Table< Signature >.
Referenced by Event_Table< void *(void *)>::check(), Event_Table< Signature >::execute_event(), Event_Table< void *(void *)>::execute_event(), Event_Table< Signature >::is_registered(), Event_Table< void *(void *)>::is_registered(), Event_Table< Signature >::register_event(), Event_Table< void *(void *)>::register_event(), Event_Table< Signature >::unregister_event(), and Event_Table< void *(void *)>::unregister_event().
|
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.
| Callable | Any callable compatible with Signature (lambda, function, functor) |
| fct | Event handler to register |
Definition at line 194 of file driven_table.H.
References Event_Table< Signature >::append_event_to_table(), Aleph::divide_and_conquer_partition_dp(), and Event_Table< Signature >::size().
|
inline |
Register an event at a specific index.
The index must be valid and must not already contain an event.
| Callable | Any callable compatible with Signature (lambda, function, functor) |
| index | Slot index where the event will be registered |
| fct | Event handler to register |
| range_error | if 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::divide_and_conquer_partition_dp(), Event_Table< Signature >::read_table(), Event_Table< Signature >::size(), and Event_Table< Signature >::write_table().
Referenced by run_legacy_example(), run_modern_example(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
pure virtual |
Get the number of event slots in the table.
Implemented in Static_Event_Table< Signature >, and Dynamic_Event_Table< Signature >.
Referenced by Event_Table< Signature >::append_event_to_table(), Event_Table< Signature >::execute_event(), Event_Table< Signature >::is_registered(), Event_Table< Signature >::register_event(), Event_Table< Signature >::register_event(), and Event_Table< Signature >::unregister_event().
|
inline |
Unregister an event at the given index.
The slot is cleared and can be reused later.
| index | Slot index to clear |
| range_error | if 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().
|
protectedpure virtual |
Implemented in Static_Event_Table< Signature >, and Dynamic_Event_Table< Signature >.
Referenced by Event_Table< Signature >::append_event_to_table(), Event_Table< void *(void *)>::append_event_to_table(), Event_Table< Signature >::register_event(), and Event_Table< void *(void *)>::register_event().