Salome HOME
New DS implementation
[modules/smesh.git] / src / SMDS / SMDS_MapOfMeshElement.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_MapOfMeshElement.cxx
25 //  Author : Jean-Michel BOULCOURT
26 //  Module : SMESH
27
28 using namespace std;
29 #include "SMDS_MapOfMeshElement.ixx"
30 #include <Standard_NoSuchObject.hxx>
31
32
33 #ifndef _Standard_DomainError_HeaderFile
34 #include <Standard_DomainError.hxx>
35 #endif
36 #ifndef _SMDS_MeshElement_HeaderFile
37 #include "SMDS_MeshElement.hxx"
38 #endif
39 #ifndef _SMDS_MeshElementMapHasher_HeaderFile
40 #include "SMDS_MeshElementMapHasher.hxx"
41 #endif
42 #ifndef _SMDS_StdMapNodeOfExtendedMap_HeaderFile
43 #include "SMDS_StdMapNodeOfExtendedMap.hxx"
44 #endif
45 #ifndef _SMDS_MapIteratorOfExtendedMap_HeaderFile
46 #include "SMDS_MapIteratorOfExtendedMap.hxx"
47 #endif
48  
49
50 #define TheKey Handle_SMDS_MeshElement
51 #define TheKey_hxx <SMDS_MeshElement.hxx>
52 #define Hasher SMDS_MeshElementMapHasher
53 #define Hasher_hxx <SMDS_MeshElementMapHasher.hxx>
54 #define TCollection_StdMapNode SMDS_StdMapNodeOfExtendedMap
55 #define TCollection_StdMapNode_hxx <SMDS_StdMapNodeOfExtendedMap.hxx>
56 #define TCollection_MapIterator SMDS_MapIteratorOfExtendedMap
57 #define TCollection_MapIterator_hxx <SMDS_MapIteratorOfExtendedMap.hxx>
58 #define Handle_TCollection_StdMapNode Handle_SMDS_StdMapNodeOfExtendedMap
59 #define TCollection_StdMapNode_Type_() SMDS_StdMapNodeOfExtendedMap_Type_()
60 #define TCollection_Map SMDS_ExtendedMap
61 #define TCollection_Map_hxx <SMDS_ExtendedMap.hxx>
62
63
64
65 //=======================================================================
66 //function : Find
67 //purpose  : 
68 //=======================================================================
69
70 const Handle(SMDS_MeshElement)& SMDS_MapOfMeshElement::Find(const TheKey& K) const
71 {
72   if (IsEmpty()) {
73     Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::Find");
74   }
75 //  Standard_NoSuchObject_Raise_if(IsEmpty(),"SMDS_MapOfMeshElement::Find");
76   TCollection_StdMapNode** data = (TCollection_StdMapNode**) myData1;
77   TCollection_StdMapNode* p = data[Hasher::HashCode(K,NbBuckets())];
78   while (p) {
79     if (Hasher::IsEqual(p->Key(),K)) {
80       return p->Key();
81       }
82     p = (TCollection_StdMapNode*) p->Next();
83   }
84   Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::Find");
85   return p->Key();
86 }
87
88 //=======================================================================
89 //function : ChangeFind
90 //purpose  : 
91 //=======================================================================
92
93 Handle(SMDS_MeshElement)& SMDS_MapOfMeshElement::ChangeFind(const TheKey& K)
94 {
95   if (IsEmpty()) {
96     Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::ChangeFind");
97   }
98 //Standard_NoSuchObject_Raise_if(IsEmpty(),"SMDS_MapOfMeshElement::ChangeFind");
99   TCollection_StdMapNode** data = (TCollection_StdMapNode**) myData1;
100   TCollection_StdMapNode* p = data[Hasher::HashCode(K,NbBuckets())];
101   while (p) {
102     if (Hasher::IsEqual(p->Key(),K)) {
103       return p->Key();
104       }
105     p = (TCollection_StdMapNode*)  p->Next();
106   }
107   Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::ChangeFind");
108   return p->Key();
109 }
110
111
112 //=======================================================================
113 //function : FindID
114 //purpose  : 
115 //=======================================================================
116
117 const Handle(SMDS_MeshElement)& SMDS_MapOfMeshElement::FindID(const Standard_Integer ID) const
118 {
119   if (IsEmpty()) {
120     Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::FindID");
121   }
122 //  Standard_NoSuchObject_Raise_if(IsEmpty(),"SMDS_MapOfMeshElement::Find");
123   TCollection_StdMapNode** data = (TCollection_StdMapNode**) myData1;
124   TCollection_StdMapNode* p = data[ID % NbBuckets()];
125   while (p) {
126     if (p->Key()->GetID() == ID) {
127       return p->Key();
128       }
129     p = (TCollection_StdMapNode*) p->Next();
130   }
131   Standard_NoSuchObject::Raise("SMDS_MapOfMeshElement::Find");
132   return  p->Key();
133 }
134
135 //=======================================================================
136 //function : ContainsID
137 //purpose  : 
138 //=======================================================================
139
140 Standard_Boolean SMDS_MapOfMeshElement::ContainsID(const Standard_Integer ID) const
141 {
142   if (IsEmpty()) return Standard_False;
143   TCollection_StdMapNode** data = (TCollection_StdMapNode**) myData1;
144   TCollection_StdMapNode* p = data[ID % NbBuckets()];
145   while (p) {
146     if (p->Key()->GetID() == ID) {
147       return Standard_True;
148       }
149     p = (TCollection_StdMapNode*)p->Next();
150   }
151   return Standard_False;
152 }