Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-03-17 20:24:17


Hi Everyone,

I've been working on this library for the past few months, and I've
uploaded the zip archive to the vault ( http://tinyurl.com/2bu427 ).

First, let me describe what the library is for, what problem it's
supposed to solve, and how it's different from existing
implementations.

The dispatcher library aims to provide a homogeneous function registry
associating keys to callbacks. The type of the key and the function
signature are provided as template parameters. The function registry
(or dispatcher) can be given an index validation and routing strategy
to validate indexes during runtime.

The dispatcher is not a container, but it does contain an
implementation of a strategized_map which encapsulates an STL map and
allows the user to define an index validation and routing strategy on
top of the existing STL map implementation.

The intended use of the library is given as an inlined example snippet
(also discussed in the documentation also in the zip archive):

using namespace boost::dispatch ;
dispatcher<void(std::string)> d;
// register some functions to d here...
d[0] = a_function;
d[1] = another_function;
d[3] = some_other_function;
// note index '2' is not defined
invoke_(d)("Hello, World!")
  << 0 << 1 << alt_(2, 3);

The intention is to be able to delay implementations to loaded dll's
or external modules, while writing statically type safe functions like
below:

template <class DispatcherType>
void some_function(DispatcherType & d) {
  using namespace boost::dispatch;
  try {
    invoke_(d)("a", "b", "c") // bind the three arguments to
successive invocations
      << alt_("handler1", "handler2") << "cleanup";
  } catch (std::exception & e) {
    std::cerr << e.what() << '\n';
  };
};

// client code...
{
  using namespace boost::dispatch;
  dispatch<void(std::string, std::string, std::string), std::string> d;
  // load the implementations using dlopen, or something like that
  d["handler2"] = loaded_function_2;
  d["cleanup"] = cleanup_function;
  some_function(d);
}

More details available in the contained documentation.

Comments and suggestions (and some help with Boost.PP) will be very
much appreciated.

Have a great day everyone, and I certainly hope this library would be
useful to others who need this functionality.

-- 
Dean Michael C. Berris
http://cplusplus-soup.blogspot.com/
mikhailberis AT gmail DOT com
+63 928 7291459

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk