Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
driven_table.H File Reference

Event-driven table abstraction for event-driven simulations. More...

#include <aleph.H>
#include <tpl_dynArray.H>
#include <ah-errors.H>
#include <functional>
#include <memory>
#include <type_traits>
Include dependency graph for driven_table.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Event_Table< Signature >
 Abstract base class for type-safe event tables. More...
 
class  Event_Table< void *(void *)>
 Specialization of Event_Table for legacy void*(void*) signature. More...
 
class  Static_Event_Table< Signature >
 Fixed-size event table implementation. More...
 
class  Dynamic_Event_Table< Signature >
 Dynamic (growable) event table implementation. More...
 

Typedefs

typedef void *(* Event_Fct) (void *)
 Type alias for legacy event handler functions.
 
using Legacy_Static_Event_Table = Static_Event_Table< void *(void *)>
 Legacy event table type (uses void* for input/output).
 
using Legacy_Dynamic_Event_Table = Dynamic_Event_Table< void *(void *)>
 Legacy dynamic event table type (uses void* for input/output).
 

Detailed Description

Event-driven table abstraction for event-driven simulations.

This file provides type-safe event tables for managing event handlers in event-driven simulations and frameworks. Events can be registered as function pointers, lambdas, functors, or std::function objects, with compile-time type safety for arguments and return values.

Overview

Event tables map integer indices to event handler callables. Two implementations are provided:

Both implementations are templated on the event signature, allowing type-safe event handlers with arbitrary arguments and return types.

Use Cases

  • Event-driven simulations (discrete event simulation)
  • State machines with numbered states/transitions
  • Command dispatch tables
  • Plugin systems with dynamic event registration
Modern Example (with lambdas and type safety)
// Define type-safe event table for events that take an int and return void
Dynamic_Event_Table<void(int)> table;
// Register lambda
auto start_id = table.register_event([](int x) {
std::cout << "Starting with " << x << "\n";
});
// Register function
auto stop_id = table.register_event([](int x) {
std::cout << "Stopping with " << x << "\n";
});
// Execute events with type-safe arguments
table.execute_event(start_id, 42);
table.execute_event(stop_id, 100);
Dynamic (growable) event table implementation.
void register_event(const size_t index, Callable &&fct)
Register an event at a specific index.
auto execute_event(const size_t index, Args &&... args) const
Execute the event at the given index with type-safe arguments.
Legacy Example (backward compatible)
// Old style still works for compatibility
void* on_start(void* data) {
std::cout << "Starting...\n";
return nullptr;
}
Legacy_Static_Event_Table table; // or Legacy_Dynamic_Event_Table
auto id = table.register_event(on_start);
table.execute_event(id, nullptr);
Fixed-size event table implementation.
Author
Leandro Rabindranath León

Definition in file driven_table.H.

Typedef Documentation

◆ Event_Fct

typedef void *(* Event_Fct) (void *)

Type alias for legacy event handler functions.

Event functions take a void* input parameter and return a void* result. This allows arbitrary data to be passed to and returned from events.

Deprecated:
Use templated Event_Table with std::function instead for type safety.

Definition at line 112 of file driven_table.H.

◆ Legacy_Dynamic_Event_Table

Legacy dynamic event table type (uses void* for input/output).

Deprecated:
Use templated Dynamic_Event_Table<Signature> for type safety.

This alias maintains backward compatibility with code using the old Dynamic_Event_Table interface with void* event handlers.

Definition at line 595 of file driven_table.H.

◆ Legacy_Static_Event_Table

Legacy event table type (uses void* for input/output).

Deprecated:
Use templated Event_Table<Signature> for type safety.

This alias maintains backward compatibility with code using the old Event_Table interface with void* event handlers.

Definition at line 586 of file driven_table.H.