dispatch table; symbolic references
Emil
emilper at gmail.com
Sat Jun 8 05:36:53 PDT 2013
need a dispatch table and tried it this way:
class Action {
string[string] function(string[string] p) action;
this( string[string] function(string[string] p) action_ref ) {
this.action = action_ref;
}
string[string] execute(string[string] parameters) {
return this.action(parameters);
}
}
then
Action[string] dispatch_table = [
"test1" : new Action(&myapp.index.test),
"test2" : new Action(&myapp.index.another_test)
];
auto my_first_result = dispatch_table["test1"].execute(["a":
"aa", "b":"BB"]);
auto my_second_result = dispatch_table["test2"].execute([" some
string key for test2": "in test 2"]);
This works, but I am wondering if there is another way. Does D
support symbolic references so I could keep the hashtable in a
string[string], or even use a string variable holding a class
name to instantiate a class ?
thank you
More information about the Digitalmars-d-learn
mailing list