Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/smesh.git] / src / SMDS / SMDS_MeshElementIDFactory.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMDS_MeshElementIDFactory.cxx
25 //  Author : Jean-Michel BOULCOURT
26 //  Module : SMESH
27
28
29 #include "SMDS_MeshElementIDFactory.hxx"
30 #include "SMDS_MeshElement.hxx"
31
32 using namespace std;
33
34 //=======================================================================
35 //function : SMDS_MeshElementIDFactory
36 //purpose  : 
37 //=======================================================================
38 SMDS_MeshElementIDFactory::SMDS_MeshElementIDFactory():SMDS_MeshIDFactory()
39 {
40 }
41
42 //=======================================================================
43 //function : BindID
44 //purpose  : 
45 //=======================================================================
46 bool SMDS_MeshElementIDFactory::BindID(int ID, SMDS_MeshElement * elem)
47 {
48         bool bound=myIDElements.insert(
49                 map<int, SMDS_MeshElement*>::value_type(ID,elem)).second;
50         if(bound) elem->myID=ID;
51         return bound;
52 }
53
54 //=======================================================================
55 //function : MeshElement
56 //purpose  : 
57 //=======================================================================
58 SMDS_MeshElement* SMDS_MeshElementIDFactory::MeshElement(int ID)
59 {
60     map<int, SMDS_MeshElement*>::iterator it=myIDElements.find(ID);
61     if(it==myIDElements.end()) return NULL; else return (*it).second;
62 }
63
64
65 //=======================================================================
66 //function : GetFreeID
67 //purpose  : 
68 //=======================================================================
69 int SMDS_MeshElementIDFactory::GetFreeID()
70 {
71   int ID;
72   do {
73     ID = SMDS_MeshIDFactory::GetFreeID();
74   } while (myIDElements.find(ID) != myIDElements.end());
75   return ID;
76 }
77
78 //=======================================================================
79 //function : ReleaseID
80 //purpose  : 
81 //=======================================================================
82 void SMDS_MeshElementIDFactory::ReleaseID(const int ID)
83 {
84   myIDElements.erase(ID);
85   SMDS_MeshIDFactory::ReleaseID(ID);
86 }
87
88 //=======================================================================
89 //function : GetMaxID
90 //purpose  : 
91 //=======================================================================
92
93 int SMDS_MeshElementIDFactory::GetMaxID() const
94 {
95   map<int, SMDS_MeshElement*>::const_reverse_iterator it = myIDElements.rbegin();
96   if ( it !=  myIDElements.rend() )
97     return (*it).first;
98
99   return 0;
100 }
101
102 //=======================================================================
103 //function : GetMinID
104 //purpose  : 
105 //=======================================================================
106
107 int SMDS_MeshElementIDFactory::GetMinID() const
108 {
109   map<int, SMDS_MeshElement*>::const_iterator it = myIDElements.begin();
110   if ( it !=  myIDElements.end() )
111     return (*it).first;
112
113   return 0;
114 }
115