|
xorp
|
Link between elements and operations. More...
#include <dispatcher.hh>
Classes | |
| class | OpNotFound |
| Exception thrown if no operation is found for given arguments. More... | |
| union | Value |
Public Types | |
| typedef vector< const Element * > | ArgList |
Public Member Functions | |
| template<class L , class R , Element *(*)(const L &, const R &) funct> | |
| void | add (const BinOper &op) |
| Method to register a binary operation callback with dispatcher. | |
| template<class T , Element *(*)(const T &) funct> | |
| void | add (const UnOper &op) |
| Method to register a unary operation callback with dispatcher. | |
| Element * | run (const Oper &op, unsigned argc, const Element **argv) const |
| Execute an n-ary operation. | |
| Element * | run (const UnOper &op, const Element &arg) const |
| Execute an unary operation. | |
| Element * | run (const BinOper &op, const Element &left, const Element &right) const |
| Execute a binary operation. | |
Private Types | |
| typedef Element *(* | CB_bin )(const Element &, const Element &) |
| typedef Element *(* | CB_un )(const Element &) |
| typedef unsigned | Key |
| typedef map< Key, Value > | Map |
Private Member Functions | |
| Key | makeKey (const Oper &op, unsigned argc, const Element **argv) const |
| Create a key for the callback table based on operation and arguments. | |
| Value | lookup (const Oper &op, unsigned argc, const Element **argv) const |
| Lookup a callback for the requested operation and elements. | |
Static Private Attributes | |
| static Value | _map [32768] |
Link between elements and operations.
Executes operations on elments.
Implementation of multimethods. Insipred/copied from Alexandrescu [Modern C++ Design].
By taking base element arguments and an operation, it will execute the correct operation based on the concrete type of the arguments.
Similar to an ElementFactory.
| void Dispatcher::add | ( | const BinOper & | op | ) | [inline] |
Method to register a binary operation callback with dispatcher.
| L | concrete class of first argument |
| R | concrete class of second argument |
| funct | function to be called to perform operation. |
| op | binary operation to be registered. |
| void Dispatcher::add | ( | const UnOper & | op | ) | [inline] |
Method to register a unary operation callback with dispatcher.
| T | concrete class of argument |
| funct | function to be called to perform operation. |
| op | unary operation to be registered. |
Execute an unary operation.
| op | Operation to perform. |
| arg | Argument of operation. |
Execute an n-ary operation.
Throws an exception on failure.
| op | operation to dispatch. |
| args | arguments of operation. |
Execute a binary operation.
| op | Operation to perform. |
| left | first argument. |
| right | second argument. |