From 15fe990a24d8d714beeaa14cef42fbd7fef9303d Mon Sep 17 00:00:00 2001 From: atantar Date: Mon, 24 Sep 2007 11:55:11 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@612 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/peoParallelAlgorithmWrapper.h | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h diff --git a/trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h b/trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h new file mode 100644 index 000000000..90999de00 --- /dev/null +++ b/trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h @@ -0,0 +1,80 @@ +// "peoParallelAlgorithmWrapper.h" + +// (c) OPAC Team, LIFL, September 2007 + +/* + Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef __peoParaAlgorithm_h +#define __peoParaAlgorithm_h + + +#include "core/runner.h" +#include "core/peo_debug.h" + + + + +class peoParallelAlgorithmWrapper : public Runner { + +public: + + template< typename AlgorithmType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm ) + : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) { + + } + + template< typename AlgorithmType, typename AlgorithmDataType > peoParallelAlgorithmWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) + : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) { + + } + + void run() { algorithm->operator()(); } + + +private: + + struct AbstractAlgorithm { + + // virtual destructor as we will be using inheritance and polymorphism + virtual ~AbstractAlgorithm() { } + + // operator to be called for executing the algorithm + virtual void operator()() { } + }; + + + template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm { + + Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) + : algorithm( externalAlgorithm ), algorithmData( externalData ) { + + } + + virtual void operator()() { algorithm( algorithmData ); } + + AlgorithmType& algorithm; + AlgorithmDataType& algorithmData; + }; + + + template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm { + + Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) { + + } + + virtual void operator()() { algorithm(); } + + AlgorithmType& algorithm; + }; + + +private: + + AbstractAlgorithm* algorithm; +}; + + +#endif