0025616: Avoid Classes using "new" to allocate Instances but not defining a copy...
authorazn <azn@opencascade.com>
Thu, 15 Jan 2015 11:41:27 +0000 (14:41 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 15 Jan 2015 11:42:36 +0000 (14:42 +0300)
The empty copy constructor, assignemnts operator, default constructors added to the following classes:
The following classes use “new” function without Handles:
- Select3D_PointData
- BSB_T3Bits
- IntPatch_InfoPD
- LDOM_StringElem
- BinomAllocator
- ProjLib_OnSurface
- Standard_MMgrFactory

Useless declaration of default constructor have been deleted.

src/Bnd/Bnd_BoundSortBox.cxx
src/IntPatch/IntPatch_PrmPrmIntersection.cxx
src/LDOM/LDOM_OSStream.cxx
src/LDOM/LDOM_OSStream.hxx
src/PLib/PLib.cxx
src/ProjLib/ProjLib_ProjectOnSurface.cxx
src/Select3D/Select3D_PointData.hxx
src/Standard/Standard.cxx

index 30438dd..9957b1c 100644 (file)
@@ -123,7 +123,10 @@ static long unsigned _P2[32] = { 1,2,4,8,  16,32,64,128,  256,512,1024,2048,
                                 1048576,2097152,4194304,8388608,
                                 16777216,33554432,67108864,134217728,
                                 268435456,536870912,1073741824,2147483648U};
-class BSB_T3Bits { //-- size is power of 2 > 4
+
+//-- size is power of 2 > 4
+class BSB_T3Bits
+{
 public:
 
   Standard_Integer _DECAL;
@@ -162,26 +165,36 @@ public:
   Standard_Integer NbAxisZ(const Standard_Integer i) {   return(axisZ[0][i]);   }
   
   inline Standard_Integer GrilleInteger(Standard_Integer ix,
-                                       Standard_Integer iy,
-                                       Standard_Integer iz) { 
+                                        Standard_Integer iy,
+                                        Standard_Integer iz)
+  {
     Standard_Integer tz = iz<<_DECAL2;
     Standard_Integer ty = iy<<_DECAL;
     Standard_Integer t  = ix;
-    t|=ty; t|=tz;
+    t|=ty;
+    t|=tz;
     return(t);
   }
-  
+
   inline void IntegerGrille(Standard_Integer t,
-                           Standard_Integer &ix,
-                           Standard_Integer &iy,
-                           Standard_Integer &iz) { 
+                            Standard_Integer &ix,
+                            Standard_Integer &iy,
+                            Standard_Integer &iz)
+  {
     ix = t & _BASEM1; t>>=_DECAL;
     iy = t & _BASEM1; t>>=_DECAL;
     iz = t;
   }
+
+private:
+
+  BSB_T3Bits (const BSB_T3Bits&);
+  BSB_T3Bits& operator= (const BSB_T3Bits&);
 };
+
 //=======================================================================
-BSB_T3Bits::~BSB_T3Bits() { 
+BSB_T3Bits::~BSB_T3Bits()
+{
   if(p) { delete [] p; p=0; } 
 #if DEBUG
   printf("\n BASE:%d\n",_BASE);
index 683e2c8..8c67283 100644 (file)
@@ -2998,7 +2998,14 @@ public:
     const Standard_Integer j) { 
       return myP2[Index(i,j)];
   };
-protected:
+
+private:
+
+  IntPatch_InfoPD (const IntPatch_InfoPD&);
+  IntPatch_InfoPD& operator=(const IntPatch_InfoPD&);
+
+private:
+
   Standard_Integer myNBI;
   char *myP1DS2;
   char *myP2DS1;
index 0dee401..c4f6969 100644 (file)
 // commercial license or contractual agreement.
 
 #include <LDOM_OSStream.hxx>
-#include <NCollection_DefineAlloc.hxx>
 #include <NCollection_IncAllocator.hxx>
 #include <string.h>
 #include <Standard.hxx>
 #include <Standard_Integer.hxx>
 
-// One element of sequence
-/* Can only be allocated by the allocator and assumes it is IncAllocator, so 
-   no destructor is required.
-*/
-class LDOM_StringElem
+//=======================================================================
+//function : LDOM_StringElem()
+//purpose  : Constructor
+//=======================================================================
+LDOM_SBuffer::LDOM_StringElem::LDOM_StringElem
+  ( const int theLength, const Handle_NCollection_BaseAllocator& theAlloc )
+: buf (reinterpret_cast<char*>(theAlloc->Allocate (theLength))),
+  len (0),
+  next(0)
 {
-  char* buf;             // pointer on data string
-  int len;               // quantity of really written data
-  LDOM_StringElem* next; // pointer on the next element of a sequence
-
-  DEFINE_NCOLLECTION_ALLOC
-  
-  LDOM_StringElem (int aLen, const Handle_NCollection_BaseAllocator& theAlloc) :
-    buf (reinterpret_cast<char*> (theAlloc->Allocate (aLen))),
-    len (0),
-    next (0)
-  {
-  }
-
-friend class LDOM_SBuffer;
-};
+}
 
 //=======================================================================
 //function : LDOM_SBuffer()
index ce1b316..2648b92 100644 (file)
@@ -32,6 +32,7 @@
 //          and current element of sequence,
 //          also it has methods for the sequence management.
 
+#include <NCollection_DefineAlloc.hxx>
 #include <NCollection_BaseAllocator.hxx>
 #include <Standard_OStream.hxx>
 #include <Standard_Boolean.hxx>
 #include <stdlib.h>
 #include <stdio.h> /* EOF */
 
-class LDOM_StringElem; // defined in cxx file
-
 class LDOM_SBuffer : public streambuf
 {
- public:
+  // One element of sequence.
+  // Can only be allocated by the allocator and assumes
+  // it is IncAllocator, so destructor isn't required.
+  struct LDOM_StringElem
+  {
+    char*            buf;  //!< pointer on data string
+    int              len;  //!< quantity of really written data
+    LDOM_StringElem* next; //!< pointer on the next element of a sequence
+
+    DEFINE_NCOLLECTION_ALLOC
+
+    LDOM_StringElem(const int, const Handle_NCollection_BaseAllocator&);
+    ~LDOM_StringElem();
+
+  private:
+    LDOM_StringElem (const LDOM_StringElem&);
+    LDOM_StringElem& operator= (const LDOM_StringElem&);
+  };
+
+public:
   Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
   // Constructor. Sets a default value for the
   //              length of each sequence element.
@@ -74,8 +92,8 @@ class LDOM_SBuffer : public streambuf
   Standard_EXPORT ~LDOM_SBuffer ();
   // Destructor
 
- private:
+private:
+
   Standard_Integer      myMaxBuf; // default length of one element
   Standard_Integer      myLength; // full length of contained data
   LDOM_StringElem* myFirstString; // the head of the sequence
index 23fa302..2de1ca6 100644 (file)
@@ -264,6 +264,10 @@ public:
     return Standard_Real (myBinom[N][P]);
   }
 
+private:
+  BinomAllocator (const BinomAllocator&);
+  BinomAllocator& operator= (const BinomAllocator&);
+
 private:
   Standard_Integer**  myBinom;
   Standard_Integer myMaxBinom;
index 5098b3f..c71c2ce 100644 (file)
@@ -85,10 +85,7 @@ static Standard_Boolean OnSurface_D1(const Standard_Real , // U,
 class ProjLib_OnSurface : public AppCont_Function
 
 {
-  Handle(Adaptor3d_HCurve)       myCurve;
-  Extrema_ExtPS *myExtPS;
-
-  public :
+public:
 
   ProjLib_OnSurface(const Handle(Adaptor3d_HCurve)   & C, 
                     const Handle(Adaptor3d_HSurface) & S)
@@ -125,6 +122,14 @@ class ProjLib_OnSurface : public AppCont_Function
     gp_Pnt aPnt;
     return OnSurface_D1(theT, aPnt, theVec(1), myCurve, myExtPS);
   }
+
+private:
+  ProjLib_OnSurface (const ProjLib_OnSurface&);
+  ProjLib_OnSurface& operator= (const ProjLib_OnSurface&);
+
+private:
+  Handle(Adaptor3d_HCurve)       myCurve;
+  Extrema_ExtPS*                 myExtPS;
 };
 
 
index e294b67..1d6b949 100644 (file)
@@ -106,9 +106,10 @@ public:
   }
 
 private:
+  Select3D_PointData (const Select3D_PointData&);
+  Select3D_PointData& operator= (const Select3D_PointData&);
 
-  // Default constructor
-  Select3D_PointData () {}
+private:
 
   Select3D_Pnt*    mypolyg3d;
   Select3D_Pnt2d*  mypolyg2d;
index 4f79abb..8cdd855 100644 (file)
 //           used to construct appropriate memory manager according
 //           to environment settings, and to ensure destruction upon exit
 //=======================================================================
+class Standard_MMgrFactory
+{
+public:
+  static Standard_MMgrRoot* GetMMgr();
+  ~Standard_MMgrFactory();
 
-class Standard_MMgrFactory {
- public:
+private:
   Standard_MMgrFactory();
-  ~Standard_MMgrFactory();
- public:
+  Standard_MMgrFactory (const Standard_MMgrFactory&);
+  Standard_MMgrFactory& operator= (const Standard_MMgrFactory&);
+
+private:
   Standard_MMgrRoot* myFMMgr;
 };
 
@@ -157,11 +163,8 @@ Standard_MMgrFactory::Standard_MMgrFactory()
 
 Standard_MMgrFactory::~Standard_MMgrFactory()
 {
-  if (  myFMMgr ) {
+  if (  myFMMgr )
     myFMMgr->Purge(Standard_True);
-//  delete myFMMgr;
-//  myFMMgr = 0;  
-  }
 }
 
 //=======================================================================
@@ -205,8 +208,7 @@ Standard_MMgrFactory::~Standard_MMgrFactory()
 // be counting calls to Allocate() and Free()...
 //
 //=======================================================================
-
-static Standard_MMgrRoot* GetMMgr()
+Standard_MMgrRoot* Standard_MMgrFactory::GetMMgr()
 {
   static Standard_MMgrFactory aFactory;
   return aFactory.myFMMgr;
@@ -219,7 +221,7 @@ static Standard_MMgrRoot* GetMMgr()
 
 Standard_Address Standard::Allocate(const Standard_Size size)
 {
-  return GetMMgr()->Allocate(size);
+  return Standard_MMgrFactory::GetMMgr()->Allocate(size);
 }
 
 //=======================================================================
@@ -229,7 +231,7 @@ Standard_Address Standard::Allocate(const Standard_Size size)
 
 void Standard::Free (Standard_Address theStorage)
 {
-  GetMMgr()->Free(theStorage);
+  Standard_MMgrFactory::GetMMgr()->Free(theStorage);
 }
 
 //=======================================================================
@@ -240,7 +242,7 @@ void Standard::Free (Standard_Address theStorage)
 Standard_Address Standard::Reallocate (Standard_Address theStorage,
                                       const Standard_Size theSize)
 {
-  return GetMMgr()->Reallocate (theStorage, theSize);
+  return Standard_MMgrFactory::GetMMgr()->Reallocate (theStorage, theSize);
 }
 
 //=======================================================================
@@ -250,7 +252,7 @@ Standard_Address Standard::Reallocate (Standard_Address theStorage,
 
 Standard_Integer Standard::Purge()
 {
-  return GetMMgr()->Purge();
+  return Standard_MMgrFactory::GetMMgr()->Purge();
 }
 
 //=======================================================================