GenericFunctor could also be called generic callback. Basically, its a callable object that can be binded to call a C function, a C++ method or an STL like functor.

A high quality implementation of that can be found in boost bind, function and lambda libraries. boost bind/function was initially considered as it claimed a good portability. The main reason why a mini generic functor library was developped was compile time. Another was that you easily ended with compiler internal error when playing with bind on VC++ 6.

The generic functor implemented for CppUnit2 is minimal, but meet the implementation requirement. Since boost::function are also functors, they can also be bound to CppUnit2 generic functor.

Here are some examples of use:

CppUT::Functor0 fn = CppUT::makeFn0( &callback0 ); 
fn();

struct TestFunctor
{
   void operator()() const
   {
      callbackCalled = true;
   }
};

TestFunctor testFunctor;
fn = CppUT::makeFn0( testFunctor );
fn();

struct HelperObject
{
   void setFlag( bool value )
   {
      flag_ = value;
   }
}; 

CppUT::SmartPtr<HelperObject> helper( new HelperObject() );
helper->flag_ = false;
fn = CppUT::makeMemFn1( helper, &HelperObject::setFlag );
fn( true ); 

More complex examples can be found in testfunctor.cpp.


CppUnit2/GenericFunctor (last edited 2008-02-26 06:29:57 by localhost)

SourceForge.net Logo