]> OCCT Git - occt.git/commitdiff
Coding - Refactor TopoDS.hxx #221
authordpasukhi <dpasukhi@opencascade.com>
Sat, 28 Dec 2024 21:39:33 +0000 (21:39 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Sat, 28 Dec 2024 21:49:09 +0000 (21:49 +0000)
Remove TopoDS.lxx and move inline definition to declarations.
Refactor TopoDS.hxx with more detailed description.

src/TopoDS/FILES
src/TopoDS/TopoDS.hxx
src/TopoDS/TopoDS.lxx [deleted file]

index d7e34f3cb2e14393d87c19e8175271ce40d883d1..792c01637c93f92762c299bb902a388522f3704e 100644 (file)
@@ -1,5 +1,4 @@
 TopoDS.hxx
-TopoDS.lxx
 TopoDS_AlertAttribute.hxx
 TopoDS_AlertAttribute.cxx
 TopoDS_Builder.cxx
index 4803790d9dd49fd039ad2075561f18f54efe1850..4de7e219d475c4b2ac458d39a99dea069e328591 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <Standard.hxx>
 #include <Standard_DefineAlloc.hxx>
+#include <Standard_TypeMismatch.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopoDS_Shape.hxx>
 
 class TopoDS_Vertex;
 class TopoDS_Shape;
@@ -29,92 +32,202 @@ class TopoDS_Shell;
 class TopoDS_Solid;
 class TopoDS_CompSolid;
 class TopoDS_Compound;
-class TopoDS_Shape;
 class TopoDS_HShape;
 class TopoDS_TShape;
 class TopoDS_TVertex;
-class TopoDS_Vertex;
 class TopoDS_TEdge;
-class TopoDS_Edge;
 class TopoDS_TWire;
-class TopoDS_Wire;
 class TopoDS_TFace;
-class TopoDS_Face;
 class TopoDS_TShell;
-class TopoDS_Shell;
 class TopoDS_TSolid;
-class TopoDS_Solid;
 class TopoDS_TCompSolid;
-class TopoDS_CompSolid;
 class TopoDS_TCompound;
-class TopoDS_Compound;
 class TopoDS_Builder;
 class TopoDS_Iterator;
 
-
-//! Provides methods to cast objects of class
-//! TopoDS_Shape to be objects of more specialized
-//! sub-classes. Types are verified, thus in the example
-//! below, the first two blocks are correct but the third is
-//! rejected by the compiler.
-class TopoDS 
+//! Provides methods to cast objects of class TopoDS_Shape to more specialized
+//! sub-classes. The types are not verified before casting. If the type does
+//! not match, a Standard_TypeMismatch exception is thrown. Below are examples
+//! of correct and incorrect casts:
+//!
+//! Correct:
+//! @code
+//! TopoDS_Shape aShape = ...; // aShape->ShapeType() == TopAbs_VERTEX
+//! const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+//! @endcode
+//!
+//! Incorrect (will throw a Standard_TypeMismatch exception):
+//! @code
+//! TopoDS_Shape aShape = ...; // aShape->ShapeType() == TopAbs_VERTEX
+//! const TopoDS_Face& face = TopoDS::Edge(aShape);
+//! @endcode
+namespace TopoDS
 {
-public:
-
-  DEFINE_STANDARD_ALLOC
-
-  
-  //! Basic tool to access the data structure.
-  //! Casts shape S to the more specialized return type, Vertex.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Vertex& Vertex (const TopoDS_Shape& S);
-inline static TopoDS_Vertex& Vertex(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Edge
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Edge& Edge (const TopoDS_Shape& S);
-inline static TopoDS_Edge& Edge(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Wire.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Wire& Wire (const TopoDS_Shape& S);
-inline static TopoDS_Wire& Wire(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Face.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Face& Face (const TopoDS_Shape& S);
-inline static TopoDS_Face& Face(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Shell.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Shell& Shell (const TopoDS_Shape& S);
-inline static TopoDS_Shell& Shell(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Solid.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Solid& Solid (const TopoDS_Shape& S);
-inline static TopoDS_Solid& Solid(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, CompSolid.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_CompSolid& CompSolid (const TopoDS_Shape& S);
-inline static TopoDS_CompSolid& CompSolid(TopoDS_Shape&);
-  
-  //! Casts shape S to the more specialized return type, Compound.
-  //! Exceptions
-  //! Standard_TypeMismatch if S cannot be cast to this return type.
-    static const TopoDS_Compound& Compound (const TopoDS_Shape& S);
-inline static TopoDS_Compound& Compound(TopoDS_Shape&);
-
-};
-
-#include <TopoDS.lxx>
+  //! Casts shape theShape to the more specialized return type, Vertex.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Vertex
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Vertex& Vertex(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_VERTEX,
+                                   "TopoDS::Vertex");
+    return *(TopoDS_Vertex*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Vertex.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Vertex
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Vertex& Vertex(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_VERTEX,
+                                   "TopoDS::Vertex");
+    return *(TopoDS_Vertex*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Edge.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Edge
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Edge& Edge(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_EDGE, "TopoDS::Edge");
+    return *(TopoDS_Edge*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Edge.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Edge
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Edge& Edge(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_EDGE, "TopoDS::Edge");
+    return *(TopoDS_Edge*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Wire.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Wire
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Wire& Wire(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_WIRE, "TopoDS::Wire");
+    return *(TopoDS_Wire*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Wire.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Wire
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Wire& Wire(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_WIRE, "TopoDS::Wire");
+    return *(TopoDS_Wire*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Face.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Face
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Face& Face(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_FACE, "TopoDS::Face");
+    return *(TopoDS_Face*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Face.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Face
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Face& Face(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_FACE, "TopoDS::Face");
+    return *(TopoDS_Face*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Shell.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Shell
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Shell& Shell(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_SHELL, "TopoDS::Shell");
+    return *(TopoDS_Shell*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Shell.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Shell
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Shell& Shell(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_SHELL, "TopoDS::Shell");
+    return *(TopoDS_Shell*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Solid.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Solid
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Solid& Solid(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_SOLID, "TopoDS::Solid");
+    return *(TopoDS_Solid*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Solid.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Solid
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Solid& Solid(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_SOLID, "TopoDS::Solid");
+    return *(TopoDS_Solid*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, CompSolid.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_CompSolid
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_CompSolid& CompSolid(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_COMPSOLID,
+                                   "TopoDS::CompSolid");
+    return *(TopoDS_CompSolid*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, CompSolid.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_CompSolid
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_CompSolid& CompSolid(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_COMPSOLID,
+                                   "TopoDS::CompSolid");
+    return *(TopoDS_CompSolid*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Compound.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Compound
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline const TopoDS_Compound& Compound(const TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_COMPOUND,
+                                   "TopoDS::Compound");
+    return *(TopoDS_Compound*)&theShape;
+  }
+
+  //! Casts shape theShape to the more specialized return type, Compound.
+  //! @param theShape the shape to be cast
+  //! @return the casted shape as TopoDS_Compound
+  //! @throws Standard_TypeMismatch if theShape cannot be cast to this return type.
+  inline TopoDS_Compound& Compound(TopoDS_Shape& theShape)
+  {
+    Standard_TypeMismatch_Raise_if(theShape.IsNull() ? Standard_False : theShape.ShapeType() != TopAbs_COMPOUND,
+                                   "TopoDS::Compound");
+    return *(TopoDS_Compound*)&theShape;
+  }
+}
 
 #endif // _TopoDS_HeaderFile
diff --git a/src/TopoDS/TopoDS.lxx b/src/TopoDS/TopoDS.lxx
deleted file mode 100644 (file)
index f1acd92..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-// Created on: 1993-03-08
-// Created by: Remi LEQUETTE
-// Copyright (c) 1993-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <TopAbs_ShapeEnum.hxx>
-#include <TopoDS_Shape.hxx>
-#include <Standard_TypeMismatch.hxx>
-
-// return True if the Shape has not the expected type
-inline static Standard_Boolean TopoDS_Mismatch(const TopoDS_Shape& S,
-                                              const TopAbs_ShapeEnum T)
-{
-  return S.IsNull() ? Standard_False : S.ShapeType() != T;
-}
-
-//=======================================================================
-//function : Vertex
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Vertex&  TopoDS::Vertex(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_VERTEX),"TopoDS::Vertex");
-  return *(TopoDS_Vertex*) &S;
-}
-
-
-//=======================================================================
-//function : Vertex
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Vertex& TopoDS::Vertex(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_VERTEX),"TopoDS::Vertex");
-  return *(TopoDS_Vertex*) &S;
-}
-
-
-//=======================================================================
-//function : Edge
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Edge&  TopoDS::Edge(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_EDGE),"TopoDS::Edge");
-  return *(TopoDS_Edge*) &S;
-}
-
-
-//=======================================================================
-//function : Edge
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Edge& TopoDS::Edge(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_EDGE),"TopoDS::Edge");
-  return *(TopoDS_Edge*) &S;
-}
-
-
-//=======================================================================
-//function : Wire
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Wire&  TopoDS::Wire(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_WIRE),"TopoDS::Wire");
-  return *(TopoDS_Wire*) &S;
-}
-
-
-//=======================================================================
-//function : Wire
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Wire& TopoDS::Wire(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_WIRE),"TopoDS::Wire");
-  return *(TopoDS_Wire*) &S;
-}
-
-
-//=======================================================================
-//function : Face
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Face&  TopoDS::Face(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_FACE),"TopoDS::Face");
-  return *(TopoDS_Face*) &S;
-}
-
-
-//=======================================================================
-//function : Face
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Face& TopoDS::Face(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_FACE),"TopoDS::Face");
-  return *(TopoDS_Face*) &S;
-}
-
-
-//=======================================================================
-//function : Shell
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Shell&  TopoDS::Shell(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_SHELL),"TopoDS::Shell");
-  return *(TopoDS_Shell*) &S;
-}
-
-
-//=======================================================================
-//function : Shell
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Shell& TopoDS::Shell(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_SHELL),"TopoDS::Shell");
-  return *(TopoDS_Shell*) &S;
-}
-
-
-//=======================================================================
-//function : Solid
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Solid&  TopoDS::Solid(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_SOLID),"TopoDS::Solid");
-  return *(TopoDS_Solid*) &S;
-}
-
-
-//=======================================================================
-//function : Solid
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Solid& TopoDS::Solid(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_SOLID),"TopoDS::Solid");
-  return *(TopoDS_Solid*) &S;
-}
-
-
-//=======================================================================
-//function : CompSolid
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_CompSolid&  TopoDS::CompSolid(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_COMPSOLID),"TopoDS::CompSolid");
-  return *(TopoDS_CompSolid*) &S;
-}
-
-
-//=======================================================================
-//function : CompSolid
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_CompSolid& TopoDS::CompSolid(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_COMPSOLID),"TopoDS::CompSolid");
-  return *(TopoDS_CompSolid*) &S;
-}
-
-
-//=======================================================================
-//function : Compound
-//purpose  : 
-//=======================================================================
-
-inline const TopoDS_Compound&  TopoDS::Compound(const TopoDS_Shape& S)
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_COMPOUND),"TopoDS::Compound");
-  return *(TopoDS_Compound*) &S;
-}
-
-
-//=======================================================================
-//function : Compound
-//purpose  : 
-//=======================================================================
-
-inline TopoDS_Compound& TopoDS::Compound(TopoDS_Shape& S) 
-{
-  Standard_TypeMismatch_Raise_if(TopoDS_Mismatch(S,TopAbs_COMPOUND),"TopoDS::Compound");
-  return *(TopoDS_Compound*) &S;
-}
-
-