From 9851d8836415d40dafa7045c4afe8a685b9a0e8a Mon Sep 17 00:00:00 2001 From: caremoli Date: Thu, 17 Sep 2009 07:58:16 +0000 Subject: [PATCH] CCAR: move genericobj management in SALOMEDSImpl from Study to AttributeIOR and put it into 2 functions IORGenericObjIncref and IORGenericObjDecref --- .../SALOMEDSImpl_AttributeIOR.cxx | 59 ++++++++++++++++++- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 48 --------------- 2 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx index bfe178356..3ce911286 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx @@ -28,6 +28,55 @@ using namespace std; +//to disable automatic genericobj management comment the following line +#define WITHGENERICOBJ + +#ifdef WITHGENERICOBJ +#include "SALOME_GenericObj_i.hh" + +static CORBA::ORB_var getORB() +{ + int argc=0; + return CORBA::ORB_init(argc,0); +} + +void IORGenericObjDecref(const std::string& anIOR) +{ + CORBA::Object_var obj; + SALOME::GenericObj_var gobj; + try + { + obj = getORB()->string_to_object(anIOR.c_str()); + gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->Destroy(); + } + } + catch(const CORBA::Exception& e) + { + } +} + +void IORGenericObjIncref(const std::string& anIOR) +{ + CORBA::Object_var obj; + SALOME::GenericObj_var gobj; + try + { + obj = getORB()->string_to_object(anIOR.c_str()); + gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->Register(); + } + } + catch(const CORBA::Exception& e) + { + } +} +#endif + //======================================================================= //function : GetID //purpose : @@ -72,7 +121,11 @@ void SALOMEDSImpl_AttributeIOR::SetValue(const std::string& theValue) Backup(); //remove IOR entry in study if(theValue != myString) - study->DeleteIORLabelMapItem(myString); + { + IORGenericObjIncref(theValue); + IORGenericObjDecref(myString); + study->DeleteIORLabelMapItem(myString); + } myString = theValue; @@ -99,7 +152,9 @@ SALOMEDSImpl_AttributeIOR::SALOMEDSImpl_AttributeIOR() } SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR() -{} +{ + IORGenericObjDecref(myString); +} //======================================================================= //function : ID diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 26d019c5d..7832d50c7 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -48,18 +48,6 @@ using namespace std; #define VARIABLE_SEPARATOR ':' #define OPERATION_SEPARATOR '|' -//to disable automatic genericobj management comment the following line -#define WITHGENERICOBJ - -#ifdef WITHGENERICOBJ -#include "SALOME_GenericObj_i.hh" -static CORBA::ORB_var getORB() -{ - int argc=0; - return CORBA::ORB_init(argc,0); -} -#endif - //============================================================================ /*! Function : SALOMEDSImpl_Study * Purpose : SALOMEDSImpl_Study constructor @@ -973,26 +961,6 @@ void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anE _errorCode = ""; DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true); if (myIORLabels.find(anIOR) != myIORLabels.end()) myIORLabels.erase(anIOR); -#ifdef WITHGENERICOBJ - else - { - // if the ior was not already registered, incref the genericobj (if it's one) - CORBA::Object_var obj; - SALOME::GenericObj_var gobj; - try - { - obj = getORB()->string_to_object(anIOR.c_str()); - gobj = SALOME::GenericObj::_narrow(obj); - if(! CORBA::is_nil(gobj) ) - { - gobj->Register(); - } - } - catch(const CORBA::Exception& e) - { - } - } -#endif myIORLabels[anIOR] = aLabel; } @@ -1002,22 +970,6 @@ void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR) { //remove the ior entry and decref the genericobj (if it's one) myIORLabels.erase(anIOR); -#ifdef WITHGENERICOBJ - CORBA::Object_var obj; - SALOME::GenericObj_var gobj; - try - { - obj = getORB()->string_to_object(anIOR.c_str()); - gobj = SALOME::GenericObj::_narrow(obj); - if(! CORBA::is_nil(gobj) ) - { - gobj->Destroy(); - } - } - catch(const CORBA::Exception& e) - { - } -#endif } } -- 2.39.2