From bd3ce7be7ceffacd3fbdbe4dc1cb44ff9d88ac18 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Tue, 16 Dec 2025 13:18:42 +0000 Subject: [PATCH] Coding - Implement move semantics and default constructor for CSLib_Class2d (#919) - Added a default constructor to CSLib_Class2d for creating empty classifiers. - Implemented move constructor and move assignment operator to optimize resource management. - Updated IntTools_FClass2d and BRepTopAdaptor_FClass2d to utilize the new move semantics, eliminating unnecessary dynamic memory allocations. - Replaced deprecated pointer-based storage with NCollection_Sequence for better memory management. - Removed the obsolete BRepTopAdaptor_SeqOfPtr class to streamline the codebase. --- .../TKMath/CSLib/CSLib_Class2d.hxx | 40 ++++++++++++++++++- .../TKBO/IntTools/IntTools_FClass2d.cxx | 22 +++------- .../TKBO/IntTools/IntTools_FClass2d.hxx | 30 +++++++------- .../BRepTopAdaptor_FClass2d.cxx | 21 +++------- .../BRepTopAdaptor_FClass2d.hxx | 29 +++++++------- .../BRepTopAdaptor_SeqOfPtr.hxx | 24 ----------- .../TKTopAlgo/BRepTopAdaptor/FILES.cmake | 1 - 7 files changed, 82 insertions(+), 85 deletions(-) delete mode 100644 src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_SeqOfPtr.hxx diff --git a/src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx b/src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx index 961446c252..ab1e22e200 100644 --- a/src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx +++ b/src/FoundationClasses/TKMath/CSLib/CSLib_Class2d.hxx @@ -48,6 +48,9 @@ public: DEFINE_STANDARD_ALLOC + //! Default constructor. Creates an empty classifier. + CSLib_Class2d() = default; + //! Constructs a 2D classifier from an array of polygon vertices. //! //! The polygon is automatically closed (no need to repeat the first point at the end). @@ -87,6 +90,38 @@ public: double theUMax, double theVMax); + //! Move constructor. + CSLib_Class2d(CSLib_Class2d&& theOther) noexcept + : myPnts2dX(std::move(theOther.myPnts2dX)), + myPnts2dY(std::move(theOther.myPnts2dY)), + myTolU(theOther.myTolU), + myTolV(theOther.myTolV), + myPointsCount(theOther.myPointsCount), + myUMin(theOther.myUMin), + myVMin(theOther.myVMin), + myUMax(theOther.myUMax), + myVMax(theOther.myVMax) + { + } + + //! Move assignment operator. + CSLib_Class2d& operator=(CSLib_Class2d&& theOther) noexcept + { + if (this != &theOther) + { + myPnts2dX = std::move(theOther.myPnts2dX); + myPnts2dY = std::move(theOther.myPnts2dY); + myTolU = theOther.myTolU; + myTolV = theOther.myTolV; + myPointsCount = theOther.myPointsCount; + myUMin = theOther.myUMin; + myVMin = theOther.myVMin; + myUMax = theOther.myUMax; + myVMax = theOther.myVMax; + } + return *this; + } + //! Classifies a point relative to the polygon. //! //! @param[in] thePoint The 2D point to classify @@ -134,7 +169,10 @@ private: double theUMax, double theVMax); - //! Assignment operator is forbidden. + //! Copy constructor is deleted. + CSLib_Class2d(const CSLib_Class2d&) = delete; + + //! Copy assignment operator is deleted. CSLib_Class2d& operator=(const CSLib_Class2d&) = delete; private: diff --git a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.cxx b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.cxx index 214f9d15b9..a191dc78de 100644 --- a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.cxx +++ b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.cxx @@ -404,7 +404,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV gp_Pnt2d anInitPnt(0., 0.); // PClass.Init(anInitPnt); - TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); BadWire = 1; TabOrien.Append(-1); } @@ -506,8 +506,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV if (FlecheV < Toluv) FlecheV = Toluv; - TabClass.Append( - (void*)new CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); // if (std::abs(aS) < Precision::SquareConfusion()) { @@ -534,8 +533,7 @@ void IntTools_FClass2d::Init(const TopoDS_Face& aFace, const Standard_Real TolUV TabOrien.Append(-1); TColgp_Array1OfPnt2d PPClass(1, 2); SeqPnt2d.Clear(); - TabClass.Append( - (void*)new CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(SeqPnt2d, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); } } // else if(WireIsNotEmpty) } // for(; aExpF.More(); aExpF.Next()) { @@ -649,7 +647,7 @@ TopAbs_State IntTools_FClass2d::Perform(const gp_Pnt2d& _Puv, Standard_Integer n, cur, TabOrien_n; for (n = 1; n <= nbtabclass; n++) { - cur = ((CSLib_Class2d*)TabClass(n))->SiDans(Puv); + cur = TabClass(n).SiDans(Puv); TabOrien_n = TabOrien(n); if (cur == 1) @@ -809,7 +807,7 @@ TopAbs_State IntTools_FClass2d::TestOnRestriction(const gp_Pnt2d& _Puv, { for (Standard_Integer n = 1; n <= nbtabclass; n++) { - Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans_OnMode(Puv, Tol); + Standard_Integer cur = TabClass(n).SiDans_OnMode(Puv, Tol); if (cur == 1) { if (TabOrien(n) == 0) @@ -890,13 +888,5 @@ TopAbs_State IntTools_FClass2d::TestOnRestriction(const gp_Pnt2d& _Puv, IntTools_FClass2d::~IntTools_FClass2d() { - Standard_Integer nbtabclass = TabClass.Length(); - for (Standard_Integer d = 1; d <= nbtabclass; d++) - { - if (TabClass(d)) - { - delete ((CSLib_Class2d*)TabClass(d)); - TabClass(d) = NULL; - } - } + TabClass.Clear(); } diff --git a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.hxx b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.hxx index 3294275440..47e637d5d1 100644 --- a/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.hxx +++ b/src/ModelingAlgorithms/TKBO/IntTools/IntTools_FClass2d.hxx @@ -22,10 +22,12 @@ #include #include -#include +#include +#include #include #include #include + #include class gp_Pnt2d; @@ -72,19 +74,19 @@ public: Standard_EXPORT Standard_Boolean IsHole() const; private: - BRepTopAdaptor_SeqOfPtr TabClass; - TColStd_SequenceOfInteger TabOrien; - Standard_Real Toluv; - TopoDS_Face Face; - Standard_Real U1; - Standard_Real V1; - Standard_Real U2; - Standard_Real V2; - Standard_Real Umin; - Standard_Real Umax; - Standard_Real Vmin; - Standard_Real Vmax; - Standard_Boolean myIsHole; + NCollection_Sequence TabClass; + TColStd_SequenceOfInteger TabOrien; + Standard_Real Toluv; + TopoDS_Face Face; + Standard_Real U1; + Standard_Real V1; + Standard_Real U2; + Standard_Real V2; + Standard_Real Umin; + Standard_Real Umax; + Standard_Real Vmin; + Standard_Real Vmax; + Standard_Boolean myIsHole; mutable std::unique_ptr myFExplorer; }; diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.cxx index 209dbef273..be6d828698 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.cxx @@ -265,7 +265,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace, //// modified by jgv, 28.04.2009 //// PClass.Init(gp_Pnt2d(0., 0.)); ///////////////////////////////////// - TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); anIsBadWire = true; TabOrien.Append(-1); } @@ -406,7 +406,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace, FlecheU = Toluv; if (FlecheV < Toluv) FlecheV = Toluv; - TabClass.Append((void*)new CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(PClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); } // if(nbpoints>3 else { @@ -415,8 +415,7 @@ BRepTopAdaptor_FClass2d::BRepTopAdaptor_FClass2d(const TopoDS_Face& aFace, TColgp_Array1OfPnt2d xPClass(1, 2); xPClass(1) = SeqPnt2d(1); xPClass(2) = SeqPnt2d(2); - TabClass.Append( - (void*)new CSLib_Class2d(xPClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); + TabClass.Append(CSLib_Class2d(xPClass, FlecheU, FlecheV, Umin, Vmin, Umax, Vmax)); } } // else if(WareIsNotEmpty } // for(FaceExplorer @@ -532,7 +531,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::Perform(const gp_Pnt2d& _Puv, { for (Standard_Integer n = 1; n <= nbtabclass; n++) { - Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans(Puv); + Standard_Integer cur = TabClass(n).SiDans(Puv); if (cur == 1) { if (TabOrien(n) == 0) @@ -673,7 +672,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::TestOnRestriction( { for (Standard_Integer n = 1; n <= nbtabclass; n++) { - Standard_Integer cur = ((CSLib_Class2d*)TabClass(n))->SiDans_OnMode(Puv, Tol); + Standard_Integer cur = TabClass(n).SiDans_OnMode(Puv, Tol); if (cur == 1) { if (TabOrien(n) == 0) @@ -748,15 +747,7 @@ TopAbs_State BRepTopAdaptor_FClass2d::TestOnRestriction( void BRepTopAdaptor_FClass2d::Destroy() { - Standard_Integer nbtabclass = TabClass.Length(); - for (Standard_Integer d = 1; d <= nbtabclass; d++) - { - if (TabClass(d)) - { - delete ((CSLib_Class2d*)TabClass(d)); - TabClass(d) = NULL; - } - } + TabClass.Clear(); } #include diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.hxx b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.hxx index c652ebb3c7..b8f97149b5 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.hxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_FClass2d.hxx @@ -20,10 +20,12 @@ #include #include -#include +#include +#include #include #include #include + class gp_Pnt2d; class BRepTopAdaptor_FClass2d @@ -57,20 +59,19 @@ public: const Standard_Real Tol, const Standard_Boolean RecadreOnPeriodic = Standard_True) const; -protected: private: - BRepTopAdaptor_SeqOfPtr TabClass; - TColStd_SequenceOfInteger TabOrien; - Standard_Real Toluv; - TopoDS_Face Face; - Standard_Real U1; - Standard_Real V1; - Standard_Real U2; - Standard_Real V2; - Standard_Real Umin; - Standard_Real Umax; - Standard_Real Vmin; - Standard_Real Vmax; + NCollection_Sequence TabClass; + TColStd_SequenceOfInteger TabOrien; + Standard_Real Toluv; + TopoDS_Face Face; + Standard_Real U1; + Standard_Real V1; + Standard_Real U2; + Standard_Real V2; + Standard_Real Umin; + Standard_Real Umax; + Standard_Real Vmin; + Standard_Real Vmax; }; #endif // _BRepTopAdaptor_FClass2d_HeaderFile diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_SeqOfPtr.hxx b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_SeqOfPtr.hxx deleted file mode 100644 index 24b2d043dc..0000000000 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/BRepTopAdaptor_SeqOfPtr.hxx +++ /dev/null @@ -1,24 +0,0 @@ -// Created on: 1994-04-01 -// Created by: Modelistation -// Copyright (c) 1994-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. - -#ifndef _BRepTopAdaptor_SeqOfPtr_HeaderFile -#define _BRepTopAdaptor_SeqOfPtr_HeaderFile - -#include - -typedef TColStd_SequenceOfAddress BRepTopAdaptor_SeqOfPtr; - -#endif // _BRepTopAdaptor_SeqOfPtr_HeaderFile diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/FILES.cmake b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/FILES.cmake index a017127a25..8d58b90c22 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/FILES.cmake +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepTopAdaptor/FILES.cmake @@ -9,7 +9,6 @@ set(OCCT_BRepTopAdaptor_FILES BRepTopAdaptor_HVertex.hxx BRepTopAdaptor_HVertex.lxx BRepTopAdaptor_MapOfShapeTool.hxx - BRepTopAdaptor_SeqOfPtr.hxx BRepTopAdaptor_Tool.cxx BRepTopAdaptor_Tool.hxx BRepTopAdaptor_TopolTool.cxx