Salome HOME
Replace void* with shared_ptr<void> in GeomAPI_Interface
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 30 Jun 2015 06:02:40 +0000 (09:02 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 30 Jun 2015 07:43:24 +0000 (10:43 +0300)
21 files changed:
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_Ax1.cpp
src/GeomAPI/GeomAPI_Ax3.cpp
src/GeomAPI/GeomAPI_Circ.cpp
src/GeomAPI/GeomAPI_Circ2d.cpp
src/GeomAPI/GeomAPI_Curve.cpp
src/GeomAPI/GeomAPI_DataMapOfShapeShape.cpp
src/GeomAPI/GeomAPI_Dir.cpp
src/GeomAPI/GeomAPI_Dir2d.cpp
src/GeomAPI/GeomAPI_Interface.cpp
src/GeomAPI/GeomAPI_Interface.h
src/GeomAPI/GeomAPI_Lin.cpp
src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Pnt.cpp
src/GeomAPI/GeomAPI_Pnt2d.cpp
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_ShapeExplorer.cpp
src/GeomAPI/GeomAPI_XY.cpp
src/GeomAPI/GeomAPI_XYZ.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp

index 681926a68d3439c3235d0657e34e8bfa949167aa..2365746655bf4d095c096c00aae855a4a703e0ad 100644 (file)
@@ -43,10 +43,10 @@ GeomAPI_AISObject::GeomAPI_AISObject()
 
 GeomAPI_AISObject::~GeomAPI_AISObject()
 {
-  if (myImpl) {
+  if (!empty()) {
     // This is necessary for correct deletion of Handle entity. 
     // Without this Handle does not decremented counter to 0
-    Handle(AIS_InteractiveObject) *anAIS = (Handle(AIS_InteractiveObject)*)myImpl;
+    Handle(AIS_InteractiveObject) *anAIS = implPtr<Handle(AIS_InteractiveObject)>();
     anAIS->Nullify();
   }
 }
index dcf5a987a4803e66da6f7a2ab9dfbeb049e06bd8..65bc65bb4f60d98b1992494de568347fa9bbe073 100644 (file)
@@ -8,7 +8,7 @@
 
 #include <gp_Ax1.hxx>
 
-#define MY_AX1 static_cast<gp_Ax1*>(myImpl)
+#define MY_AX1 implPtr<gp_Ax1>()
 
 //=================================================================================================
 GeomAPI_Ax1::GeomAPI_Ax1()
@@ -63,4 +63,4 @@ std::shared_ptr<GeomAPI_Ax1> GeomAPI_Ax1::reversed()
   std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(anAxis.Location().X(), anAxis.Location().Y(), anAxis.Location().Z()));
   std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(anAxis.Direction().X(), anAxis.Direction().Y(), anAxis.Direction().Z()));
   return std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(aPnt, aDir));
-}
\ No newline at end of file
+}
index 892869a4c9a7f4593af69285648478443bb49e07..0ff482b851b19f3058616f1e20ec819409584eec 100644 (file)
@@ -15,7 +15,7 @@
 #include <Precision.hxx>
 
 
-#define MY_AX3 static_cast<gp_Ax3*>(myImpl)
+#define MY_AX3 implPtr<gp_Ax3>()
 
 
 GeomAPI_Ax3::GeomAPI_Ax3()
@@ -102,4 +102,4 @@ std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, doubl
   double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
   double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
-}
\ No newline at end of file
+}
index 807390364369856c4603231a1c8cb01d0d3690c3..34332272cc421ed08741b2b1cad5c50c7cd33f94 100644 (file)
@@ -16,7 +16,7 @@
 #include <Geom_Circle.hxx>
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 
-#define MY_CIRC static_cast<gp_Circ*>(myImpl)
+#define MY_CIRC implPtr<gp_Circ>()
 
 static gp_Circ* newCirc(const gp_Pnt& theCenter, const gp_Dir& theDir, const double theRadius)
 {
index 9871e60fb0387d510778839af5823d79d59a9234..0e0a21a310363b97656f94d14f5b6ecd05f17ee9 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <IntAna2d_AnaIntersection.hxx>
 
-#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
+#define MY_CIRC2D implPtr<gp_Circ2d>()
 
 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
                             const double theRadius)
index 46a1ea19f663732398053c879e03682ce95514e7..f96fd7b7850d7d4492dbbbf4419a85064ce66621 100644 (file)
@@ -16,7 +16,7 @@
 #include <TopoDS.hxx>
 #include <GeomAdaptor_Curve.hxx>
 
-#define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
+#define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
 
 GeomAPI_Curve::GeomAPI_Curve()
     : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
