0025077: [OOP] Explicit initialization of copy constructor
[occt.git] / src / BOPDS / BOPDS_PassKey.lxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 3// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 9// This library is free software; you can redistribute it and/or modify it under
10// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 11// by the Free Software Foundation, with special exception defined in the file
12// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13// distribution for complete text of the license and disclaimer of any warranty.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
18static
19 inline Standard_Integer NormalizedId(const Standard_Integer aId,
20 const Standard_Integer aDiv);
21static
22 inline void SortShell(const Standard_Integer n,
23 Standard_Integer* a);
24
25//=======================================================================
26//function :
27//purpose :
28//=======================================================================
29 inline BOPDS_PassKey::BOPDS_PassKey()
30{
31 myAllocator=NCollection_BaseAllocator::CommonBaseAllocator();
32 myPtr=NULL;
33 Clear();
34}
35//=======================================================================
36//function :
37//purpose :
38//=======================================================================
39 inline BOPDS_PassKey::BOPDS_PassKey(const Handle(NCollection_BaseAllocator)& theAllocator)
40{
41 myAllocator=theAllocator;
42 myPtr=NULL;
43 Clear();
44}
45//=======================================================================
46//function :
47//purpose :
48//=======================================================================
a9b30f0a 49 inline BOPDS_PassKey::BOPDS_PassKey(const BOPDS_PassKey& theOther)
50:
51 myPtr(0)
4e57c75e 52{
a9b30f0a 53 (*this) = theOther;
4e57c75e 54}
55//=======================================================================
56//function :operator =
57//purpose :
58//=======================================================================
59 inline BOPDS_PassKey& BOPDS_PassKey::operator =(const BOPDS_PassKey& aOther)
60{
4e57c75e 61 Clear();
62 //
63 myAllocator=aOther.myAllocator;
64 myNbIds=aOther.myNbIds;
65 mySum=aOther.mySum;
66 //
67 if (myNbIds) {
68 myPtr=Allocate(myNbIds);
a9b30f0a 69 for (int i=0; i<myNbIds; ++i) {
4e57c75e 70 myPtr[i]=aOther.myPtr[i];
71 }
72 }
73 //
74 return *this;
75}
76//=======================================================================
77//function :~
78//purpose :
79//=======================================================================
80 inline BOPDS_PassKey::~BOPDS_PassKey()
81{
82 Clear();
83}
84//=======================================================================
85//function :Allocate
86//purpose :
87//=======================================================================
88 inline BOPCol_PInteger BOPDS_PassKey::Allocate(const Standard_Integer theSize)
89{
90 BOPCol_PInteger pPtr;
91 //
92 pPtr=(BOPCol_PInteger)myAllocator->Allocate(theSize*sizeof(Standard_Integer));
93 return pPtr;
94}
95
96//=======================================================================
97//function :Clear
98//purpose :
99//=======================================================================
100 inline void BOPDS_PassKey::Clear()
101{
102 myNbIds=0;
103 mySum=0;
104 if (myPtr) {
547702a1 105 myAllocator->Free(myPtr);
4e57c75e 106 myPtr=NULL;
107 }
108}
109//=======================================================================
110//function :SetIds
111//purpose :
112//=======================================================================
113 inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1)
114{
115 Clear();
116 myNbIds=1;
117 myPtr=Allocate(myNbIds);
118 myPtr[0]=aId1;
119 mySum=NormalizedId(aId1, myNbIds);
120}
121
122//=======================================================================
123//function :SetIds
124//purpose :
125//=======================================================================
126 inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
127 const Standard_Integer aId2)
128{
129 Clear();
130 //
131 myNbIds=2;
132 myPtr=Allocate(myNbIds);
133 //
134 if (aId1<aId2) {
135 myPtr[0]=aId1;
136 myPtr[1]=aId2;
137 }
138 else {
139 myPtr[0]=aId2;
140 myPtr[1]=aId1;
141 }
142 //
143 mySum=NormalizedId(aId1, myNbIds);
144 mySum=mySum+NormalizedId(aId2, myNbIds);
145}
146//=======================================================================
147//function :SetIds
148//purpose :
149//=======================================================================
150 inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
151 const Standard_Integer aId2,
152 const Standard_Integer aId3)
153{
154 Clear();
155 //
156 myNbIds=3;
157 myPtr=Allocate(myNbIds);
158 //
159 myPtr[0]=aId1;
160 myPtr[1]=aId2;
161 myPtr[2]=aId3;
162 //
163 SortShell(myNbIds, myPtr);
164 //
165 mySum=NormalizedId(aId1, myNbIds);
166 mySum=mySum+NormalizedId(aId2, myNbIds);
167 mySum=mySum+NormalizedId(aId3, myNbIds);
168}
169//=======================================================================
170//function :SetIds
171//purpose :
172//=======================================================================
173 inline void BOPDS_PassKey::SetIds(const Standard_Integer aId1,
174 const Standard_Integer aId2,
175 const Standard_Integer aId3,
176 const Standard_Integer aId4)
177{
178 Clear();
179 //
180 myNbIds=4;
181 myPtr=Allocate(myNbIds);
182 //
183 myPtr[0]=aId1;
184 myPtr[1]=aId2;
185 myPtr[2]=aId3;
186 myPtr[3]=aId4;
187 //
188 SortShell(myNbIds, myPtr);
189 //
190 mySum=NormalizedId(aId1, myNbIds);
191 mySum=mySum+NormalizedId(aId2, myNbIds);
192 mySum=mySum+NormalizedId(aId3, myNbIds);
193 mySum=mySum+NormalizedId(aId4, myNbIds);
194}
195//=======================================================================
196//function :SetIds
197//purpose :
198//=======================================================================
199 inline void BOPDS_PassKey::SetIds(const BOPCol_ListOfInteger& aLI)
200{
201 Standard_Integer i, aId, aSum;
202 BOPCol_ListIteratorOfListOfInteger aIt;
203 //
204 Clear();
205 //
206 myNbIds=aLI.Extent();
207 myPtr=Allocate(myNbIds);
208 //
209 aSum=0;
210 aIt.Initialize(aLI);
211 for (i=0; aIt.More(); aIt.Next(), ++i) {
212 aId=aIt.Value();
213 myPtr[i]=aId;
214 aSum+=NormalizedId(aId, myNbIds);
215 }
216 mySum=aSum;
217 //
218 SortShell(myNbIds, myPtr);
219}
220//=======================================================================
221//function :NbIds
222//purpose :
223//=======================================================================
224 inline Standard_Integer BOPDS_PassKey::NbIds()const
225{
226 return myNbIds;
227}
228//=======================================================================
229//function :Id
230//purpose :
231//=======================================================================
232 inline Standard_Integer BOPDS_PassKey::Id(const Standard_Integer aIndex) const
233{
234 if (aIndex<0 || aIndex>myNbIds-1) {
235 return -1;
236 }
237 return myPtr[aIndex];
238}
239//=======================================================================
240//function :Ids
241//purpose :
242//=======================================================================
243 inline void BOPDS_PassKey::Ids(Standard_Integer& aId1,
244 Standard_Integer& aId2) const
245{
246 aId1=0;
247 aId2=0;
248 if (myNbIds>1) {
249 aId1=myPtr[0];
250 aId2=myPtr[1];
251 }
252}
253//=======================================================================
254//function :IsEqual
255//purpose :
256//=======================================================================
257 inline Standard_Boolean BOPDS_PassKey::IsEqual(const BOPDS_PassKey& aOther) const
258{
259 Standard_Boolean bRet;
260 Standard_Integer i;
261 //
262 bRet=Standard_False;
263 //
264 if (myNbIds!=aOther.myNbIds) {
265 return bRet;
266 }
267 for (i=0; i<myNbIds; ++i) {
268 if (myPtr[i]!=aOther.myPtr[i]) {
269 return bRet;
270 }
271 }
272 return !bRet;
273}
274//=======================================================================
275//function : HashCode
276//purpose :
277//=======================================================================
278 inline Standard_Integer BOPDS_PassKey::HashCode(const Standard_Integer aUpper) const
279{
280 return ::HashCode(mySum, aUpper);
281}
282//=======================================================================
283// function: NormalizedId
284// purpose :
285//=======================================================================
286inline Standard_Integer NormalizedId(const Standard_Integer aId,
287 const Standard_Integer aDiv)
288{
289 Standard_Integer aMax, aTresh, aIdRet;
290 //
291 aIdRet=aId;
292 aMax=::IntegerLast();
293 aTresh=aMax/aDiv;
294 if (aId>aTresh) {
295 aIdRet=aId%aTresh;
296 }
297 return aIdRet;
298}
299//=======================================================================
300// function: SortShell
301// purpose :
302//=======================================================================
303inline void SortShell(const Standard_Integer n,
304 Standard_Integer* a)
305{
306 Standard_Integer nd, i, j, l, d=1;
307 Standard_Integer x;
308 //
309 while(d<=n) {
310 d*=2;
311 }
312 //
313 while (d) {
314 d=(d-1)/2;
315 //
316 nd=n-d;
317 for (i=0; i<nd; ++i) {
318 j=i;
319 m30:;
320 l=j+d;
321 if (a[l] < a[j]) {
322 x=a[j];
323 a[j]=a[l];
324 a[l]=x;
325 j-=d;
326 if (j > -1) {
327 goto m30;
328 }
329 }//if (a[l] < a[j]){
330 }//for (i=0; i<nd; ++i)
331 }//while (1)
332}