1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-07 18:30:55 +03:00

0025616: Avoid Classes using "new" to allocate Instances but not defining a copy Constructor

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.
This commit is contained in:
azn 2015-01-15 14:41:27 +03:00 committed by bugmaster
parent c8be748cd4
commit 6a38ff486c
8 changed files with 96 additions and 57 deletions

View 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, 1048576,2097152,4194304,8388608,
16777216,33554432,67108864,134217728, 16777216,33554432,67108864,134217728,
268435456,536870912,1073741824,2147483648U}; 268435456,536870912,1073741824,2147483648U};
class BSB_T3Bits { //-- size is power of 2 > 4
//-- size is power of 2 > 4
class BSB_T3Bits
{
public: public:
Standard_Integer _DECAL; Standard_Integer _DECAL;
@ -163,25 +166,35 @@ public:
inline Standard_Integer GrilleInteger(Standard_Integer ix, inline Standard_Integer GrilleInteger(Standard_Integer ix,
Standard_Integer iy, Standard_Integer iy,
Standard_Integer iz) { Standard_Integer iz)
{
Standard_Integer tz = iz<<_DECAL2; Standard_Integer tz = iz<<_DECAL2;
Standard_Integer ty = iy<<_DECAL; Standard_Integer ty = iy<<_DECAL;
Standard_Integer t = ix; Standard_Integer t = ix;
t|=ty; t|=tz; t|=ty;
t|=tz;
return(t); return(t);
} }
inline void IntegerGrille(Standard_Integer t, inline void IntegerGrille(Standard_Integer t,
Standard_Integer &ix, Standard_Integer &ix,
Standard_Integer &iy, Standard_Integer &iy,
Standard_Integer &iz) { Standard_Integer &iz)
{
ix = t & _BASEM1; t>>=_DECAL; ix = t & _BASEM1; t>>=_DECAL;
iy = t & _BASEM1; t>>=_DECAL; iy = t & _BASEM1; t>>=_DECAL;
iz = t; 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(p) { delete [] p; p=0; }
#if DEBUG #if DEBUG
printf("\n BASE:%d\n",_BASE); printf("\n BASE:%d\n",_BASE);

View File

@ -2998,7 +2998,14 @@ public:
const Standard_Integer j) { const Standard_Integer j) {
return myP2[Index(i,j)]; return myP2[Index(i,j)];
}; };
protected:
private:
IntPatch_InfoPD (const IntPatch_InfoPD&);
IntPatch_InfoPD& operator=(const IntPatch_InfoPD&);
private:
Standard_Integer myNBI; Standard_Integer myNBI;
char *myP1DS2; char *myP1DS2;
char *myP2DS1; char *myP2DS1;

View File

@ -14,34 +14,23 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <LDOM_OSStream.hxx> #include <LDOM_OSStream.hxx>
#include <NCollection_DefineAlloc.hxx>
#include <NCollection_IncAllocator.hxx> #include <NCollection_IncAllocator.hxx>
#include <string.h> #include <string.h>
#include <Standard.hxx> #include <Standard.hxx>
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
// One element of sequence //=======================================================================
/* Can only be allocated by the allocator and assumes it is IncAllocator, so //function : LDOM_StringElem()
no destructor is required. //purpose : Constructor
*/ //=======================================================================
class LDOM_StringElem LDOM_SBuffer::LDOM_StringElem::LDOM_StringElem
{ ( const int theLength, const Handle_NCollection_BaseAllocator& theAlloc )
char* buf; // pointer on data string : buf (reinterpret_cast<char*>(theAlloc->Allocate (theLength))),
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), len (0),
next(0) next(0)
{ {
} }
friend class LDOM_SBuffer;
};
//======================================================================= //=======================================================================
//function : LDOM_SBuffer() //function : LDOM_SBuffer()
//purpose : //purpose :

View File

@ -32,6 +32,7 @@
// and current element of sequence, // and current element of sequence,
// also it has methods for the sequence management. // also it has methods for the sequence management.
#include <NCollection_DefineAlloc.hxx>
#include <NCollection_BaseAllocator.hxx> #include <NCollection_BaseAllocator.hxx>
#include <Standard_OStream.hxx> #include <Standard_OStream.hxx>
#include <Standard_Boolean.hxx> #include <Standard_Boolean.hxx>
@ -39,10 +40,27 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> /* EOF */ #include <stdio.h> /* EOF */
class LDOM_StringElem; // defined in cxx file
class LDOM_SBuffer : public streambuf class LDOM_SBuffer : public streambuf
{ {
// 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: public:
Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf); Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
// Constructor. Sets a default value for the // Constructor. Sets a default value for the

View File

@ -264,6 +264,10 @@ public:
return Standard_Real (myBinom[N][P]); return Standard_Real (myBinom[N][P]);
} }
private:
BinomAllocator (const BinomAllocator&);
BinomAllocator& operator= (const BinomAllocator&);
private: private:
Standard_Integer** myBinom; Standard_Integer** myBinom;
Standard_Integer myMaxBinom; Standard_Integer myMaxBinom;

