diff --git a/FDTD/engine.cpp b/FDTD/engine.cpp index 277234f..15dc55b 100644 --- a/FDTD/engine.cpp +++ b/FDTD/engine.cpp @@ -18,10 +18,18 @@ #include "engine.h" #include "tools/array_ops.h" +//! \brief construct an Engine instance +//! it's the responsibility of the caller to free the returned pointer +Engine* Engine::createEngine(Operator* op) +{ + Engine* e = new Engine(op); + e->Init(); + return e; +} + Engine::Engine(Operator* op) { Op = op; - Init(); } Engine::~Engine() diff --git a/FDTD/engine.h b/FDTD/engine.h index 401fa13..4e98ddd 100644 --- a/FDTD/engine.h +++ b/FDTD/engine.h @@ -28,7 +28,7 @@ class Engine friend class ProcessFields; friend class ProcessFieldsTD; public: - Engine(Operator* op); + static Engine* createEngine(Operator* op); virtual ~Engine(); virtual void Init(); @@ -40,6 +40,7 @@ public: unsigned int GetNumberOfTimesteps() {return numTS;}; protected: + Engine(Operator* op); Operator* Op; FDTD_FLOAT**** volt; diff --git a/FDTD/engine_multithread.cpp b/FDTD/engine_multithread.cpp index ee5e167..c974835 100644 --- a/FDTD/engine_multithread.cpp +++ b/FDTD/engine_multithread.cpp @@ -18,6 +18,15 @@ #include "engine_multithread.h" #include "tools/array_ops.h" +//! \brief construct an Engine_Multithread instance +//! it's the responsibility of the caller to free the returned pointer +Engine_Multithread* Engine_Multithread::createEngine(Operator* op) +{ + Engine_Multithread* e = new Engine_Multithread(op); + e->Init(); + return e; +} + Engine_Multithread::Engine_Multithread(Operator* op) : Engine(op) { } diff --git a/FDTD/engine_multithread.h b/FDTD/engine_multithread.h index 3d45b6c..24f532e 100644 --- a/FDTD/engine_multithread.h +++ b/FDTD/engine_multithread.h @@ -29,8 +29,8 @@ class Engine_Multithread : public Engine friend class ProcessFields; friend class ProcessFieldsTD; public: - Engine_Multithread(Operator* op); - virtual ~Engine_Multithread(); + static Engine_Multithread* createEngine(Operator* op); + virtual ~Engine_Multithread(); virtual void Init(); virtual void Reset(); @@ -40,6 +40,7 @@ public: protected: + Engine_Multithread(Operator* op); }; #endif // ENGINE_MULTITHREAD_H diff --git a/openems.cpp b/openems.cpp index e2ffc2f..d920e70 100644 --- a/openems.cpp +++ b/openems.cpp @@ -226,10 +226,10 @@ int openEMS::SetupFDTD(const char* file) //create FDTD engine switch (m_engine) { case EngineType_Multithreaded: - FDTD_Eng = new Engine_Multithread(FDTD_Op); + FDTD_Eng = Engine_Multithread::createEngine(FDTD_Op); break; default: - FDTD_Eng = new Engine(FDTD_Op); + FDTD_Eng = Engine::createEngine(FDTD_Op); break; }