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

Fixed-size event table implementation. More...

#include <driven_table.H>

Inheritance diagram for Static_Event_Table< Signature >:
[legend]
Collaboration diagram for Static_Event_Table< Signature >:
[legend]

Public Types

using Event_Handler = typename Event_Table< Signature >::Event_Handler
 
- Public Types inherited from Event_Table< Signature >
using Event_Handler = std::function< Signature >
 

Public Member Functions

size_t size () const override
 Get table size (implements Event_Table virtual method)
 
 Static_Event_Table (const size_t num_events=0)
 Construct a static event table with a fixed size.
 
 Static_Event_Table (const Static_Event_Table &)=delete
 Copying disabled (events may contain non-copyable captures)
 
Static_Event_Tableoperator= (const Static_Event_Table &)=delete
 
 Static_Event_Table (Static_Event_Table &&other) noexcept
 Move constructor - transfers ownership of the array.
 
Static_Event_Tableoperator= (Static_Event_Table &&other) noexcept
 Move assignment - transfers ownership of the array.
 
 ~Static_Event_Table () override=default
 Destructor - automatically frees the underlying array.
 
- Public Member Functions inherited from Event_Table< Signature >
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.
 

Private Member Functions

void verify_index (const size_t i) const
 Verify index is within valid range.
 
const Event_Handlerread_table (const size_t i) const override
 Read event at index (implements Event_Table virtual method)
 
void write_table (const size_t i, Event_Handler &&event_fct) override
 Write event at index (implements Event_Table virtual method)
 
void clear_slot (size_t i) override
 Clear event at index (implements Event_Table virtual method)
 

Private Attributes

std::unique_ptr< Event_Handler[]> table
 Array of event handlers.
 
size_t size_table
 Fixed size of the table.
 

Additional Inherited Members

Detailed Description

template<typename Signature>
class Static_Event_Table< Signature >

Fixed-size event table implementation.

Uses a fixed-size array of event handlers. The size is determined at construction and cannot be changed afterward. Suitable when the number of possible events is known in advance.

Warning
The auto-append overload register_event(fct) (without an explicit index) is not supported on static tables and will always throw range_error. Use register_event(index, fct) instead.
Template Parameters
SignatureFunction signature for events (e.g., void(int), int(double, bool))

Memory Management

  • Owns the underlying array (managed by std::unique_ptr)
  • Non-copyable (events may contain non-copyable captures)
  • Moveable (transfers ownership of the array)
Complexity
  • Space: O(n) where n is table size
  • register_event: O(1)
  • unregister_event: O(1)
  • execute_event: O(1)

Definition at line 378 of file driven_table.H.

Member Typedef Documentation

◆ Event_Handler

template<typename Signature >
using Static_Event_Table< Signature >::Event_Handler = typename Event_Table<Signature>::Event_Handler

Definition at line 381 of file driven_table.H.

Constructor & Destructor Documentation

◆ Static_Event_Table() [1/3]

template<typename Signature >
Static_Event_Table< Signature >::Static_Event_Table ( const size_t  num_events = 0)
inlineexplicit

Construct a static event table with a fixed size.

All event slots are initialized to empty.

Parameters
num_eventsNumber of event slots to allocate (default: 0)

Definition at line 427 of file driven_table.H.

◆ Static_Event_Table() [2/3]

Copying disabled (events may contain non-copyable captures)

◆ Static_Event_Table() [3/3]

Move constructor - transfers ownership of the array.

The moved-from object is left in a valid but empty state.

Parameters
otherTable to move from (will be emptied)

Definition at line 444 of file driven_table.H.

References Aleph::maps().

◆ ~Static_Event_Table()

template<typename Signature >
Static_Event_Table< Signature >::~Static_Event_Table ( )
overridedefault

Destructor - automatically frees the underlying array.

Member Function Documentation

◆ clear_slot()

template<typename Signature >
void Static_Event_Table< Signature >::clear_slot ( size_t  i)
inlineoverrideprivatevirtual

Clear event at index (implements Event_Table virtual method)

Implements Event_Table< Signature >.

Definition at line 411 of file driven_table.H.

References Static_Event_Table< Signature >::table, and Static_Event_Table< Signature >::verify_index().

◆ operator=() [1/2]

◆ operator=() [2/2]

Move assignment - transfers ownership of the array.

Deletes the current array and takes ownership of other's array.

Parameters
otherTable to move from (will be emptied)
Returns
Reference to this

Definition at line 457 of file driven_table.H.

References Aleph::maps(), Static_Event_Table< Signature >::size_table, and Static_Event_Table< Signature >::table.

◆ read_table()

template<typename Signature >
const Event_Handler * Static_Event_Table< Signature >::read_table ( const size_t  i) const
inlineoverrideprivatevirtual

Read event at index (implements Event_Table virtual method)

Implements Event_Table< Signature >.

Definition at line 397 of file driven_table.H.

References Static_Event_Table< Signature >::table, and Static_Event_Table< Signature >::verify_index().

◆ size()

template<typename Signature >
size_t Static_Event_Table< Signature >::size ( ) const
inlineoverridevirtual

Get table size (implements Event_Table virtual method)

Implements Event_Table< Signature >.

Definition at line 419 of file driven_table.H.

References Static_Event_Table< Signature >::size_table.

Referenced by TEST(), and TEST().

◆ verify_index()

template<typename Signature >
void Static_Event_Table< Signature >::verify_index ( const size_t  i) const
inlineprivate

Verify index is within valid range.

Parameters
iIndex to verify
Exceptions
range_errorif the index is out of bounds

Definition at line 391 of file driven_table.H.

References ah_range_error_if, and Static_Event_Table< Signature >::size_table.

Referenced by Static_Event_Table< Signature >::clear_slot(), Static_Event_Table< Signature >::read_table(), and Static_Event_Table< Signature >::write_table().

◆ write_table()

template<typename Signature >
void Static_Event_Table< Signature >::write_table ( const size_t  i,
Event_Handler &&  event_fct 
)
inlineoverrideprivatevirtual

Write event at index (implements Event_Table virtual method)

Implements Event_Table< Signature >.

Definition at line 404 of file driven_table.H.

References Aleph::maps(), Static_Event_Table< Signature >::table, and Static_Event_Table< Signature >::verify_index().

Member Data Documentation

◆ size_table

◆ table


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