0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / TNaming / TNaming_NamedShape.cxx
index 2d0930b..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_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)
 
+// 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");
@@ -422,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));
 }
 
 //=======================================================================
@@ -875,9 +881,9 @@ 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;
@@ -1011,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);
 }
 
@@ -1030,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);
   }
 }
@@ -1046,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);
   }
 }
@@ -1068,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);
 }
 
@@ -1086,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);
   }
@@ -1101,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) 
@@ -1109,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);
   }
 }
@@ -1120,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);
 }
 
@@ -1190,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);
 }
 
@@ -1209,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);
   }
 }
@@ -1225,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);
 }
 
@@ -1242,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);
   }
 }
@@ -1258,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);
   }
 }
@@ -1278,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);
   }
 }