Commit b0b9a030 authored by BRAMAS Berenger's avatar BRAMAS Berenger

Add a new template FOR for object and use it for the utest rotation

parent 6341b8ad
......@@ -58,6 +58,40 @@ void For(Args... args){
}
///////////////////////////////////////////////////////////////////////////////////////
/// FForAll : Compile all and exec all
///////////////////////////////////////////////////////////////////////////////////////
#include <functional>
namespace FForAllThis{
template <class IterType, const IterType CurrentIter, const IterType iterTo, const IterType IterStep,
class Func, bool IsNotOver, typename... Args>
struct Evaluator{
static void Run(Func* object, Args... args){
object->Func::template For<CurrentIter>(args...);
Evaluator<IterType, CurrentIter+IterStep, iterTo, IterStep, Func, (CurrentIter+IterStep < iterTo), Args...>::Run(object, args...);
}
};
template <class IterType, const IterType CurrentIter, const IterType iterTo, const IterType IterStep,
class Func, typename... Args>
struct Evaluator< IterType, CurrentIter, iterTo, IterStep, Func, false, Args...>{
static void Run(Func* object, Args... args){
}
};
template <class IterType, const IterType IterFrom, const IterType iterTo, const IterType IterStep,
class Func, typename... Args>
void For(Func* object, Args... args){
Evaluator<IterType, IterFrom, iterTo, IterStep, Func, (IterFrom<iterTo), Args...>::Run(object, args...);
}
}
///////////////////////////////////////////////////////////////////////////////////////
/// FRunIf : Compile all and exec only one (if the template variable is equal to
/// the first variable)
......
......@@ -42,6 +42,13 @@ struct RunContainer{
}
};
struct RunClass {
template <const int P>
void For(double mydouble, int myint){
std::cout << "RunClass::For >> P = " << P << " mydouble " << mydouble << " myint " << myint << "\n";
}
};
// Compile with g++ -std=c++11 main.cpp -o test.exe
int main(int argc, char** argv){
......@@ -51,6 +58,10 @@ int main(int argc, char** argv){
// This will call the For method (maybe several times)
FForAll::For<int, 0, 20, 1, RunContainer>(45.4, 55);
// This will call the For method (maybe several times)
RunClass runner;
FForAllThis::For<int, 0, 20, 1, RunClass>(&runner, 45.4, 55);
// This will call the Run method
FRunIf::Run<int, 0, 20, 1, RunContainer>(3, 45.4, 55);
......
......@@ -16,6 +16,7 @@
#include "../Src/Utils/FGlobal.hpp"
#include "../Src/Utils/FTic.hpp"
#include "../Src/Utils/FTemplate.hpp"
#include "../Src/Containers/FOctree.hpp"
#include "../Src/Containers/FVector.hpp"
......@@ -198,17 +199,17 @@ class TestRotationDirect : public FUTester<TestRotationDirect> {
/** Rotation */
template<int P>
void TestRotation(){
typedef FRotationCell<P> CellClass;
typedef FP2PParticleContainerIndexed<> ContainerClass;
typedef FRotationCell<P> CellClass;
typedef FP2PParticleContainerIndexed<> ContainerClass;
typedef FRotationKernel<CellClass, ContainerClass, P > KernelClass;
typedef FRotationKernel<CellClass, ContainerClass, P > KernelClass;
typedef FSimpleLeaf<ContainerClass > LeafClass;
typedef FOctree< CellClass, ContainerClass , LeafClass > OctreeClass;
typedef FSimpleLeaf<ContainerClass > LeafClass;
typedef FOctree< CellClass, ContainerClass , LeafClass > OctreeClass;
typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
typedef FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass > FmmClass;
RunTest<CellClass, ContainerClass, KernelClass, LeafClass, OctreeClass, FmmClass,P>();
RunTest<CellClass, ContainerClass, KernelClass, LeafClass, OctreeClass, FmmClass,P>();
}
///////////////////////////////////////////////////////////
......@@ -217,29 +218,13 @@ class TestRotationDirect : public FUTester<TestRotationDirect> {
/** set test */
void SetTests(){
AddTest(&TestRotationDirect::TestRotation<4>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<6>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<8>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<10>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<12>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<14>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<16>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<18>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<20>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<22>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<24>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<26>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<28>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<32>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<35>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<40>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<45>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<50>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<55>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<60>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<65>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<70>,"Test Rotation Kernel");
AddTest(&TestRotationDirect::TestRotation<75>,"Test Rotation Kernel");
FForAllThis::For<int, 6, 40, 2, TestRotationDirect>(this);
}
public:
template <int P>
void For(){
AddTest(&TestRotationDirect::TestRotation<P>,"Test Rotation Kernel");
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment