From 6928e35131cb6f258abcc145d95211f65dd4109e Mon Sep 17 00:00:00 2001 From: abv Date: Mon, 21 Sep 2015 16:38:01 +0300 Subject: [PATCH] 0025571: Avoid base Classes without virtual Destructors Destructors of collection classes from NCollection and math_Function are made virtual to allow safe destruction by pointer to base class. Destructors of classes HatchGen_IntersectionPoint, IntCurveSurface_Intersection, Intf_Interference, IntRes2d_Intersection are made protected to avoid possibility of destructing by pointer to corresponding base class. --- src/HatchGen/HatchGen_IntersectionPoint.cxx | 10 -------- src/HatchGen/HatchGen_IntersectionPoint.hxx | 23 ++++-------------- .../IntCurveSurface_Intersection.hxx | 7 +++--- src/IntRes2d/IntRes2d_Intersection.hxx | 3 +++ src/Intf/Intf_Interference.hxx | 5 +++- src/NCollection/NCollection_BaseList.hxx | 5 ++++ src/NCollection/NCollection_BaseMap.hxx | 3 +++ src/NCollection/NCollection_BaseSequence.hxx | 3 +++ src/NCollection/NCollection_BaseVector.hxx | 3 +++ src/NCollection/NCollection_DataMap.hxx | 2 +- .../NCollection_IndexedDataMap.hxx | 2 +- src/NCollection/NCollection_IndexedMap.hxx | 2 +- src/NCollection/NCollection_List.hxx | 2 +- src/NCollection/NCollection_Map.hxx | 2 +- src/NCollection/NCollection_Sequence.hxx | 2 +- src/NCollection/NCollection_Vector.hxx | 2 +- src/math/math_Function.hxx | 24 ++----------------- 17 files changed, 37 insertions(+), 63 deletions(-) diff --git a/src/HatchGen/HatchGen_IntersectionPoint.cxx b/src/HatchGen/HatchGen_IntersectionPoint.cxx index 17e7884050..b3305938e8 100644 --- a/src/HatchGen/HatchGen_IntersectionPoint.cxx +++ b/src/HatchGen/HatchGen_IntersectionPoint.cxx @@ -32,16 +32,6 @@ HatchGen_IntersectionPoint::HatchGen_IntersectionPoint () : { } -//======================================================================= -// Function : ~HatchGen_IntersectionPoint -// Purpose : Destructor -//======================================================================= - -HatchGen_IntersectionPoint::~HatchGen_IntersectionPoint() -{ -} - - //======================================================================= // Function : SetIndex // Purpose : Sets the index of the supporting curve. diff --git a/src/HatchGen/HatchGen_IntersectionPoint.hxx b/src/HatchGen/HatchGen_IntersectionPoint.hxx index 6a6edcd0fa..7c961d23a6 100644 --- a/src/HatchGen/HatchGen_IntersectionPoint.hxx +++ b/src/HatchGen/HatchGen_IntersectionPoint.hxx @@ -80,17 +80,16 @@ public: //! Dump of the point on element. Standard_EXPORT virtual void Dump (const Standard_Integer Index = 0) const = 0; - Standard_EXPORT virtual ~HatchGen_IntersectionPoint(); - - - protected: - //! Creates an empty intersection point. Standard_EXPORT HatchGen_IntersectionPoint(); + //! Destructor is protected for safer inheritance + ~HatchGen_IntersectionPoint() {} + +protected: Standard_Integer myIndex; Standard_Real myParam; @@ -99,20 +98,6 @@ protected: TopAbs_State myAfter; Standard_Boolean mySegBeg; Standard_Boolean mySegEnd; - - -private: - - - - - }; - - - - - - #endif // _HatchGen_IntersectionPoint_HeaderFile diff --git a/src/IntCurveSurface/IntCurveSurface_Intersection.hxx b/src/IntCurveSurface/IntCurveSurface_Intersection.hxx index 109fcaf21e..a81d4cbaeb 100644 --- a/src/IntCurveSurface/IntCurveSurface_Intersection.hxx +++ b/src/IntCurveSurface/IntCurveSurface_Intersection.hxx @@ -68,15 +68,14 @@ public: //! Dump all the fields. Standard_EXPORT void Dump() const; - - - protected: - //! Empty Constructor; Standard_EXPORT IntCurveSurface_Intersection(); + //! Destructor is protected, for safe inheritance + ~IntCurveSurface_Intersection() {} + //! Internal method //! copy the fields to Standard_EXPORT void SetValues (const IntCurveSurface_Intersection& Inter); diff --git a/src/IntRes2d/IntRes2d_Intersection.hxx b/src/IntRes2d/IntRes2d_Intersection.hxx index 441006294b..ab39e3bf52 100644 --- a/src/IntRes2d/IntRes2d_Intersection.hxx +++ b/src/IntRes2d/IntRes2d_Intersection.hxx @@ -86,6 +86,9 @@ protected: IntRes2d_Intersection(); IntRes2d_Intersection(const IntRes2d_Intersection& Other); + + //! Destructor is protected, for safe inheritance + ~IntRes2d_Intersection () {} Standard_EXPORT void SetValues (const IntRes2d_Intersection& Inter); diff --git a/src/Intf/Intf_Interference.hxx b/src/Intf/Intf_Interference.hxx index 429ef7c479..5231de61d0 100644 --- a/src/Intf/Intf_Interference.hxx +++ b/src/Intf/Intf_Interference.hxx @@ -90,9 +90,12 @@ public: protected: - + //! Empty constructor Standard_EXPORT Intf_Interference(const Standard_Boolean Self); + //! Destructor is protected, for safer inheritance + ~Intf_Interference () {} + //! Only one argument for the intersection. Standard_EXPORT void SelfInterference (const Standard_Boolean Self); diff --git a/src/NCollection/NCollection_BaseList.hxx b/src/NCollection/NCollection_BaseList.hxx index d1c698b1a1..e98a2c3352 100644 --- a/src/NCollection/NCollection_BaseList.hxx +++ b/src/NCollection/NCollection_BaseList.hxx @@ -119,6 +119,11 @@ public: const Handle(NCollection_BaseAllocator)& Allocator() const { return myAllocator; } + // ******** Destructor + // Purpose: defines virtual interface + virtual ~NCollection_BaseList (void) + {} + protected: // --------- PROTECTED METHODS ---------- diff --git a/src/NCollection/NCollection_BaseMap.hxx b/src/NCollection/NCollection_BaseMap.hxx index 94740f3a04..a84362bd74 100644 --- a/src/NCollection/NCollection_BaseMap.hxx +++ b/src/NCollection/NCollection_BaseMap.hxx @@ -166,6 +166,9 @@ public: myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator); } + //! Destructor + virtual ~NCollection_BaseMap() {} + //! BeginResize Standard_EXPORT Standard_Boolean BeginResize (const Standard_Integer NbBuckets, diff --git a/src/NCollection/NCollection_BaseSequence.hxx b/src/NCollection/NCollection_BaseSequence.hxx index d2a2bbc229..c4a5bc794e 100644 --- a/src/NCollection/NCollection_BaseSequence.hxx +++ b/src/NCollection/NCollection_BaseSequence.hxx @@ -115,6 +115,9 @@ public: myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator); } + //! Destructor + virtual ~NCollection_BaseSequence() {} + Standard_EXPORT void ClearSeq (NCollection_DelSeqNode fDel); Standard_EXPORT void PAppend (NCollection_SeqNode *); Standard_EXPORT void PAppend (NCollection_BaseSequence& S); diff --git a/src/NCollection/NCollection_BaseVector.hxx b/src/NCollection/NCollection_BaseVector.hxx index 7e8be304c8..9b32c0c59b 100755 --- a/src/NCollection/NCollection_BaseVector.hxx +++ b/src/NCollection/NCollection_BaseVector.hxx @@ -184,6 +184,9 @@ protected: //! @name protected methods myData = allocMemBlocks (myCapacity); } + //! Destructor + virtual ~NCollection_BaseVector() {} + //! @return pointer to memory where to put the new item Standard_EXPORT void* expandV (const Standard_Integer theIndex); diff --git a/src/NCollection/NCollection_DataMap.hxx b/src/NCollection/NCollection_DataMap.hxx index b223e3b048..8756f5b2c2 100644 --- a/src/NCollection/NCollection_DataMap.hxx +++ b/src/NCollection/NCollection_DataMap.hxx @@ -359,7 +359,7 @@ class NCollection_DataMap : public NCollection_BaseMap } //! Destructor - ~NCollection_DataMap (void) + virtual ~NCollection_DataMap (void) { Clear(); } //! Size diff --git a/src/NCollection/NCollection_IndexedDataMap.hxx b/src/NCollection/NCollection_IndexedDataMap.hxx index 05d4e32cb4..09b60ad6fd 100644 --- a/src/NCollection/NCollection_IndexedDataMap.hxx +++ b/src/NCollection/NCollection_IndexedDataMap.hxx @@ -593,7 +593,7 @@ class NCollection_IndexedDataMap : public NCollection_BaseMap } //! Destructor - ~NCollection_IndexedDataMap (void) + virtual ~NCollection_IndexedDataMap (void) { Clear(); } //! Size diff --git a/src/NCollection/NCollection_IndexedMap.hxx b/src/NCollection/NCollection_IndexedMap.hxx index 29628b90aa..f7ac9ee9e5 100644 --- a/src/NCollection/NCollection_IndexedMap.hxx +++ b/src/NCollection/NCollection_IndexedMap.hxx @@ -454,7 +454,7 @@ class NCollection_IndexedMap : public NCollection_BaseMap } //! Destructor - ~NCollection_IndexedMap (void) + virtual ~NCollection_IndexedMap (void) { Clear(); } //! Size diff --git a/src/NCollection/NCollection_List.hxx b/src/NCollection/NCollection_List.hxx index b525603371..39a4280d09 100644 --- a/src/NCollection/NCollection_List.hxx +++ b/src/NCollection/NCollection_List.hxx @@ -271,7 +271,7 @@ public: { PReverse(); } //! Destructor - clears the List - ~NCollection_List (void) + virtual ~NCollection_List (void) { Clear(); } private: diff --git a/src/NCollection/NCollection_Map.hxx b/src/NCollection/NCollection_Map.hxx index 6424858fe2..16dde63fcc 100644 --- a/src/NCollection/NCollection_Map.hxx +++ b/src/NCollection/NCollection_Map.hxx @@ -290,7 +290,7 @@ class NCollection_Map : public NCollection_BaseMap } //! Destructor - ~NCollection_Map (void) + virtual ~NCollection_Map (void) { Clear(); } //! Size diff --git a/src/NCollection/NCollection_Sequence.hxx b/src/NCollection/NCollection_Sequence.hxx index f9f8fed281..f50896cf02 100644 --- a/src/NCollection/NCollection_Sequence.hxx +++ b/src/NCollection/NCollection_Sequence.hxx @@ -325,7 +325,7 @@ public: { ChangeValue (theIndex) = theItem; } // ******** Destructor - clears the Sequence - ~NCollection_Sequence (void) + virtual ~NCollection_Sequence (void) { Clear(); } private: diff --git a/src/NCollection/NCollection_Vector.hxx b/src/NCollection/NCollection_Vector.hxx index fb56faeda4..e7b89df5c2 100755 --- a/src/NCollection/NCollection_Vector.hxx +++ b/src/NCollection/NCollection_Vector.hxx @@ -165,7 +165,7 @@ public: //! @name public methods } //! Destructor - ~NCollection_Vector() + virtual ~NCollection_Vector() { for (Standard_Integer anItemIter = 0; anItemIter < myCapacity; ++anItemIter) { diff --git a/src/math/math_Function.hxx b/src/math/math_Function.hxx index 628fbb201c..81064a2d06 100644 --- a/src/math/math_Function.hxx +++ b/src/math/math_Function.hxx @@ -34,6 +34,8 @@ public: DEFINE_STANDARD_ALLOC + //! Virtual destructor, for safe inheritance + virtual ~math_Function () {} //! Computes the value of the function for a given value of //! variable . @@ -56,28 +58,6 @@ public: //! to save the current state of the function and to return //! an Integer that allows retrieval of the state. Standard_EXPORT virtual Standard_Integer GetStateNumber(); - - - - -protected: - - - - - -private: - - - - - }; - - - - - - #endif // _math_Function_HeaderFile