From: srn Date: Mon, 18 Dec 2006 08:00:40 +0000 (+0000) Subject: Added checks for null input objects X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ece42af11da42916a76b4941e97f2a1e0aae0bfe;p=modules%2Fkernel.git Added checks for null input objects --- diff --git a/src/SALOMEDS/SALOMEDS_AttributeTarget.cxx b/src/SALOMEDS/SALOMEDS_AttributeTarget.cxx index fff0cb6f0..8c631d021 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTarget.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTarget.cxx @@ -21,6 +21,9 @@ // Author : Sergey RUIN // Module : SALOME + +#include "utilities.h" + #include "SALOMEDS_AttributeTarget.hxx" #include "SALOMEDS.hxx" @@ -43,6 +46,9 @@ SALOMEDS_AttributeTarget::~SALOMEDS_AttributeTarget() void SALOMEDS_AttributeTarget::Add(const _PTR(SObject)& theObject) { + ASSERT(theObject); + if(!theObject) return; + SALOMEDS_SObject* aSO = dynamic_cast(theObject.get()); if (_isLocal) { @@ -82,6 +88,9 @@ std::vector<_PTR(SObject)> SALOMEDS_AttributeTarget::Get() void SALOMEDS_AttributeTarget::Remove(const _PTR(SObject)& theObject) { + ASSERT(theObject); + if(!theObject) return; + SALOMEDS_SObject* aSO = dynamic_cast(theObject.get()); if (_isLocal) { diff --git a/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx index 42ced1f14..adb27fb5b 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTarget_i.cxx @@ -21,7 +21,7 @@ // Author : Sergey RUIN // Module : SALOME - +#include "utilities.h" #include "SALOMEDS_AttributeTarget_i.hxx" #include "SALOMEDSImpl_SObject.hxx" @@ -35,6 +35,10 @@ using namespace std; void SALOMEDS_AttributeTarget_i::Add(SALOMEDS::SObject_ptr anObject) { SALOMEDS::Locker lock; + + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + TDF_Label aLabel; TDF_Tool::Label(_impl->Label().Data(),anObject->GetID(),aLabel,1); (Handle(SALOMEDSImpl_AttributeTarget)::DownCast(_impl))->Add(SALOMEDSImpl_Study::SObject(aLabel)); @@ -58,6 +62,10 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_AttributeTarget_i::Get() void SALOMEDS_AttributeTarget_i::Remove(SALOMEDS::SObject_ptr anObject) { SALOMEDS::Locker lock; + + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + TDF_Label aLabel; TDF_Tool::Label(_impl->Label().Data(),anObject->GetID(),aLabel,1); (Handle(SALOMEDSImpl_AttributeTarget)::DownCast(_impl))->Remove(SALOMEDSImpl_Study::SObject(aLabel)); diff --git a/src/SALOMEDS/SALOMEDS_AttributeTreeNode.cxx b/src/SALOMEDS/SALOMEDS_AttributeTreeNode.cxx index 8cac2063e..737c7419a 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTreeNode.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTreeNode.cxx @@ -21,6 +21,8 @@ // Author : Sergey RUIN // Module : SALOME +#include "utilities.h" + #include "SALOMEDS_AttributeTreeNode.hxx" #include "SALOMEDS.hxx" @@ -49,6 +51,9 @@ SALOMEDS_AttributeTreeNode::~SALOMEDS_AttributeTreeNode() void SALOMEDS_AttributeTreeNode::SetFather(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -99,6 +104,9 @@ _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetFather() void SALOMEDS_AttributeTreeNode::SetPrevious(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -149,6 +157,9 @@ _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetPrevious() void SALOMEDS_AttributeTreeNode::SetNext(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -199,6 +210,9 @@ _PTR(AttributeTreeNode) SALOMEDS_AttributeTreeNode::GetNext() void SALOMEDS_AttributeTreeNode::SetFirst(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -285,6 +299,9 @@ std::string SALOMEDS_AttributeTreeNode::GetTreeID() void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -303,6 +320,9 @@ void SALOMEDS_AttributeTreeNode::Append(const _PTR(AttributeTreeNode)& value) void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -321,6 +341,9 @@ void SALOMEDS_AttributeTreeNode::Prepend(const _PTR(AttributeTreeNode)& value) void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -339,6 +362,9 @@ void SALOMEDS_AttributeTreeNode::InsertBefore(const _PTR(AttributeTreeNode)& val void SALOMEDS_AttributeTreeNode::InsertAfter(const _PTR(AttributeTreeNode)& value) { + ASSERT(value); + if(!value) return; + SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { CheckLocked(); @@ -389,6 +415,8 @@ bool SALOMEDS_AttributeTreeNode::IsRoot() bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& value) { + if(!value) return false; + bool ret; SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { @@ -408,6 +436,8 @@ bool SALOMEDS_AttributeTreeNode::IsDescendant(const _PTR(AttributeTreeNode)& val bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value) { + if(!value) return false; + bool ret; SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { @@ -427,6 +457,8 @@ bool SALOMEDS_AttributeTreeNode::IsFather(const _PTR(AttributeTreeNode)& value) bool SALOMEDS_AttributeTreeNode::IsChild(const _PTR(AttributeTreeNode)& value) { + if(!value) return false; + bool ret; SALOMEDS_AttributeTreeNode* aTN = dynamic_cast(value.get()); if (_isLocal) { diff --git a/src/SALOMEDS/SALOMEDS_AttributeTreeNode_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTreeNode_i.cxx index 3574d218b..b51a06851 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTreeNode_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTreeNode_i.cxx @@ -55,6 +55,10 @@ void SALOMEDS_AttributeTreeNode_i::SetFather(SALOMEDS::AttributeTreeNode_ptr val { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->SetFather(GetNode(value, aNode)); } @@ -81,6 +85,10 @@ void SALOMEDS_AttributeTreeNode_i::SetPrevious(SALOMEDS::AttributeTreeNode_ptr v { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->SetPrevious(GetNode(value, aNode)); } @@ -107,6 +115,10 @@ void SALOMEDS_AttributeTreeNode_i::SetNext(SALOMEDS::AttributeTreeNode_ptr value { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->SetNext(GetNode(value, aNode)); } @@ -133,6 +145,10 @@ void SALOMEDS_AttributeTreeNode_i::SetFirst(SALOMEDS::AttributeTreeNode_ptr valu { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->SetFirst(GetNode(value, aNode)); } @@ -176,6 +192,10 @@ void SALOMEDS_AttributeTreeNode_i::Append(SALOMEDS::AttributeTreeNode_ptr value) { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->Append(GetNode(value, aNode)); } @@ -184,6 +204,10 @@ void SALOMEDS_AttributeTreeNode_i::Prepend(SALOMEDS::AttributeTreeNode_ptr value { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->Prepend(GetNode(value, aNode)); } @@ -192,6 +216,10 @@ void SALOMEDS_AttributeTreeNode_i::InsertBefore(SALOMEDS::AttributeTreeNode_ptr { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->InsertBefore(GetNode(value, aNode)); } @@ -200,6 +228,10 @@ void SALOMEDS_AttributeTreeNode_i::InsertAfter(SALOMEDS::AttributeTreeNode_ptr v { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(value)); + if(CORBA::is_nil(value)) return; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); aNode->InsertAfter(GetNode(value, aNode)); } @@ -229,6 +261,9 @@ CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsRoot() CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsDescendant(SALOMEDS::AttributeTreeNode_ptr value) { SALOMEDS::Locker lock; + + if(CORBA::is_nil(value)) return false; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); return aNode->IsDescendant(GetNode(value, aNode)); } @@ -236,6 +271,9 @@ CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsDescendant(SALOMEDS::AttributeTre CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsFather(SALOMEDS::AttributeTreeNode_ptr value) { SALOMEDS::Locker lock; + + if(CORBA::is_nil(value)) return false; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); return aNode->IsFather(GetNode(value, aNode)); } @@ -243,6 +281,9 @@ CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsFather(SALOMEDS::AttributeTreeNod CORBA::Boolean SALOMEDS_AttributeTreeNode_i::IsChild(SALOMEDS::AttributeTreeNode_ptr value) { SALOMEDS::Locker lock; + + if(CORBA::is_nil(value)) return false; + Handle(SALOMEDSImpl_AttributeTreeNode) aNode = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(_impl); return aNode->IsChild(GetNode(value, aNode)); } diff --git a/src/SALOMEDS/SALOMEDS_GenericAttribute.cxx b/src/SALOMEDS/SALOMEDS_GenericAttribute.cxx index f7d837568..1d24f0d10 100644 --- a/src/SALOMEDS/SALOMEDS_GenericAttribute.cxx +++ b/src/SALOMEDS/SALOMEDS_GenericAttribute.cxx @@ -138,6 +138,8 @@ SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute { SALOMEDS::Locker lock; + if(theGA.IsNull()) return NULL; + SALOMEDS_GenericAttribute* aGA = NULL; std::string aTypeOfAttribute = theGA->GetClassType().ToCString(); __CreateGenericClientAttributeLocal @@ -146,6 +148,8 @@ SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDS::GenericAttribute_ptr theGA) { + if(CORBA::is_nil(theGA)) return NULL; + SALOMEDS_GenericAttribute* aGA = NULL; std::string aTypeOfAttribute = theGA->GetClassType(); __CreateGenericClientAttributeCORBA diff --git a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx index 8ab64d6ab..154aa72c4 100644 --- a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx +++ b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx @@ -118,6 +118,8 @@ SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute _mapOfAttrib[theAttr.operator->()] = attr_servant; } */ + if(theAttr.IsNull()) return SALOMEDS::GenericAttribute::_nil(); + // mpv: now servants Destroyed by common algos of CORBA char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute):: DownCast(theAttr)->GetClassType().ToCString(); diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 207684032..66649fd8d 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -405,8 +405,14 @@ std::vector SALOMEDS_Study::GetComponentNames(const std::string& th _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO) { + + ASSERT(theSO); + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); SALOMEDSClient_ChildIterator* aCI = NULL; + + if(!theSO) return _PTR(ChildIterator)(aCI); + if (_isLocal) { SALOMEDS::Locker lock; @@ -548,7 +554,10 @@ void SALOMEDS_Study::StudyId(int id) std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO) { + ASSERT(theSO); std::vector<_PTR(SObject)> aVector; + if(!theSO) return aVector; + SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); int aLength, i; if (_isLocal) { diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx index 277ceebb9..197da3b57 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder.cxx @@ -98,7 +98,8 @@ _PTR(SComponent) SALOMEDS_StudyBuilder::NewComponent(const std::string& Componen void SALOMEDS_StudyBuilder::DefineComponentInstance (const _PTR(SComponent)& theSCO, const std::string& ComponentIOR) { - if(theSCO) return; + ASSERT(theSCO); + if(!theSCO) return; SALOMEDS_SComponent* aSCO = dynamic_cast(theSCO.get()); if (_isLocal) { @@ -116,7 +117,9 @@ void SALOMEDS_StudyBuilder::DefineComponentInstance (const _PTR(SComponent)& the void SALOMEDS_StudyBuilder::RemoveComponent(const _PTR(SComponent)& theSCO) { + ASSERT(theSCO); if(!theSCO) return; + SALOMEDS_SComponent* aSCO = dynamic_cast(theSCO.get()); if (_isLocal) { CheckLocked(); @@ -131,6 +134,8 @@ _PTR(SObject) SALOMEDS_StudyBuilder::NewObject(const _PTR(SObject)& theFatherObj { CheckLocked(); + ASSERT(theFatherObject); + SALOMEDSClient_SObject* aSO = NULL; SALOMEDS_SObject* father = dynamic_cast< SALOMEDS_SObject*>(theFatherObject.get()); if (father == NULL) return _PTR(SObject)(aSO); @@ -154,6 +159,9 @@ _PTR(SObject) SALOMEDS_StudyBuilder::NewObjectToTag(const _PTR(SObject)& theFath { CheckLocked(); + ASSERT(theFatherObject); + ASSERT(theTag > 0); + SALOMEDSClient_SObject* aSO = NULL; SALOMEDS_SObject* father = dynamic_cast< SALOMEDS_SObject*>(theFatherObject.get()); if (father == NULL) return _PTR(SObject)(aSO); @@ -192,7 +200,9 @@ void SALOMEDS_StudyBuilder::AddDirectory(const std::string& thePath) void SALOMEDS_StudyBuilder::LoadWith(const _PTR(SComponent)& theSCO, const std::string& theIOR) { - if(!theSCO) return; + ASSERT(theSCO); + if(!theSCO) + THROW_SALOME_CORBA_EXCEPTION("Null SComponent", SALOME::BAD_PARAM); SALOMEDS_SComponent* aSCO = dynamic_cast(theSCO.get()); CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str()); @@ -216,6 +226,10 @@ void SALOMEDS_StudyBuilder::LoadWith(const _PTR(SComponent)& theSCO, const std:: void SALOMEDS_StudyBuilder::Load(const _PTR(SObject)& theSCO) { + ASSERT(theSCO); + if(!theSCO) + THROW_SALOME_CORBA_EXCEPTION("Null SComponent", SALOME::BAD_PARAM); + SALOMEDS_SComponent* aSCO = dynamic_cast(theSCO.get()); if (_isLocal) _local_impl->Load(Handle(SALOMEDSImpl_SComponent)::DownCast(aSCO->GetLocalImpl())); else _corba_impl->Load(SALOMEDS::SComponent::_narrow(aSCO->GetCORBAImpl())); @@ -223,6 +237,7 @@ void SALOMEDS_StudyBuilder::Load(const _PTR(SObject)& theSCO) void SALOMEDS_StudyBuilder::RemoveObject(const _PTR(SObject)& theSO) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -237,6 +252,7 @@ void SALOMEDS_StudyBuilder::RemoveObject(const _PTR(SObject)& theSO) void SALOMEDS_StudyBuilder::RemoveObjectWithChildren(const _PTR(SObject)& theSO) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -252,6 +268,8 @@ void SALOMEDS_StudyBuilder::RemoveObjectWithChildren(const _PTR(SObject)& theSO) _PTR(GenericAttribute) SALOMEDS_StudyBuilder::FindOrCreateAttribute(const _PTR(SObject)& theSO, const std::string& aTypeOfAttribute) { + ASSERT(theSO); + SALOMEDSClient_GenericAttribute* anAttr = NULL; if(!theSO) return _PTR(GenericAttribute)(anAttr); SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -304,6 +322,7 @@ bool SALOMEDS_StudyBuilder::FindAttribute(const _PTR(SObject)& theSO, void SALOMEDS_StudyBuilder::RemoveAttribute(const _PTR(SObject)& theSO, const std::string& aTypeOfAttribute) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -318,6 +337,8 @@ void SALOMEDS_StudyBuilder::RemoveAttribute(const _PTR(SObject)& theSO, const st void SALOMEDS_StudyBuilder::Addreference(const _PTR(SObject)& me, const _PTR(SObject)& thereferencedObject) { + ASSERT(me); + ASSERT(thereferencedObject); if(!me || !thereferencedObject) return; SALOMEDS_SObject* aSO = dynamic_cast(me.get()); @@ -333,6 +354,7 @@ void SALOMEDS_StudyBuilder::Addreference(const _PTR(SObject)& me, const _PTR(SOb void SALOMEDS_StudyBuilder::RemoveReference(const _PTR(SObject)& me) { + ASSERT(me); if(!me) return; SALOMEDS_SObject* aSO = dynamic_cast(me.get()); if (_isLocal) { @@ -346,6 +368,7 @@ void SALOMEDS_StudyBuilder::RemoveReference(const _PTR(SObject)& me) void SALOMEDS_StudyBuilder::SetGUID(const _PTR(SObject)& theSO, const std::string& theGUID) { + ASSERT(theSO); if(!theSO) return; if(!Standard_GUID::CheckGUIDFormat((char*)theGUID.c_str())) throw invalid_argument("Invalid GUID"); @@ -361,6 +384,7 @@ void SALOMEDS_StudyBuilder::SetGUID(const _PTR(SObject)& theSO, const std::strin bool SALOMEDS_StudyBuilder::IsGUID(const _PTR(SObject)& theSO, const std::string& theGUID) { + ASSERT(theSO); if(!theSO || !Standard_GUID::CheckGUIDFormat((char*)theGUID.c_str())) return false; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -506,6 +530,7 @@ void SALOMEDS_StudyBuilder::CheckLocked() void SALOMEDS_StudyBuilder::SetName(const _PTR(SObject)& theSO, const std::string& theValue) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -520,6 +545,7 @@ void SALOMEDS_StudyBuilder::SetName(const _PTR(SObject)& theSO, const std::strin void SALOMEDS_StudyBuilder::SetComment(const _PTR(SObject)& theSO, const std::string& theValue) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); @@ -534,6 +560,7 @@ void SALOMEDS_StudyBuilder::SetComment(const _PTR(SObject)& theSO, const std::st void SALOMEDS_StudyBuilder::SetIOR(const _PTR(SObject)& theSO, const std::string& theValue) { + ASSERT(theSO); if(!theSO) return; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx index 87adc2db8..3409937fd 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx @@ -94,6 +94,10 @@ void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr a { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(aComponent)); + if(CORBA::is_nil(aComponent)) return; + Handle(SALOMEDSImpl_SComponent) aSCO; aSCO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSComponent((char*)aComponent->GetID()); @@ -110,7 +114,10 @@ void SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponen { SALOMEDS::Locker lock; CheckLocked(); + ASSERT(!CORBA::is_nil(aComponent)); + if(CORBA::is_nil(aComponent)) return; + Handle(SALOMEDSImpl_SComponent) aSCO; aSCO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSComponent((char*)aComponent->GetID()); _impl->RemoveComponent(aSCO); @@ -125,7 +132,10 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr t { SALOMEDS::Locker lock; CheckLocked(); - + + ASSERT(!CORBA::is_nil(theFatherObject)); + if(CORBA::is_nil(theFatherObject)) return SALOMEDS::SObject::_nil(); + Handle(SALOMEDSImpl_SObject) aFO, aSO; aFO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theFatherObject->GetID()); aSO = _impl->NewObject(aFO); @@ -145,6 +155,10 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(theFatherObject)); + if(CORBA::is_nil(theFatherObject)) return SALOMEDS::SObject::_nil(); + Handle(SALOMEDSImpl_SObject) aFO, aSO; aFO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theFatherObject->GetID()); aSO = _impl->NewObjectToTag(aFO, atag); @@ -162,6 +176,10 @@ void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject) { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); _impl->RemoveObject(aSO); @@ -176,6 +194,10 @@ void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anO { SALOMEDS::Locker lock; CheckLocked(); + + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); _impl->RemoveObjectWithChildren(aSO); @@ -192,11 +214,19 @@ void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO, SALOMEDS::Locker lock; Unexpect aCatch(SBSalomeException); - Handle(SALOMEDSImpl_SComponent) aSCO; - aSCO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSComponent((char*)anSCO->GetID()); - SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb); - bool isDone = _impl->LoadWith(aSCO, driver); - delete driver; + ASSERT(!CORBA::is_nil(anSCO)); + + bool isDone = false; + + if(!CORBA::is_nil(anSCO)) { + + Handle(SALOMEDSImpl_SComponent) aSCO; + aSCO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSComponent((char*)anSCO->GetID()); + SALOMEDS_Driver_i* driver = new SALOMEDS_Driver_i(aDriver, _orb); + isDone = _impl->LoadWith(aSCO, driver); + delete driver; + + } if(!isDone && _impl->IsError()) { THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().ToCString(),SALOME::BAD_PARAM); @@ -224,9 +254,14 @@ SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SA const char* aTypeOfAttribute) { SALOMEDS::Locker lock; + ASSERT(!CORBA::is_nil(anObject)); + + if(CORBA::is_nil(anObject)) return SALOMEDS::GenericAttribute::_nil(); + Handle(SALOMEDSImpl_SObject) aSO; CORBA::String_var anID = anObject->GetID(); aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject(anID.inout()); + Handle(TDF_Attribute) anAttr; try { anAttr = _impl->FindOrCreateAttribute(aSO, TCollection_AsciiString((char*)aTypeOfAttribute)); @@ -252,7 +287,10 @@ CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anOb const char* aTypeOfAttribute) { SALOMEDS::Locker lock; + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return false; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); Handle(TDF_Attribute) anAttr; @@ -274,7 +312,10 @@ void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject, { SALOMEDS::Locker lock; CheckLocked(); + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); _impl->RemoveAttribute(aSO, TCollection_AsciiString((char*)aTypeOfAttribute)); @@ -290,9 +331,11 @@ void SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me, { SALOMEDS::Locker lock; CheckLocked(); + ASSERT(!CORBA::is_nil(me)); ASSERT(!CORBA::is_nil(theReferencedObject)); - + if(CORBA::is_nil(me) || CORBA::is_nil(theReferencedObject)) return; + Handle(SALOMEDSImpl_SObject) aSO, aRefSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)me->GetID()); aRefSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theReferencedObject->GetID()); @@ -308,7 +351,10 @@ void SALOMEDS_StudyBuilder_i::RemoveReference(SALOMEDS::SObject_ptr me) { SALOMEDS::Locker lock; CheckLocked(); + ASSERT(!CORBA::is_nil(me)); + if(CORBA::is_nil(me)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)me->GetID()); _impl->RemoveReference(aSO); @@ -343,7 +389,10 @@ void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char { SALOMEDS::Locker lock; CheckLocked(); + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); _impl->SetGUID(aSO, TCollection_AsciiString((char*)theGUID)); @@ -357,7 +406,10 @@ void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID) { SALOMEDS::Locker lock; + ASSERT(!CORBA::is_nil(anObject)); + if(CORBA::is_nil(anObject)) return false; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)anObject->GetID()); return _impl->IsGUID(aSO, TCollection_AsciiString((char*)theGUID)); @@ -524,6 +576,9 @@ void SALOMEDS_StudyBuilder_i::SetName(SALOMEDS::SObject_ptr theSO, const char* t SALOMEDS::Locker lock; Unexpect aCatch(SBLockProtection); CheckLocked(); + + ASSERT(!CORBA::is_nil(theSO)); + if(CORBA::is_nil(theSO)) return; Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theSO->GetID()); @@ -542,6 +597,9 @@ void SALOMEDS_StudyBuilder_i::SetComment(SALOMEDS::SObject_ptr theSO, const char Unexpect aCatch(SBLockProtection); CheckLocked(); + ASSERT(!CORBA::is_nil(theSO)); + if(CORBA::is_nil(theSO)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theSO->GetID()); _impl->SetComment(aSO, TCollection_AsciiString((char*)theValue)); @@ -559,6 +617,9 @@ void SALOMEDS_StudyBuilder_i::SetIOR(SALOMEDS::SObject_ptr theSO, const char* th Unexpect aCatch(SBLockProtection); CheckLocked(); + ASSERT(!CORBA::is_nil(theSO)); + if(CORBA::is_nil(theSO)) return; + Handle(SALOMEDSImpl_SObject) aSO; aSO = Handle(SALOMEDSImpl_Study)::DownCast(_impl->GetOwner())->GetSObject((char*)theSO->GetID()); _impl->SetIOR(aSO, TCollection_AsciiString((char*)theValue)); diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx index 617f7c194..d928f4ca2 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx @@ -352,6 +352,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::CanCopy(SALOMEDS::SObject_ptr theObject) { SALOMEDS::Locker lock; + if(CORBA::is_nil(theObject)) return false; + SALOMEDS::Study_var aStudy = theObject->GetStudy(); Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID()); @@ -371,6 +373,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::Copy(SALOMEDS::SObject_ptr theObject) { SALOMEDS::Locker lock; + if(CORBA::is_nil(theObject)) return false; + SALOMEDS::Study_var aStudy = theObject->GetStudy(); Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID()); @@ -390,6 +394,8 @@ CORBA::Boolean SALOMEDS_StudyManager_i::CanPaste(SALOMEDS::SObject_ptr theObject { SALOMEDS::Locker lock; + if(CORBA::is_nil(theObject)) return false; + SALOMEDS::Study_var aStudy = theObject->GetStudy(); Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); Handle(SALOMEDSImpl_SObject) anObject = aStudyImpl->GetSObject((char*)theObject->GetID()); @@ -411,6 +417,9 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theOb SALOMEDS::Locker lock; Unexpect aCatch(LockProtection); + + if(CORBA::is_nil(theObject)) return SALOMEDS::SObject::_nil(); + SALOMEDS::Study_var aStudy = theObject->GetStudy(); Handle(SALOMEDSImpl_Study) aStudyImpl = _impl->GetStudyByID(aStudy->StudyId()); @@ -434,6 +443,8 @@ SALOMEDS::SObject_ptr SALOMEDS_StudyManager_i::Paste(SALOMEDS::SObject_ptr theOb SALOMEDS_Driver_i* GetDriver(const Handle(SALOMEDSImpl_SObject)& theObject, CORBA::ORB_ptr orb) { SALOMEDS_Driver_i* driver = NULL; + + if(theObject.IsNull()) return driver; Handle(SALOMEDSImpl_SComponent) aSCO = theObject->GetFatherComponent(); if(!aSCO.IsNull()) { diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index d23ace255..f3ce6f382 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -431,6 +431,9 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject { SALOMEDS::Locker lock; + ASSERT(!CORBA::is_nil(theSO)); + if(CORBA::is_nil(theSO)) return SALOMEDS::ChildIterator::_nil(); + Handle(SALOMEDSImpl_SObject) aSO = _impl->GetSObject(theSO->GetID()); Handle(SALOMEDSImpl_ChildIterator) anItr = new SALOMEDSImpl_ChildIterator(aSO); @@ -567,6 +570,9 @@ SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA:: { SALOMEDS::Locker lock; + ASSERT(!theLabel.IsNull()); + if(theLabel.IsNull()) return SALOMEDS::Study::_nil(); + Handle(SALOMEDSImpl_AttributeIOR) Att; if (theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),Att)){ char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Value()).ToCString()); @@ -590,10 +596,14 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObj { SALOMEDS::Locker lock; - SALOMEDS::GenericAttribute_ptr aTarget; - if (anObject->FindAttribute(aTarget,"AttributeTarget")) { - return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get(); + ASSERT(!CORBA::is_nil(anObject)); + if(!CORBA::is_nil(anObject)) { + SALOMEDS::GenericAttribute_ptr aTarget; + if (anObject->FindAttribute(aTarget,"AttributeTarget")) { + return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get(); + } } + SALOMEDS::Study::ListOfSObject* aList = new SALOMEDS::Study::ListOfSObject; aList->length(0); return aList;