|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Dispatcher pattern in Aleph-w (ah-dispatcher.H) with tree and hash backends.
More...
#include <iostream>#include <iomanip>#include <string>#include <functional>#include <sstream>#include <ah-dispatcher.H>#include <tpl_dynArray.H>Go to the source code of this file.
Namespaces | |
| namespace | Calculator |
| Basic arithmetic operations for the calculator. | |
Functions | |
| void | print_header (const string &title) |
| void | print_subheader (const string &subtitle) |
| double | Calculator::add (double a, double b) |
| double | Calculator::sub (double a, double b) |
| double | Calculator::mul (double a, double b) |
| double | Calculator::div (double a, double b) |
| double | Calculator::mod (double a, double b) |
| double | Calculator::pow (double a, double b) |
| void | demo_calculator () |
| void | demo_text_processor () |
| void | demo_regions_menu () |
| void | demo_state_machine () |
| void | demo_hash_dispatcher () |
| void | demo_variadic_dispatcher () |
| int | main () |
Dispatcher pattern in Aleph-w (ah-dispatcher.H) with tree and hash backends.
This example demonstrates Aleph-w's dispatcher containers: maps from keys (typically std::string) to callables (functions, lambdas, functors) enabling command-style dispatch without long if/else chains.
It includes multiple demos (calculator, text transforms, menu, state machine) and compares tree-backed vs hash-backed dispatch.
std::stringstd::function<...> or function pointersContainers shown:
AHDispatcher<Signature>: ordered/tree-based dispatcherAhHashDispatcher<Signature>: hash-based dispatcherTypical operations:
disp[key] = callable;if (disp.has(key)) disp[key](...);Let n be the number of registered commands.
O(log n)O(1) averageThis example has no command-line options; it runs all demos.
operator[] to execute, ensure the key exists or use has() first.ah-dispatcher.Hdynmap_example.C / dynset_trees.C (ordered containers and backends)Definition in file dispatcher_example.C.
| void demo_calculator | ( | ) |
Definition at line 146 of file dispatcher_example.C.
References Calculator::add(), Aleph::DynList< T >::append(), Calculator::div(), Aleph::DynList< T >::insert(), Aleph::maps(), Calculator::mod(), Calculator::mul(), Calculator::pow(), print_header(), Aleph::HTList::size(), and Calculator::sub().
Referenced by main().
| void demo_hash_dispatcher | ( | ) |
Definition at line 456 of file dispatcher_example.C.
References Aleph::DynList< T >::append(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), and Aleph::HTList::size().
Referenced by main().
| void demo_regions_menu | ( | ) |
Definition at line 281 of file dispatcher_example.C.
References Aleph::DynList< T >::append(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), and Aleph::HTList::size().
Referenced by main().
| void demo_state_machine | ( | ) |
Definition at line 356 of file dispatcher_example.C.
References Aleph::DynList< T >::insert(), log(), Aleph::maps(), and print_header().
Referenced by main().
| void demo_text_processor | ( | ) |
Definition at line 197 of file dispatcher_example.C.
References Aleph::DynList< T >::append(), Aleph::count(), Aleph::DynList< T >::insert(), GenericItems< Container, T >::keys(), Aleph::maps(), print_header(), Aleph::HTList::size(), Aleph::to_string(), Aleph::tolower(), and Aleph::toupper().
Referenced by main().
| void demo_variadic_dispatcher | ( | ) |
Definition at line 531 of file dispatcher_example.C.
References Aleph::DynList< T >::append(), Aleph::DynList< T >::insert(), Aleph::maps(), print_header(), Aleph::HTList::size(), and Aleph::to_string().
Referenced by main().
| int main | ( | ) |
Definition at line 591 of file dispatcher_example.C.
References demo_calculator(), demo_hash_dispatcher(), demo_regions_menu(), demo_state_machine(), demo_text_processor(), demo_variadic_dispatcher(), and Aleph::maps().
| void print_header | ( | const string & | title | ) |
Definition at line 108 of file dispatcher_example.C.
References Aleph::maps().
| void print_subheader | ( | const string & | subtitle | ) |
Definition at line 116 of file dispatcher_example.C.
References FunctionalMethods< Container, T >::length(), and Aleph::maps().