index 97e3f10683127f11da42d3fe25b3b18ba3540267..2d0ce7924c36f348ae8c0641b14f30e5eda0c717 100644 (file)
@@ -57,8 +57,8 @@ bool GeomAPI_DataMapOfShapeShape::unBind(std::shared_ptr<GeomAPI_Shape> theKey)
 
  GeomAPI_DataMapOfShapeShape::~GeomAPI_DataMapOfShapeShape()
  {
-  if (myImpl) {
-       implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+  if (!empty()) {
+    implPtr<TopTools_DataMapOfShapeShape>()->Clear();
     //delete myImpl;
   }
- }
\ No newline at end of file
+ }
index 5c42d68a0d9e6afc35664479468a23ca8701ee89..3174cea0ee8f6fe056534d21ccac6885a0116e69 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <gp_Dir.hxx>
 
-#define MY_DIR static_cast<gp_Dir*>(myImpl)
+#define MY_DIR implPtr<gp_Dir>()
 
 GeomAPI_Dir::GeomAPI_Dir(const double theX, const double theY, const double theZ)
     : GeomAPI_Interface(new gp_Dir(theX, theY, theZ))
index abb954f294e260c54d789982eb52f361cf7a9bf5..4cb8149a3999d46e55c58e674aff32820fe3523e 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <gp_Dir2d.hxx>
 
-#define MY_DIR static_cast<gp_Dir2d*>(myImpl)
+#define MY_DIR implPtr<gp_Dir2d>()
 
 GeomAPI_Dir2d::GeomAPI_Dir2d(const double theX, const double theY)
     : GeomAPI_Interface(new gp_Dir2d(theX, theY))
index 4db15c99606069265f46b225eb93d2b55b993199..05f182755a14a68d0b4d21a169aa49bc3ae4b7a4 100644 (file)
@@ -8,25 +8,15 @@
 
 GeomAPI_Interface::GeomAPI_Interface()
 {
-  myImpl = 0;
-}
 
-GeomAPI_Interface::GeomAPI_Interface(void* theImpl)
-{
-  myImpl = theImpl;
 }
 
 GeomAPI_Interface::~GeomAPI_Interface()
 {
-  if (myImpl) {
-    delete myImpl;
-    myImpl = 0;
-  }
+
 }
 
-void GeomAPI_Interface::setImpl(void* theImpl)
+bool GeomAPI_Interface::empty() const
 {
-  if (myImpl)
-    delete myImpl;
-  myImpl = theImpl;
+  return myImpl.get() == 0;
 }
index 49db964fc715e995c1495ec72bfaf704fbaa05bd..e5fac636a9bee588fde16e7b9ff40982d2a17a78 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <GeomAPI.h>
 
