Salome HOME
Warn about direct SMESH idl usage: smesh python package have to be used where it...
[modules/smesh.git] / src / SMDS / SMDS_MeshIDFactory.cxx
index db5df4222ce3d2f3fd5661f4ee9b5d621b8e0d6b..989e42be33d85bb5244680f546aefd49547a9d8f 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -28,6 +28,8 @@
 
 #include "SMDS_MeshIDFactory.hxx"
 
+using namespace std;
+
 //=======================================================================
 //function : SMDS_MeshIDFactory
 //purpose  : 
@@ -42,8 +44,9 @@ int SMDS_MeshIDFactory::GetFreeID()
        if (myPoolOfID.empty()) return ++myMaxID;
        else
        {
-               int ID = myPoolOfID.top();
-               myPoolOfID.pop();
+                set<int>::iterator i = myPoolOfID.begin();
+               int ID = *i;//myPoolOfID.top();
+               myPoolOfID.erase( i );//myPoolOfID.pop();
                return ID;
        }
 }
@@ -54,5 +57,27 @@ int SMDS_MeshIDFactory::GetFreeID()
 //=======================================================================
 void SMDS_MeshIDFactory::ReleaseID(const int ID)
 {
-  if (ID > 0 && ID < myMaxID) myPoolOfID.push(ID);
+  if ( ID > 0 )
+  {
+    if ( ID < myMaxID )
+    {
+      myPoolOfID.insert(ID);
+    }
+    else if ( ID == myMaxID )
+    {
+      --myMaxID;
+      if ( !myPoolOfID.empty() ) // assure that myMaxID is not in myPoolOfID
+      {
+        set<int>::iterator i = --myPoolOfID.end();
+        while ( i != myPoolOfID.begin() && myMaxID == *i ) {
+          --myMaxID; --i;
+        }
+        if ( myMaxID == *i )
+          --myMaxID; // begin of myPoolOfID reached
+        else
+          ++i;
+        myPoolOfID.erase( i, myPoolOfID.end() );
+      }
+    }
+  }
 }