00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __peoParaAlgorithm_h
00038 #define __peoParaAlgorithm_h
00039
00040
00041 #include "core/runner.h"
00042 #include "core/peo_debug.h"
00043
00049 class peoWrapper : public Runner
00050 {
00051
00052 public:
00053
00056 template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
00057 : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
00058 {}
00059
00063 template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
00064 : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
00065 {}
00066
00069 template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
00070 : algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
00071 {}
00072
00076 template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
00077 : algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
00078 {}
00079
00081 ~peoWrapper()
00082 {
00083 delete algorithm;
00084 }
00085
00087 void run()
00088 {
00089 algorithm->operator()();
00090 }
00091
00092
00093 private:
00094
00095 struct AbstractAlgorithm
00096 {
00097
00098
00099 virtual ~AbstractAlgorithm()
00100 { }
00101
00102
00103 virtual void operator()()
00104 { }
00105 };
00106
00107 template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm
00108 {
00109
00110 Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
00111 : algorithm( externalAlgorithm ), algorithmData( externalData )
00112 {}
00113
00114 virtual void operator()()
00115 {
00116 algorithm( algorithmData );
00117 }
00118
00119 AlgorithmType& algorithm;
00120 AlgorithmDataType& algorithmData;
00121 };
00122
00123 template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm
00124 {
00125
00126 Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
00127 {}
00128
00129 virtual void operator()()
00130 {
00131 algorithm();
00132 }
00133
00134 AlgorithmType& algorithm;
00135 };
00136
00137 template< typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
00138 {
00139
00140 FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
00141 : algorithm( externalAlgorithm ), algorithmData( externalData )
00142 {}
00143
00144 virtual void operator()()
00145 {
00146 algorithm( algorithmData );
00147 }
00148
00149 AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
00150 AlgorithmDataType& algorithmData;
00151 };
00152
00153 template< typename AlgorithmReturnType > struct FunctionAlgorithm< AlgorithmReturnType, void > : public AbstractAlgorithm
00154 {
00155
00156 FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() )
00157 : algorithm( externalAlgorithm )
00158 {}
00159
00160 virtual void operator()()
00161 {
00162 algorithm();
00163 }
00164
00165 AlgorithmReturnType (*algorithm)();
00166 };
00167
00168 private:
00170 AbstractAlgorithm* algorithm;
00171 };
00172
00173
00174 #endif