+#include <memory>
+
 /**\class GeomAPI_Interface
  * \ingroup DataModel
  * \brief General base class for all interfaces in this package
 
 class GEOMAPI_EXPORT GeomAPI_Interface
 {
- protected:
-  void* myImpl;  ///< pointer to the internal impl object
+ private:
+  std::shared_ptr<void> myImpl;  ///< pointer to the internal impl object
 
  public:
   /// None - constructor
   GeomAPI_Interface();
 
   /// Constructor by the impl pointer (used for internal needs)
-  GeomAPI_Interface(void* theImpl);
+  template<class T> explicit GeomAPI_Interface(T* theImpl)
+  {
+    myImpl.reset(theImpl);
+  }
 
   /// Destructor
   virtual ~GeomAPI_Interface();
@@ -32,15 +37,26 @@ class GEOMAPI_EXPORT GeomAPI_Interface
   /// Returns the pointer to the impl
   template<class T> inline T* implPtr()
   {
-    return static_cast<T*>(myImpl);
+    return static_cast<T*>(myImpl.get());
+  }
+  /// Returns the pointer to the impl
+  template<class T> inline const T* implPtr() const
+  {
+    return static_cast<T*>(myImpl.get());
   }
   /// Returns the reference object of the impl
   template<class T> inline const T& impl() const
   {
-    return *(static_cast<T*>(myImpl));
+    return *(static_cast<T*>(myImpl.get()));
   }
   /// Updates the impl (deletes the old one)
-  void setImpl(void* theImpl);
+  template<class T> inline void setImpl(T* theImpl)
+  {
+    myImpl.reset(theImpl);
+  }
+
+  // Returns true if the impl is empty
+  bool empty() const;
 };
 
 #endif
index 8b64190ba21c78a21df5824d9c4d04d5161122e9..79db6e1860b0cb21735d55a06bdd6340767665ce 100644 (file)
@@ -20,7 +20,7 @@
 #include <Precision.hxx>
 #include <ProjLib.hxx>
 
-#define MY_LIN static_cast<gp_Lin*>(myImpl)
+#define MY_LIN implPtr<gp_Lin>()
 
 static gp_Lin* newLine(const double theStartX, const double theStartY, const double theStartZ,
                        const double theEndX, const double theEndY, const double theEndZ)
index 3c784eefdbd7eb0c3b1ca1215aad9fea5128c5c5..6b53b8fdc8abbee47052c4ad5d4b75e32e18e020 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <IntAna2d_AnaIntersection.hxx>
 
-#define MY_LIN2D static_cast<gp_Lin2d*>(myImpl)
+#define MY_LIN2D implPtr<gp_Lin2d>()
 
 static gp_Lin2d* newLine2d(const double theStartX, const double theStartY, const double theEndX,
                            const double theEndY)
index 29fe933a668f87ddfab4985fbf3ff1b910e12c6a..0cf67c2ad7ae7c5b506b685c7fc17d66fac336ee 100644 (file)
@@ -14,7 +14,7 @@
 #include<gp_Pln.hxx>
 #include<ProjLib.hxx>
 
-#define MY_PNT static_cast<gp_Pnt*>(myImpl)
+#define MY_PNT implPtr<gp_Pnt>()
 
 GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ)
     : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ))
index 2bd8e3937982f62d42bc0f6c734cc4712ab2cd3d..a2bab72a78896bd3d07c080401b72fdeb8fa89e2 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <Precision.hxx>
 
-#define MY_PNT2D static_cast<gp_Pnt2d*>(myImpl)
+#define MY_PNT2D implPtr<gp_Pnt2d>()
 
 GeomAPI_Pnt2d::GeomAPI_Pnt2d(const double theX, const double theY)
     : GeomAPI_Interface(new gp_Pnt2d(theX, theY))
index f8139103c4729c638666cde2c0fa76395a8ce00d..41f1278608c1656de5fac1923b387e989653f260 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <sstream>
 
-#define MY_SHAPE static_cast<TopoDS_Shape*>(myImpl)
+#define MY_SHAPE implPtr<TopoDS_Shape>()
 
 GeomAPI_Shape::GeomAPI_Shape()
     : GeomAPI_Interface(new TopoDS_Shape())
index 3732d5afe2cbf8bbe34dd0b6c61721a5cde72b6c..6b94439c0053e1c62516fa3ba07e4886e4387b5e 100644 (file)
@@ -9,7 +9,7 @@
 #include <Standard_NoMoreObject.hxx>
 #include <TopExp_Explorer.hxx>
 
-#define MY_EXPLORER static_cast<TopExp_Explorer*>(myImpl)
+#define MY_EXPLORER implPtr<TopExp_Explorer>()
 
 //=================================================================================================
 GeomAPI_ShapeExplorer::GeomAPI_ShapeExplorer()
index 5cfeff6badaa0dc444d4d6b16a17f2eb9f1f7a10..52561d580f4c1f92d7d8c3076136810e1450da2f 100644 (file)
@@ -8,7 +8,7 @@
 
 #include<gp_XY.hxx>
 
-#define MY_XY static_cast<gp_XY*>(myImpl)
+#define MY_XY implPtr<gp_XY>()
 
 GeomAPI_XY::GeomAPI_XY(const double theX, const double theY)
     : GeomAPI_Interface(new gp_XY(theX, theY))
index 1b8e0e457f068914f6b433274b42025d7e06844e..22588c1ed63e303885758c2868472c2e5cd9635b 100644 (file)
@@ -8,7 +8,7 @@
 
 #include<gp_XYZ.hxx>
 
-#define MY_XYZ static_cast<gp_XYZ*>(myImpl)
+#define MY_XYZ implPtr<gp_XYZ>()
 
 GeomAPI_XYZ::GeomAPI_XYZ(const double theX, const double theY, const double theZ)
     : GeomAPI_Interface(new gp_XYZ(theX, theY, theZ))
index 29c4aec277baa4167af118b36f05d4f343f9e261..eecff212ae9b9ae754de6ffce161332d7c2f136f 100644 (file)
@@ -132,7 +132,7 @@ GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const
 //============================================================================
 GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
 {
-  if (myImpl) {    
-       myMap.clear();
+  if (!empty()) {
+    myMap.clear();
   }
-}
\ No newline at end of file
+}
index 58a4684ddc132325c7c3bdc78bfcfe37eaea3a2d..651e0360120efd4664a8debc614966d81d0683e5 100644 (file)
@@ -255,6 +255,6 @@ GeomAlgoAPI_MakeShape * GeomAlgoAPI_Placement::makeShape() const
 //============================================================================
 GeomAlgoAPI_Placement::~GeomAlgoAPI_Placement()
 {
-  if (myImpl)
+  if (!empty())
     myMap.clear();
 }