mike/dispatchTable

Source   Edit  

Internal module that implements late binding dispatch table. This is used for the error handling implementation so that handling a parent exception automatically handles the child exceptions (if nothing else handles them)

Types

DispatchMethod[O; D; R] = proc (obj: O; data: D): R
Method in the dispatch table. Takes in the object along with an argument Source   Edit  
DispatchTable[O; D; R] = Table[DispatchKey, DispatchMethod[O, D, R]]

Dynamic dispatch table. DispatchMethods get passed the object that is getting called along with a bit of data.

Implemented so we can get late binding for method calling

Source   Edit  

Procs

proc add[O, T, D, R](table: var DispatchTable[O, D, R]; typ: typedesc[T];
                     handler: DispatchMethod[T, D, R])
Adds a new method into the lookup table Source   Edit  
proc call[O, T, R, D](table: DispatchTable[O, D, R]; val: T; data: D): R
Calls the appropriate handler for an object in the lookup table Source   Edit  
proc initDispatchTable[O, D, R](base: DispatchMethod[O, D, R]): DispatchTable[O,
    D, R]
Creates a new lookup table. Must have a base handler which corresponds to the root object Source   Edit