static createEngine() added to work around virtual constructor problems

pull/1/head
Sebastian Held 2010-03-26 17:24:43 +01:00
parent f46fd11416
commit a7ccec254d
5 changed files with 25 additions and 6 deletions

View File

@ -18,10 +18,18 @@
#include "engine.h" #include "engine.h"
#include "tools/array_ops.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) Engine::Engine(Operator* op)
{ {
Op = op; Op = op;
Init();
} }
Engine::~Engine() Engine::~Engine()

View File

@ -28,7 +28,7 @@ class Engine
friend class ProcessFields; friend class ProcessFields;
friend class ProcessFieldsTD; friend class ProcessFieldsTD;
public: public:
Engine(Operator* op); static Engine* createEngine(Operator* op);
virtual ~Engine(); virtual ~Engine();
virtual void Init(); virtual void Init();
@ -40,6 +40,7 @@ public:
unsigned int GetNumberOfTimesteps() {return numTS;}; unsigned int GetNumberOfTimesteps() {return numTS;};
protected: protected:
Engine(Operator* op);
Operator* Op; Operator* Op;
FDTD_FLOAT**** volt; FDTD_FLOAT**** volt;

View File

@ -18,6 +18,15 @@
#include "engine_multithread.h" #include "engine_multithread.h"
#include "tools/array_ops.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) Engine_Multithread::Engine_Multithread(Operator* op) : Engine(op)
{ {
} }

View File

@ -29,8 +29,8 @@ class Engine_Multithread : public Engine
friend class ProcessFields; friend class ProcessFields;
friend class ProcessFieldsTD; friend class ProcessFieldsTD;
public: public:
Engine_Multithread(Operator* op); static Engine_Multithread* createEngine(Operator* op);
virtual ~Engine_Multithread(); virtual ~Engine_Multithread();
virtual void Init(); virtual void Init();
virtual void Reset(); virtual void Reset();
@ -40,6 +40,7 @@ public:
protected: protected:
Engine_Multithread(Operator* op);
}; };
#endif // ENGINE_MULTITHREAD_H #endif // ENGINE_MULTITHREAD_H

View File

@ -226,10 +226,10 @@ int openEMS::SetupFDTD(const char* file)
//create FDTD engine //create FDTD engine
switch (m_engine) { switch (m_engine) {
case EngineType_Multithreaded: case EngineType_Multithreaded:
FDTD_Eng = new Engine_Multithread(FDTD_Op); FDTD_Eng = Engine_Multithread::createEngine(FDTD_Op);
break; break;
default: default:
FDTD_Eng = new Engine(FDTD_Op); FDTD_Eng = Engine::createEngine(FDTD_Op);
break; break;
} }