From cd706b355f56e9175da8642000225d7805029c27 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 2 Aug 2012 15:48:03 +0000 Subject: [PATCH] Made casting operations in ctreactor safer --- src/clib/ctreactor.cpp | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 87b8f0812..397520782 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -116,9 +116,9 @@ extern "C" { int reactor_setKineticsMgr(int i, int n) { try { - ReactorBase* r = &ReactorCabinet::item(i); - if (r->type() >= ReactorType) { - ((Reactor*)r)->setKineticsMgr(KineticsCabinet::item(n)); + // @todo This should not fail silently + if (ReactorCabinet::item(i).type() >= ReactorType) { + ReactorCabinet::get(i).setKineticsMgr(KineticsCabinet::item(n)); } return 0; } catch (...) { @@ -233,9 +233,9 @@ extern "C" { int reactor_setEnergy(int i, int eflag) { try { - ReactorBase* r = &ReactorCabinet::item(i); - if (r->type() >= ReactorType) { - ((Reactor*)r)->setEnergy(eflag); + // @todo This should not fail silently + if (ReactorCabinet::item(i).type() >= ReactorType) { + ReactorCabinet::get(i).setEnergy(eflag); } return 0; } catch (...) { @@ -246,10 +246,7 @@ extern "C" { int flowReactor_setMassFlowRate(int i, double mdot) { try { - ReactorBase* r = &ReactorCabinet::item(i); - if (r->type() >= ReactorType) { - ((FlowReactor*)r)->setMassFlowRate(mdot); - } + ReactorCabinet::get(i).setMassFlowRate(mdot); return 0; } catch (...) { return handleAllExceptions(-1, ERR); @@ -259,13 +256,7 @@ extern "C" { size_t reactor_nSensParams(int i) { try { - ReactorBase* r = &ReactorCabinet::item(i); - if (r->type() >= ReactorType) { - return ((Reactor*)r)->nSensParams(); - } else { - std::cout << "type problem..." << r->type() << std::endl; - return 0; - } + return ReactorCabinet::get(i).nSensParams(); } catch (...) { return handleAllExceptions(npos, npos); } @@ -274,8 +265,7 @@ extern "C" { int reactor_addSensitivityReaction(int i, int rxn) { try { - ReactorBase* r = &ReactorCabinet::item(i); - ((Reactor*)r)->addSensitivityReaction(rxn); + ReactorCabinet::get(i).addSensitivityReaction(rxn); return 0; } catch (...) { return handleAllExceptions(-1, ERR); @@ -480,10 +470,8 @@ extern "C" { int flowdev_setMaster(int i, int n) { try { - if (FlowDeviceCabinet::item(i).type() == PressureController_Type) { - dynamic_cast(FlowDeviceCabinet::item(i)).setMaster( - &FlowDeviceCabinet::item(n)); - } + ReactorCabinet::get(i).setMaster( + &FlowDeviceCabinet::item(n)); return 0; } catch (...) { return handleAllExceptions(-1, ERR);