git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@612 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
ed0e29adcb
commit
15fe990a24
1 changed files with 80 additions and 0 deletions
80
trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h
Normal file
80
trunk/paradiseo-peo/src/peoParallelAlgorithmWrapper.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue