PAL11544: Improve memory management: implement and use destructors.

This commit is contained in:
jfa 2006-02-16 12:30:40 +00:00
parent 0eff916f1c
commit 5d147e239e
4 changed files with 29 additions and 6 deletions

View File

@ -33,7 +33,7 @@
using namespace std; using namespace std;
//======================================================================= //=======================================================================
//function : //function : Constructor
//purpose : //purpose :
//======================================================================= //=======================================================================
SMESHDS_Command::SMESHDS_Command(const SMESHDS_CommandType aType):myType(aType), SMESHDS_Command::SMESHDS_Command(const SMESHDS_CommandType aType):myType(aType),
@ -41,6 +41,14 @@ myNumber(0)
{ {
} }
//=======================================================================
//function : Destructor
//purpose :
//=======================================================================
SMESHDS_Command::~SMESHDS_Command()
{
}
//======================================================================= //=======================================================================
//function : //function :
//purpose : //purpose :

View File

@ -1182,4 +1182,5 @@ void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
SMESHDS_Mesh::~SMESHDS_Mesh() SMESHDS_Mesh::~SMESHDS_Mesh()
{ {
delete myScript;
} }

View File

@ -30,6 +30,15 @@
using namespace std; using namespace std;
//=======================================================================
//function : Destructor
//purpose :
//=======================================================================
SMESHDS_Script::~SMESHDS_Script()
{
Clear();
}
//======================================================================= //=======================================================================
//function : getCommand //function : getCommand
//purpose : //purpose :
@ -222,7 +231,6 @@ void SMESHDS_Script::ChangePolyhedronNodes (const int ElementID,
//function : Renumber //function : Renumber
//purpose : //purpose :
//======================================================================= //=======================================================================
void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID) void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int deltaID)
{ {
getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID ); getCommand(SMESHDS_Renumber)->Renumber( isNodes, startID, deltaID );
@ -234,7 +242,11 @@ void SMESHDS_Script::Renumber (const bool isNodes, const int startID, const int
//======================================================================= //=======================================================================
void SMESHDS_Script::Clear() void SMESHDS_Script::Clear()
{ {
myCommands.clear(); list<SMESHDS_Command*>::iterator anIt = myCommands.begin();
for (; anIt != myCommands.end(); anIt++) {
delete (*anIt);
}
myCommands.clear();
} }
//======================================================================= //=======================================================================
@ -243,5 +255,5 @@ void SMESHDS_Script::Clear()
//======================================================================= //=======================================================================
const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands() const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
{ {
return myCommands; return myCommands;
} }

View File

@ -36,6 +36,9 @@
class SMESHDS_Script class SMESHDS_Script
{ {
public: public:
SMESHDS_Script() {};
~SMESHDS_Script();
void AddNode(int NewNodeID, double x, double y, double z); void AddNode(int NewNodeID, double x, double y, double z);
void AddEdge(int NewEdgeID, int idnode1, int idnode2); void AddEdge(int NewEdgeID, int idnode1, int idnode2);
void AddFace(int NewFaceID, int idnode1, int idnode2, int idnode3); void AddFace(int NewFaceID, int idnode1, int idnode2, int idnode3);
@ -66,8 +69,7 @@ class SMESHDS_Script
void Renumber (const bool isNodes, const int startID, const int deltaID); void Renumber (const bool isNodes, const int startID, const int deltaID);
void Clear(); void Clear();
const std::list<SMESHDS_Command*> & GetCommands(); const std::list<SMESHDS_Command*> & GetCommands();
~SMESHDS_Script();
private: private:
SMESHDS_Command* getCommand(const SMESHDS_CommandType aType); SMESHDS_Command* getCommand(const SMESHDS_CommandType aType);