0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / TNaming / TNaming_NamedShape.cxx
index 21b634f..d09714f 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <TNaming_NamedShape.ixx>
-#include <TNaming_Builder.ixx>
 
-#include <TDF_Label.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <gp_Pnt.hxx>
+#include <Standard.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_GUID.hxx>
+#include <Standard_NoMoreObject.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_NullObject.hxx>
+#include <Standard_Type.hxx>
+#include <TDF_Attribute.hxx>
+#include <TDF_AttributeDelta.hxx>
+#include <TDF_AttributeIterator.hxx>
 #include <TDF_Data.hxx>
+#include <TDF_DataSet.hxx>
 #include <TDF_DeltaOnAddition.hxx>
-#include <TDF_AttributeIterator.hxx>
-#include <TNaming_PtrNode.hxx>
-#include <TNaming_PtrRefShape.hxx>
-#include <TNaming_RefShape.hxx>
-#include <TNaming_PtrDataMapOfShapePtrRefShape.hxx>
-#include <TNaming_UsedShapes.hxx>
-#include <TNaming_Tool.hxx>
+#include <TDF_DeltaOnModification.hxx>
+#include <TDF_DeltaOnRemoval.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_RelocationTable.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_CopyShape.hxx>
+#include <TNaming_DeltaOnModification.hxx>
+#include <TNaming_DeltaOnRemoval.hxx>
 #include <TNaming_Iterator.hxx>
+#include <TNaming_NamedShape.hxx>
 #include <TNaming_NewShapeIterator.hxx>
 #include <TNaming_OldShapeIterator.hxx>
+#include <TNaming_PtrNode.hxx>
+#include <TNaming_PtrRefShape.hxx>
+#include <TNaming_RefShape.hxx>
 #include <TNaming_SameShapeIterator.hxx>
-
-#include <TNaming_DeltaOnModification.hxx>
-#include <TNaming_DeltaOnRemoval.hxx>
-#include <Standard_NoMoreObject.hxx>
-#include <Standard_NoSuchObject.hxx>
-#include <Standard_ConstructionError.hxx>
-#include <Standard_NullObject.hxx>
-
-#include <gp_Pnt.hxx>
-#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <TNaming_Tool.hxx>
+#include <TNaming_UsedShapes.hxx>
+#include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
 
-// Defines the nodes classes
-
-#include <Standard.hxx>
-#include <TNaming_CopyShape.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(TNaming_NamedShape,TDF_Attribute)
 
-#define BUC60921   //SRN 15/05/01 : Fixes the memory leak due to pointer to RefShape is not deleted
+// Defines the nodes classes
 //#define MDTV_DEB_HASL
 //=======================================================================
 //function : GetID
 //purpose  : 
 //=======================================================================
-
 const Standard_GUID& TNaming_NamedShape::GetID() 
 {
   static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
@@ -190,14 +194,12 @@ static void RemoveNode(Standard_Boolean                   MapExist ,
         // le shape disparait
         if (MapExist)
           M.UnBind(pos->Shape());
-        //#ifdef BUC60921
         N->myOld = 0L;
         if(pos != N->myNew)
         {
           delete pos;
           pos = 0L;
         }
-        //#endif 
       }
     }
     else {
@@ -256,7 +258,7 @@ static void RemoveNode(Standard_Boolean                   MapExist ,
 void TNaming_NamedShape::Clear()
 {
   if (Label().IsNull()) {
-#ifdef DEB_BUILDER
+#ifdef OCCT_DEBUG_BUILDER
     cout << "attention etat fantomatique" << endl;
 #endif
     return;
@@ -426,7 +428,7 @@ Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
 (const Handle(TDF_Attribute)& anOldAttribute) const
 {
   
-  return new TNaming_DeltaOnModification(*((Handle(TNaming_NamedShape)*)&anOldAttribute));
+  return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute));
 }
 
 //=======================================================================
@@ -665,7 +667,7 @@ void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
   TNaming_RefShape* pns;
   
   if (myShapes->myMap.IsBound(newShape)) {
-#ifdef DEB_BUILDER
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
 #endif
     pns = myShapes->myMap.ChangeFind(newShape);
@@ -706,7 +708,7 @@ void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
   if (myShapes->myMap.IsBound(oldShape)) 
     pos = myShapes->myMap.ChangeFind(oldShape); 
   else {
-#ifdef DEB_BUILDER
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
 #endif
     pos = new TNaming_RefShape(oldShape);  
@@ -732,7 +734,7 @@ void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
   }
 
   if (oldShape.IsSame(newShape)) {
-#ifdef DEB_BUILDER
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
 #endif
     return;
@@ -775,7 +777,7 @@ void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
   }
 
   if (oldShape.IsSame(newShape)) {
-#ifdef DEB_BUILDER
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
 #endif
     return;
@@ -879,13 +881,13 @@ TNaming_Iterator::TNaming_Iterator(const TDF_Label&       Lab,
                                   const Standard_Integer Trans)
 :myTrans(Trans)
 {
-  Handle(TNaming_NamedShape) Att;
+  Handle(TDF_Attribute) Att;
   if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
-    myNode = Att->myNode;
+    myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode;
   }
   else {
     myNode = 0L;
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout <<"TNaming_Iterator : No Shape for this label"<<endl;
 #endif
   }
@@ -1015,10 +1017,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Standard_Integer            Trans,
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
-{
-  Standard_Boolean  Old = Standard_True;  
-  TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+{ 
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                    "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");  
+  TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);  
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_True); 
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1034,10 +1038,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 :myTrans(Trans)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {    
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1050,14 +1056,16 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1072,9 +1080,11 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {
-  Standard_Boolean  Old = Standard_True;  
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+   Standard_Boolean  Old(Standard_True);  
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1090,8 +1100,10 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    Standard_Boolean  Old(Standard_True);  
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
     SelectSameShape(myNode,Old,RS,myTrans);
   }
@@ -1105,7 +1117,8 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
   myNode = anIterator.myNode;
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
@@ -1113,6 +1126,7 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1124,9 +1138,9 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
 
 void TNaming_NewShapeIterator::Next() 
 {
-  Standard_Boolean  Old = Standard_True;
   TNaming_RefShape* RS  = myNode->myOld;
   myNode = myNode->NextSameShape(RS);
+  Standard_Boolean  Old(Standard_True);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1194,9 +1208,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
 {
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1213,9 +1229,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_False;
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");    
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1229,9 +1247,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {  
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1246,10 +1266,12 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 :myTrans(-1)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {  
-    Standard_Boolean  Old = Standard_False;
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1262,14 +1284,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode; 
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1282,14 +1306,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIt
 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myOld;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1457,7 +1483,7 @@ Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label&    access,
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
     return (US->Map().IsBound(S));
   }
-#ifdef MDTV_DEB_HASL
+#ifdef OCCT_DEBUG_HASL
   cout << "##==> Sub-Shape has no Label!" <<endl;
 #endif
   return Standard_False;