View File

@ -85,9 +85,6 @@ static Standard_Boolean OnSurface_D1(const Standard_Real , // U,
class ProjLib_OnSurface : public AppCont_Function class ProjLib_OnSurface : public AppCont_Function
{ {
Handle(Adaptor3d_HCurve) myCurve;
Extrema_ExtPS *myExtPS;
public: public:
ProjLib_OnSurface(const Handle(Adaptor3d_HCurve) & C, ProjLib_OnSurface(const Handle(Adaptor3d_HCurve) & C,
@ -125,6 +122,14 @@ class ProjLib_OnSurface : public AppCont_Function
gp_Pnt aPnt; gp_Pnt aPnt;
return OnSurface_D1(theT, aPnt, theVec(1), myCurve, myExtPS); 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;
}; };

View File

@ -106,9 +106,10 @@ public:
} }
private: private:
Select3D_PointData (const Select3D_PointData&);
Select3D_PointData& operator= (const Select3D_PointData&);
// Default constructor private:
Select3D_PointData () {}
Select3D_Pnt* mypolyg3d; Select3D_Pnt* mypolyg3d;
Select3D_Pnt2d* mypolyg2d; Select3D_Pnt2d* mypolyg2d;

View File

@ -46,12 +46,18 @@
// used to construct appropriate memory manager according // used to construct appropriate memory manager according
// to environment settings, and to ensure destruction upon exit // to environment settings, and to ensure destruction upon exit
//======================================================================= //=======================================================================
class Standard_MMgrFactory
class Standard_MMgrFactory { {
public: public:
Standard_MMgrFactory(); static Standard_MMgrRoot* GetMMgr();
~Standard_MMgrFactory(); ~Standard_MMgrFactory();
public:
private:
Standard_MMgrFactory();
Standard_MMgrFactory (const Standard_MMgrFactory&);
Standard_MMgrFactory& operator= (const Standard_MMgrFactory&);
private:
Standard_MMgrRoot* myFMMgr; Standard_MMgrRoot* myFMMgr;
}; };
@ -157,11 +163,8 @@ Standard_MMgrFactory::Standard_MMgrFactory()
Standard_MMgrFactory::~Standard_MMgrFactory() Standard_MMgrFactory::~Standard_MMgrFactory()
{ {
if ( myFMMgr ) { if ( myFMMgr )
myFMMgr->Purge(Standard_True); myFMMgr->Purge(Standard_True);
// delete myFMMgr;
// myFMMgr = 0;
}
} }
//======================================================================= //=======================================================================
@ -205,8 +208,7 @@ Standard_MMgrFactory::~Standard_MMgrFactory()
// be counting calls to Allocate() and Free()... // be counting calls to Allocate() and Free()...
// //
//======================================================================= //=======================================================================
Standard_MMgrRoot* Standard_MMgrFactory::GetMMgr()
static Standard_MMgrRoot* GetMMgr()
{ {
static Standard_MMgrFactory aFactory; static Standard_MMgrFactory aFactory;
return aFactory.myFMMgr; return aFactory.myFMMgr;
@ -219,7 +221,7 @@ static Standard_MMgrRoot* GetMMgr()
Standard_Address Standard::Allocate(const Standard_Size size) 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) 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, Standard_Address Standard::Reallocate (Standard_Address theStorage,
const Standard_Size theSize) 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() Standard_Integer Standard::Purge()
{ {
return GetMMgr()->Purge(); return Standard_MMgrFactory::GetMMgr()->Purge();
} }
//======================================================================= //=======================================================================