mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-27 09:50:34 +05:00
Improve SMDS: replace std::map with NCollection_DataMap for storage of elements
This commit is contained in:
parent
e9f2fd0ea8
commit
eab9bcb035
@ -25,6 +25,9 @@
|
|||||||
// Author : Jean-Michel BOULCOURT
|
// Author : Jean-Michel BOULCOURT
|
||||||
// Module : SMESH
|
// Module : SMESH
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "SMDS_MeshElementIDFactory.hxx"
|
#include "SMDS_MeshElementIDFactory.hxx"
|
||||||
#include "SMDS_MeshElement.hxx"
|
#include "SMDS_MeshElement.hxx"
|
||||||
@ -35,7 +38,9 @@ using namespace std;
|
|||||||
//function : SMDS_MeshElementIDFactory
|
//function : SMDS_MeshElementIDFactory
|
||||||
//purpose :
|
//purpose :
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory()
|
SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():
|
||||||
|
SMDS_MeshIDFactory(),
|
||||||
|
myMin(0), myMax(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,10 +50,12 @@ SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory()
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
|
bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
|
||||||
{
|
{
|
||||||
bool bound=myIDElements.insert(
|
if (myIDElements.IsBound(ID))
|
||||||
map<int, SMDS_MeshElement*>::value_type(ID,elem)).second;
|
return false;
|
||||||
if(bound) elem->myID=ID;
|
myIDElements.Bind(ID,elem);
|
||||||
return bound;
|
elem->myID=ID;
|
||||||
|
updateMinMax (ID);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
@ -57,8 +64,9 @@ bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
|
SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
|
||||||
{
|
{
|
||||||
map<int, SMDS_MeshElement*>::iterator it=myIDElements.find(ID);
|
if (!myIDElements.IsBound(ID))
|
||||||
if(it==myIDElements.end()) return NULL; else return (*it).second;
|
return NULL;
|
||||||
|
return myIDElements.Find(ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +79,7 @@ int SMDS_MeshElementIDFactory::GetFreeID()
|
|||||||
int ID;
|
int ID;
|
||||||
do {
|
do {
|
||||||
ID = SMDS_MeshIDFactory::GetFreeID();
|
ID = SMDS_MeshIDFactory::GetFreeID();
|
||||||
} while (myIDElements.find(ID) != myIDElements.end());
|
} while (myIDElements.IsBound(ID));
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +89,12 @@ int SMDS_MeshElementIDFactory::GetFreeID()
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
|
void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
|
||||||
{
|
{
|
||||||
myIDElements.erase(ID);
|
myIDElements.UnBind(ID);
|
||||||
SMDS_MeshIDFactory::ReleaseID(ID);
|
SMDS_MeshIDFactory::ReleaseID(ID);
|
||||||
|
if (ID == myMax)
|
||||||
|
myMax = 0;
|
||||||
|
if (ID == myMin)
|
||||||
|
myMin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
@ -92,11 +104,9 @@ void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
|
|||||||
|
|
||||||
int SMDS_MeshElementIDFactory::GetMaxID() const
|
int SMDS_MeshElementIDFactory::GetMaxID() const
|
||||||
{
|
{
|
||||||
map<int, SMDS_MeshElement*>::const_reverse_iterator it = myIDElements.rbegin();
|
if (myMax == 0)
|
||||||
if ( it != myIDElements.rend() )
|
updateMinMax();
|
||||||
return (*it).first;
|
return myMax;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
@ -106,10 +116,54 @@ int SMDS_MeshElementIDFactory::GetMaxID() const
|
|||||||
|
|
||||||
int SMDS_MeshElementIDFactory::GetMinID() const
|
int SMDS_MeshElementIDFactory::GetMinID() const
|
||||||
{
|
{
|
||||||
map<int, SMDS_MeshElement*>::const_iterator it = myIDElements.begin();
|
if (myMin == 0)
|
||||||
if ( it != myIDElements.end() )
|
updateMinMax();
|
||||||
return (*it).first;
|
return myMin;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : updateMinMax
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
void SMDS_MeshElementIDFactory::updateMinMax() const
|
||||||
|
{
|
||||||
|
myMin = IntegerLast();
|
||||||
|
myMax = 0;
|
||||||
|
SMDS_IdElementMap::Iterator it(myIDElements);
|
||||||
|
for (; it.More(); it.Next())
|
||||||
|
updateMinMax (it.Key());
|
||||||
|
if (myMin == IntegerLast())
|
||||||
|
myMin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : elementsIterator
|
||||||
|
//purpose : Return an iterator on elements of the factory
|
||||||
|
//=======================================================================
|
||||||
|
|
||||||
|
class SMDS_Fact_MyElemIterator:public SMDS_ElemIterator
|
||||||
|
{
|
||||||
|
SMDS_IdElementMap::Iterator myIterator;
|
||||||
|
public:
|
||||||
|
SMDS_Fact_MyElemIterator(const SMDS_IdElementMap& s):myIterator(s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool more()
|
||||||
|
{
|
||||||
|
return myIterator.More() != Standard_False;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SMDS_MeshElement* next()
|
||||||
|
{
|
||||||
|
const SMDS_MeshElement* current = myIterator.Value();
|
||||||
|
myIterator.Next();
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SMDS_ElemIteratorPtr SMDS_MeshElementIDFactory::elementsIterator() const
|
||||||
|
{
|
||||||
|
return SMDS_ElemIteratorPtr
|
||||||
|
(new SMDS_Fact_MyElemIterator(myIDElements));
|
||||||
|
}
|
||||||
|
@ -28,12 +28,13 @@
|
|||||||
#define _SMDS_MeshElementIDFactory_HeaderFile
|
#define _SMDS_MeshElementIDFactory_HeaderFile
|
||||||
|
|
||||||
#include "SMDS_MeshIDFactory.hxx"
|
#include "SMDS_MeshIDFactory.hxx"
|
||||||
|
#include "SMDS_ElemIterator.hxx"
|
||||||
|
|
||||||
#include <map>
|
#include <NCollection_DataMap.hxx>
|
||||||
|
|
||||||
class SMDS_MeshElement;
|
class SMDS_MeshElement;
|
||||||
|
|
||||||
typedef std::map<int, SMDS_MeshElement *> SMDS_IdElementMap;
|
typedef NCollection_DataMap<int, SMDS_MeshElement *> SMDS_IdElementMap;
|
||||||
|
|
||||||
class SMDS_MeshElementIDFactory:public SMDS_MeshIDFactory
|
class SMDS_MeshElementIDFactory:public SMDS_MeshIDFactory
|
||||||
{
|
{
|
||||||
@ -45,9 +46,17 @@ class SMDS_MeshElementIDFactory:public SMDS_MeshIDFactory
|
|||||||
virtual void ReleaseID(int ID);
|
virtual void ReleaseID(int ID);
|
||||||
int GetMaxID() const;
|
int GetMaxID() const;
|
||||||
int GetMinID() const;
|
int GetMinID() const;
|
||||||
const SMDS_IdElementMap & GetIdElementMap() const { return myIDElements; }
|
SMDS_ElemIteratorPtr elementsIterator() const;
|
||||||
private:
|
private:
|
||||||
|
void updateMinMax() const;
|
||||||
|
void updateMinMax(int id) const
|
||||||
|
{
|
||||||
|
if (id > myMax) myMax = id;
|
||||||
|
if (id < myMin) myMin = id;
|
||||||
|
}
|
||||||
|
|
||||||
SMDS_IdElementMap myIDElements;
|
SMDS_IdElementMap myIDElements;
|
||||||
|
mutable int myMin, myMax;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user