git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@612 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
atantar 2007-09-24 11:55:11 +00:00
commit 15fe990a24

View file

@ -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