|
|
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.
typedef vector<const Element*> ArgList | ArgList |
Dispatcher ()
| Dispatcher |
OpNotFound (class) | OpNotFound |
If there is no combination for the given operation and element types.
template<class L, class R, Element* (*funct)(const L&,const R&)>
void add (const BinOper& op)
| add |
Method to register a binary operation callback with dispatcher.
Parameters:
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. |
template<class T, Element* (*funct)(const T&)>
void add (const UnOper& op)
| add |
Method to register a unary operation callback with dispatcher.
Parameters:
T | concrete class of argument |
funct | function to be called to perform operation. |
op | unary operation to be registered. |
Element* run (const Oper& op, unsigned argc, const Element** argv)
| run |
[const]
Execute an n-ary operation.
Throws an exception on failure.
Parameters:
op | operation to dispatch. |
args | arguments of operation. |
Returns: result of operation.
Element* run (const UnOper& op, const Element& arg)
| run |
[const]
Execute an unary operation.
Parameters:
op | Operation to perform. |
arg | Argument of operation. |
Returns: Result of operation. Caller is responsible for delete.
Element* run (const BinOper& op,
const Element& left,
const Element& right)
| run |
[const]
Execute a binary operation.
Parameters:
op | Operation to perform. |
left | first argument. |
right | second argument. |
Returns: result of operation. Caller is responsible for delete.