dispatch-table

How do I create a dispatch table within a class in PHP?

Say I have a class with a private dispatch table. $this->dispatch = array( 1 => $this->someFunction, 2 => $this->anotherFunction ); If I then call $this->dispatch[1](); I get an error that the method is not a string. When I make it a string like this: $this->dispatch = array( 1 => '$this->someFunction' ); This pro...

How do you implement a dispatch table in your language of choice?

A dispatch table is a data structure that associates an index value to an action. It's a rather elegant replacement for a switch-type statement. Most languages have support for dispatch tables, but the support ranges from do-it-yourself to built-in and hidden under a layer of syntax. How does your favorite language implement dispatch ...

How can I create a dispatch table in Boo?

I'd like to be able to store a function in a hashtable. I can create a map like: hash = {} hash["one"] = def(): print "one got called" But I'm not able to call it: func = hash["one"] func() This produces the following error message: It is not possible to invoke an expression on type 'object'. Neither Invoke or Call works. How c...

How do I implement dispatch tables in Perl?

I need to write a storage related app in Perl. The app needs to upload files from the local machine to some other storage nodes. Currently, the uploading method is FTP, but in the future it may be bittorrent or some unknown super-file-transferring method. For every file that needs to be uploaded, there is a configuration file which de...

How do I create a dispatch table in Perl with key contain whitespace and the subroutine accepting an array parameter?

Here's my current thinking, but I dont know how to dispatch/execute it my $key; my @arraydata; my %commandfunc{ "ab 1", \ foreach $k (keys %commandfunc){ if($something =~ /$k/){ #if $something match with a key string $key= $k; #some processing arraydata here; } } #dispatching?? my $command = $commandfunc{$key}-...

How can I use dispatch tables in Perl?

Possible Duplicate: How do I implement dispatch tables in Perl? I have a hash table that contains commands such as int(rand()) etc. How do I execute those commands? ...

Dispatch Table in C++

Suppose I have something like the following: class Point : geometry { ... Point(double x, double y) { } double distanceTo(Line) { } double distanceTo(Point) { } } class Line : geometry { ... Line(double x, double y, double slopex, double slopey) { } double distanceTo(Line) { } double distanceTo(Poi...

How can I implement a dispatch table using Perl objects?

What is the syntax for the hash value for a Perl object member subroutine reference in a dispatch table? use lib Alpha; my $foo = new Alpha::Foo; $foo->bar(); my %disp_table = ( bar => ??? ); I want ??? to be the code reference for $foo->bar(). ...