library of assembled shared sources

http://lass.cocamware.com

Callback

library to wrap generalized callback functions in first class objects. More...


Data Structures

class  lass::util::EmptyCallback
class  lass::util::Callback0
 callback with 0 parameter(s) and without returnvalue. More...
class  lass::util::Callback1< P1 >
 callback with 1 parameter(s) but without returnvalue. More...
class  lass::util::Callback10< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 >
 callback with 10 parameter(s) but without returnvalue. More...
class  lass::util::Callback11< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11 >
 callback with 11 parameter(s) but without returnvalue. More...
class  lass::util::Callback12< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12 >
 callback with 12 parameter(s) but without returnvalue. More...
class  lass::util::Callback13< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13 >
 callback with 13 parameter(s) but without returnvalue. More...
class  lass::util::Callback14< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14 >
 callback with 14 parameter(s) but without returnvalue. More...
class  lass::util::Callback15< P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15 >
 callback with 15 parameter(s) but without returnvalue. More...
class  lass::util::Callback2< P1, P2 >
 callback with 2 parameter(s) but without returnvalue. More...
class  lass::util::Callback3< P1, P2, P3 >
 callback with 3 parameter(s) but without returnvalue. More...
class  lass::util::Callback4< P1, P2, P3, P4 >
 callback with 4 parameter(s) but without returnvalue. More...
class  lass::util::Callback5< P1, P2, P3, P4, P5 >
 callback with 5 parameter(s) but without returnvalue. More...
class  lass::util::Callback6< P1, P2, P3, P4, P5, P6 >
 callback with 6 parameter(s) but without returnvalue. More...
class  lass::util::Callback7< P1, P2, P3, P4, P5, P6, P7 >
 callback with 7 parameter(s) but without returnvalue. More...
class  lass::util::Callback8< P1, P2, P3, P4, P5, P6, P7, P8 >
 callback with 8 parameter(s) but without returnvalue. More...
class  lass::util::Callback9< P1, P2, P3, P4, P5, P6, P7, P8, P9 >
 callback with 9 parameter(s) but without returnvalue. More...
class  lass::util::CallbackR0< R >
 callback with 0 parameters but with returnvalue. More...
class  lass::util::CallbackR1< R, P1 >
 callback with 1 parameter1 and with returnvalue. More...
class  lass::util::CallbackR10< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 >
 callback with 10 parameter10 and with returnvalue. More...
class  lass::util::CallbackR11< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11 >
 callback with 11 parameter11 and with returnvalue. More...
class  lass::util::CallbackR12< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12 >
 callback with 12 parameter12 and with returnvalue. More...
class  lass::util::CallbackR13< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13 >
 callback with 13 parameter13 and with returnvalue. More...
class  lass::util::CallbackR14< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14 >
 callback with 14 parameter14 and with returnvalue. More...
class  lass::util::CallbackR15< R, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15 >
 callback with 15 parameter15 and with returnvalue. More...
class  lass::util::CallbackR2< R, P1, P2 >
 callback with 2 parameter2 and with returnvalue. More...
class  lass::util::CallbackR3< R, P1, P2, P3 >
 callback with 3 parameter3 and with returnvalue. More...
class  lass::util::CallbackR4< R, P1, P2, P3, P4 >
 callback with 4 parameter4 and with returnvalue. More...
class  lass::util::CallbackR5< R, P1, P2, P3, P4, P5 >
 callback with 5 parameter5 and with returnvalue. More...
class  lass::util::CallbackR6< R, P1, P2, P3, P4, P5, P6 >
 callback with 6 parameter6 and with returnvalue. More...
class  lass::util::CallbackR7< R, P1, P2, P3, P4, P5, P6, P7 >
 callback with 7 parameter7 and with returnvalue. More...
class  lass::util::CallbackR8< R, P1, P2, P3, P4, P5, P6, P7, P8 >
 callback with 8 parameter8 and with returnvalue. More...
class  lass::util::CallbackR9< R, P1, P2, P3, P4, P5, P6, P7, P8, P9 >
 callback with 9 parameter9 and with returnvalue. More...


Detailed Description

library to wrap generalized callback functions in first class objects.

Date:
2002-2004
Author:
Bram de Greve [Bramz] (contact: bramz@users.sourceforge.net)
The use of this library is to treat function calls as first class objects, so you can pass them around to be called at a later time.

  int fun(int a, int b) { return a + b; }
  // ...
  CallbackR2<int, int, int> cb(fun);
  // ...
  int result = cb(1, 2); // result will be 3.

Of course, the above example could be done just as easy with plain old C function pointers. That's true, but the advantage of this library will come forward when you want to call a method of a specific object instead. You can tell what method must be called, and on what object. Later, the caller can execute this without being aware this is a different case than above. There's no way you can do this with plain old function pointers.

  class Foo
  {
      int m_;
  public:
      Foo(int m): m_(m) {}
      int bar(int a, b) const { return m * (a + b); }
  };
  // ...
  Foo foo(4);
  CallbackR2<int, int, int> cb2(&foo, Foo::bar);
  // ...
  int result2 = cb2(1, 2); // result2 will be 12.

Both constant as non-constant member functions are supported as dispatchers.

It is also possible to bind a function with a little different signature, but of which the arguments can be implicit converted to the right type.

  float spam(float a, float b) { return a / b; }
  // ...
  CallbackR2<int, int, int> cb3(spam);
  // ...
  int result3 = cb3(5, 2); // result3 will be 2

Callbacks can also be in an empty state. This is when the callback has no dispatcher, no function call is bounded to it. Callbacks will be empty when constructed by the default constructor, or when one of the arguments is a NULL pointer

  CallbackR0<double> cb4;
  assert(cb4.empty());

  CallbackR1<bool, float> cb5(0); // NULL function pointer
  assert(cb5.empty());

  CallbackR2<int, int, int> cb6(0, Foo::bar); // NULL ojbect pointer
  assert(cb6.empty());

When executing empty callbacks, we have to distinguish two situations: callbacks without return value, and callbacks with return value.

  Callback2<int, const std::string&> cb7;
  assert(cb7.empty());
  cb7(4, "hello"); // OK, empty callback but no return value expected.

  Callback3<std::string, int, int> cb8;
  assert(cb8.empty());
  try
  {
      std::string result8 = cb8(12, 34); // ERROR, an exception will be thrown.
  }
  catch(CallbackEmptyCall)
  {
      // you'll end up here on an empty call.
  }

  std::string result8b = cb8 ? cb8(12, 34) : "bah"; // result8b will be "bah".

Callbacks without return value:

Callbacks with return value:

Generated on Mon Nov 10 14:22:06 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo