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();
}
}
#include <gp_Ax1.hxx>
-#define MY_AX1 static_cast<gp_Ax1*>(myImpl)
+#define MY_AX1 implPtr<gp_Ax1>()
//=================================================================================================
GeomAPI_Ax1::GeomAPI_Ax1()
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
+}
#include <Precision.hxx>
-#define MY_AX3 static_cast<gp_Ax3*>(myImpl)
+#define MY_AX3 implPtr<gp_Ax3>()
GeomAPI_Ax3::GeomAPI_Ax3()
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
+}
#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)
{
#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)
#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)
GeomAPI_DataMapOfShapeShape::~GeomAPI_DataMapOfShapeShape()
{
- if (myImpl) {
- implPtr<TopTools_DataMapOfShapeShape>()->Clear();
+ if (!empty()) {
+ implPtr<TopTools_DataMapOfShapeShape>()->Clear();
//delete myImpl;
}
- }
\ No newline at end of file
+ }
#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))
#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))
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;
}
#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();
/// 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
#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)
#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)
#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))
#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))
#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())
#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()
#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))
#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))
//============================================================================
GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion()
{
- if (myImpl) {
- myMap.clear();
+ if (!empty()) {
+ myMap.clear();
}
-}
\ No newline at end of file
+}
//============================================================================
GeomAlgoAPI_Placement::~GeomAlgoAPI_Placement()
{
- if (myImpl)
+ if (!empty())
myMap.clear();
}