|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Tree-based command dispatcher. More...
#include <ah-dispatcher.H>
Public Member Functions | |
| AHDispatcher ()=default | |
| Default constructor. | |
| template<typename ... Pairs> | |
| AHDispatcher (const Key &key, Operation op, Pairs ... pairs) | |
| Variadic constructor for initializing with key-operation pairs. | |
| void | insert (const Key &key, Operation op) |
| Register a key-operation pair. | |
| template<typename ... Args> | |
| auto | run (const Key &key, Args &&... args) const |
| Execute the operation associated with a key. | |
| void | remove (const Key &key) |
| Remove a key-operation pair. | |
| bool | valid_key (const Key &key) |
| Check if a key is registered. | |
| DynList< Key > | keys () const |
| Get all registered keys. | |
| size_t | size () const |
| Get the number of registered operations. | |
| bool | is_empty () const |
| Check if the dispatcher is empty. | |
Private Attributes | |
| DynMapTree< Key, Operation > | tbl |
Tree-based command dispatcher.
Maps keys to operations using a balanced tree (DynMapTree). Provides O(log n) lookup, insertion, and removal.
| Key | The key type (must be comparable with <) |
| Operation | The callable type (function pointer, std::function, etc.) |
Definition at line 137 of file ah-dispatcher.H.
|
default |
Default constructor.
Creates an empty dispatcher.
|
inline |
Variadic constructor for initializing with key-operation pairs.
| key | First key to register. |
| op | Operation associated with the key. |
| pairs | Additional key-operation pairs. |
Definition at line 164 of file ah-dispatcher.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Register a key-operation pair.
If the key already exists, its operation is replaced.
| key | The key to register. |
| op | The operation to associate with the key. |
Definition at line 178 of file ah-dispatcher.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Check if the dispatcher is empty.
Definition at line 245 of file ah-dispatcher.H.
References Aleph::DynSetTree< Key, Tree, Compare >::is_empty(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Get all registered keys.
Definition at line 231 of file ah-dispatcher.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::keys(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Remove a key-operation pair.
| key | The key to remove. |
Definition at line 213 of file ah-dispatcher.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::remove(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Execute the operation associated with a key.
| Args | Types of arguments to pass to the operation. |
| key | The key identifying the operation. |
| args | Arguments to forward to the operation. |
| Aborts | if the key is not registered. |
Definition at line 196 of file ah-dispatcher.H.
References Aleph::maps(), Aleph::DynMapTree< Key, Data, Tree, Compare >::search(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Get the number of registered operations.
Definition at line 238 of file ah-dispatcher.H.
References Aleph::DynSetTree< Key, Tree, Compare >::size(), and AHDispatcher< Key, Operation >::tbl.
|
inline |
Check if a key is registered.
| key | The key to check. |
Definition at line 224 of file ah-dispatcher.H.
References Aleph::DynMapTree< Key, Data, Tree, Compare >::has(), and AHDispatcher< Key, Operation >::tbl.
|
private |
Definition at line 139 of file ah-dispatcher.H.
Referenced by AHDispatcher< Key, Operation >::AHDispatcher(), AHDispatcher< Key, Operation >::insert(), AHDispatcher< Key, Operation >::is_empty(), AHDispatcher< Key, Operation >::keys(), AHDispatcher< Key, Operation >::remove(), AHDispatcher< Key, Operation >::run(), AHDispatcher< Key, Operation >::size(), and AHDispatcher< Key, Operation >::valid_key().