0028643: Coding rules - eliminate GCC compiler warnings -Wmisleading-indentation
[occt.git] / src / Interface / Interface_CheckIterator.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <Interface_Check.hxx>
16#include <Interface_CheckIterator.hxx>
17#include <Interface_InterfaceModel.hxx>
18#include <Interface_IntVal.hxx>
19#include <Message_Messenger.hxx>
7fd59977 20#include <Standard_NoSuchObject.hxx>
42cf5bc1 21#include <Standard_Transient.hxx>
7fd59977 22#include <TCollection_HAsciiString.hxx>
23
7fd59977 24static const Handle(Interface_Check)& nulcheck ()
25{
26 static Handle(Interface_Check) nulch = new Interface_Check;
27 return nulch;
28}
29
30
31//=======================================================================
32//function : Interface_CheckIterator
33//purpose :
34//=======================================================================
35
36Interface_CheckIterator::Interface_CheckIterator ()
37{
38 Clear();
39}
40
41
42//=======================================================================
43//function : Interface_CheckIterator
44//purpose :
45//=======================================================================
46
47Interface_CheckIterator::Interface_CheckIterator(const Standard_CString name)
48 : thename (name)
49{
50 Clear();
51}
52
53
54//=======================================================================
55//function : SetName
56//purpose :
57//=======================================================================
58
59void Interface_CheckIterator::SetName (const Standard_CString name)
60{
61 thename.Clear();
62 if (name[0] != '\0') thename.AssignCat(name);
63}
64
65
66//=======================================================================
67//function : Name
68//purpose :
69//=======================================================================
70
71Standard_CString Interface_CheckIterator::Name () const
72{
73 return thename.ToCString();
74}
75
76
77//=======================================================================
78//function : SetModel
79//purpose :
80//=======================================================================
81
82void Interface_CheckIterator::SetModel(const Handle(Interface_InterfaceModel)& model)
83{
84 themod = model;
85}
86
87
88//=======================================================================
89//function : Model
90//purpose :
91//=======================================================================
92
93Handle(Interface_InterfaceModel) Interface_CheckIterator::Model() const
94{
95 return themod;
96}
97
98
99//=======================================================================
100//function : Clear
101//purpose :
102//=======================================================================
103
104void Interface_CheckIterator::Clear ()
105{
106 thelist = new Interface_HSequenceOfCheck();
107 thenums = new TColStd_HSequenceOfInteger();
108 thecurr = new Interface_IntVal;
109 thecurr->CValue() = 1;
110}
111
112
113//=======================================================================
114//function : Merge
115//purpose :
116//=======================================================================
117
118void Interface_CheckIterator::Merge (Interface_CheckIterator& other)
119{
120 themod = other.Model();
121 for (other.Start(); other.More(); other.Next())
122 Add (other.Value(),other.Number());
123}
124
125
126//=======================================================================
127//function : Add
128//purpose :
129//=======================================================================
130
131void Interface_CheckIterator::Add(const Handle(Interface_Check)& ach,
132 const Standard_Integer num)
133{
134 // Add <meme num que le dernier> -> cumul des Checks
135 if (ach->NbWarnings() + ach->NbFails() == 0) return;
136 Standard_Integer nm = num;
137 if (num <= 0 && ach->HasEntity()) {
138 if (!themod.IsNull()) {
139 nm = themod->Number (ach->Entity());
140 if (nm <= 0) nm = -1;
141 }
142 else nm = -1;
143 }
144 if (nm >= 0 && nm <= - (thecurr->Value()) ) {
145 Standard_Integer i , numpos = 0 , nb = thelist->Length();
146 for (i = nb; i > 0; i --)
147 if (thenums->Value(i) == nm) { numpos = i; break; }
148 if (numpos > 0 && nm >= 0) {
149 Handle(Interface_Check) lch = thelist->ChangeValue(numpos);
150 lch->GetMessages (ach);
151 }
152 // Cas normal : on ajoute en fin de liste
153 else { thelist->Append(ach); thenums->Append(nm); }
154 }
155 // Pas encore vu passe : inutile de chercher
156 else { thelist->Append(ach); thenums->Append(nm); thecurr->CValue() = -nm; }
157}
158
159
160//=======================================================================
161//function : Check
162//purpose :
163//=======================================================================
164
165const Handle(Interface_Check)& Interface_CheckIterator::Check
166 (const Standard_Integer num) const
167{
168 Standard_Integer i, nb = thelist->Length();
169 for (i = 1; i <= nb; i ++) {
170 if (num == thenums->Value(i)) return thelist->Value(i);
171 }
172 return nulcheck();
173}
174
175
176//=======================================================================
177//function : Check
178//purpose :
179//=======================================================================
180
181const Handle(Interface_Check)& Interface_CheckIterator::Check
182 (const Handle(Standard_Transient)& ent) const
183{
184 Standard_Integer num = -1;
185 if (!themod.IsNull()) num = themod->Number(ent);
186 if (num > 0) return Check(num);
187
188 Standard_Integer i, nb = thelist->Length();
189 for (i = 1; i <= nb; i ++) {
190 if (ent == thelist->Value(i)->Entity()) return thelist->Value(i);
191 }
192 return nulcheck();
193}
194
195
196//=======================================================================
197//function : CCheck
198//purpose :
199//=======================================================================
200
201Handle(Interface_Check)& Interface_CheckIterator::CCheck
202 (const Standard_Integer num)
203{
204 Standard_Integer i, nb = thenums->Length();
205 for (i = 1; i <= nb; i ++) {
206 if (num == thenums->Value(i)) return thelist->ChangeValue(i);
207 }
208 Handle(Interface_Check) ach = new Interface_Check;
209 thelist->Append(ach); thenums->Append(num);
210 return thelist->ChangeValue (thelist->Length());
211}
212
213
214//=======================================================================
215//function : CCheck
216//purpose :
217//=======================================================================
218
219Handle(Interface_Check)& Interface_CheckIterator::CCheck
220 (const Handle(Standard_Transient)& ent)
221{
222 Standard_Integer num = -1;
223 if (!themod.IsNull()) num = themod->Number(ent);
224 if (num > 0) return CCheck(num);
225
226 Standard_Integer i, nb = thelist->Length();
227 for (i = 1; i <= nb; i ++) {
228 if (ent == thelist->Value(i)->Entity()) return thelist->ChangeValue(i);
229 }
230
231 Handle(Interface_Check) ach = new Interface_Check;
232 thelist->Append(ach); thenums->Append(num);
233 return thelist->ChangeValue (thelist->Length());
234}
235
236
237//=======================================================================
238//function : IsEmpty
239//purpose :
240//=======================================================================
241
242Standard_Boolean Interface_CheckIterator::IsEmpty
243 (const Standard_Boolean failsonly) const
244{
245 if (thelist->IsEmpty()) return Standard_True;
246 if (!failsonly) return Standard_False;
247 Standard_Integer i, nb = thelist->Length();
248 for (i = 1; i <= nb; i ++) {
249 if (thelist->Value(i)->HasFailed()) return Standard_False;
250 }
251 return Standard_True;
252}
253
254
255//=======================================================================
256//function : Status
257//purpose :
258//=======================================================================
259
260Interface_CheckStatus Interface_CheckIterator::Status () const
261{
262 Interface_CheckStatus stat = Interface_CheckOK;
263 Standard_Integer i, nb = thelist->Length();
264 for (i = 1; i <= nb; i ++) {
265 const Handle(Interface_Check) ach = thelist->Value(i);
266 if (ach->HasFailed()) return Interface_CheckFail;
267 if (ach->NbWarnings() > 0) stat = Interface_CheckWarning;
268 }
269 return stat;
270}
271
272
273//=======================================================================
274//function : Complies
c48e2889 275//purpose :
7fd59977 276//=======================================================================
277
278Standard_Boolean Interface_CheckIterator::Complies
279 (const Interface_CheckStatus stat) const
280{
c48e2889 281 Standard_Boolean res = (stat == Interface_CheckNoFail);
282 Standard_Integer nb = thelist->Length();
283 for (Standard_Integer i = 1; i <= nb; ++i)
284 {
7fd59977 285 const Handle(Interface_Check) ach = thelist->Value(i);
286 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
c48e2889 287 switch (stat)
288 {
289 case Interface_CheckOK:
290 {
291 if (nbf + nbw > 0)
292 {
293 return Standard_False;
294 }
295 break;
296 }
297 case Interface_CheckWarning:
298 {
299 if (nbf > 0)
300 {
301 return Standard_False;
302 }
303 if (nbw > 0)
304 {
305 res = Standard_True;
306 }
307 break;
308 }
309 case Interface_CheckFail:
310 {
311 if (nbf > 0)
312 {
313 return Standard_True;
314 }
315 break;
316 }
317 case Interface_CheckAny:
318 {
319 return Standard_True;
320 }
321 case Interface_CheckMessage:
322 {
323 if (nbf + nbw > 0)
324 {
325 return Standard_True;
326 }
327 break;
328 }
329 case Interface_CheckNoFail:
330 {
331 if (nbf > 0)
332 {
333 return Standard_False;
334 }
335 break;
336 }
337 default:
338 break;
7fd59977 339 }
340 }
341 return res;
342}
343
344
345//=======================================================================
346//function : Extract
347//purpose :
348//=======================================================================
349
350Interface_CheckIterator Interface_CheckIterator::Extract
351 (const Interface_CheckStatus stat) const
352{
353 Interface_CheckIterator res;
354 res.SetModel (themod); res.SetName (thename.ToCString());
355 Standard_Integer i, nb = thelist->Length();
356 for (i = 1; i <= nb; i ++) {
357 const Handle(Interface_Check) ach = thelist->Value(i);
358 Standard_Integer nbf = ach->NbFails(), nbw = ach->NbWarnings();
359 Standard_Boolean prend = Standard_False;
360 switch (stat) {
361 case Interface_CheckOK : prend = (nbf + nbw == 0); break;
362 case Interface_CheckWarning : prend = (nbf == 0 && nbw > 0); break;
363 case Interface_CheckFail : prend = (nbf > 0); break;
364 case Interface_CheckAny : prend = Standard_True; break;
365 case Interface_CheckMessage : prend = (nbf + nbw > 0); break;
366 case Interface_CheckNoFail : prend = (nbf == 0); break;
367 default : break;
368 }
369 if (prend) res.Add (ach,thenums->Value(i));
370 }
371 return res;
372}
373
374
375//=======================================================================
376//function : Extract
377//purpose :
378//=======================================================================
379
380Interface_CheckIterator Interface_CheckIterator::Extract
381 (const Standard_CString mess,
382 const Standard_Integer incl, const Interface_CheckStatus stat) const
383{
384 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
385 Interface_CheckIterator res;
386 res.SetModel (themod); res.SetName (thename.ToCString());
387 Standard_Integer i, nb = thelist->Length();
388 for (i = 1; i <= nb; i ++) {
389 const Handle(Interface_Check) ach = thelist->Value(i);
390 if (ach->Complies(str,incl,stat)) res.Add (ach,thenums->Value(i));
391 }
392 return res;
393}
394
395
396//=======================================================================
397//function : Remove
398//purpose :
399//=======================================================================
400
401Standard_Boolean Interface_CheckIterator::Remove(const Standard_CString mess,
402 const Standard_Integer incl,
403 const Interface_CheckStatus stat)
404{
405 Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString (mess);
406 Standard_Boolean res = Standard_False;
407 Standard_Integer i, nb = thelist->Length();
408 for (i = 1; i <= nb; i ++) {
409 Handle(Interface_Check) ach = thelist->ChangeValue(i);
410 if (ach->Remove (str,incl,stat)) res = Standard_True;
411 }
412 return res;
413}
414
415
416//=======================================================================
417//function : Checkeds
418//purpose :
419//=======================================================================
420
421Handle(TColStd_HSequenceOfTransient) Interface_CheckIterator::Checkeds
422 (const Standard_Boolean failsonly, const Standard_Boolean global) const
423{
424 Handle(TColStd_HSequenceOfTransient) list;
425 if (themod.IsNull()) return list;
426 list = new TColStd_HSequenceOfTransient();
427 Standard_Integer num, i, nb = thelist->Length();
428 for (i = 1; i <= nb; i ++) {
429 const Handle(Interface_Check) chk = thelist->Value(i);
430 if (failsonly && !chk->HasFailed()) continue;
431 if (chk->NbWarnings() == 0) continue;
432 num = thenums->Value(i);
433 if (num == 0 && global) list->Append (themod);
434 else if (num > 0) list->Append (themod->Value(num));
435 }
436 return list;
437}
438
439
440//=======================================================================
441//function : Start
442//purpose :
443//=======================================================================
444
445void Interface_CheckIterator::Start () const
446{
447 thecurr->CValue() = 1;
448}
449
450
451//=======================================================================
452//function : More
453//purpose :
454//=======================================================================
455
456Standard_Boolean Interface_CheckIterator::More () const
457{
458 if (thecurr->Value() < 0) thecurr->CValue() = 1;
459 return (thecurr->Value() <= thelist->Length());
460}
461
462
463//=======================================================================
464//function : Next
465//purpose :
466//=======================================================================
467
468void Interface_CheckIterator::Next () const
469{
470 if (thecurr->Value() < 0) thecurr->CValue() = 1;
471 thecurr->CValue() ++;
472}
473
474
475//=======================================================================
476//function : Value
477//purpose :
478//=======================================================================
479
480const Handle(Interface_Check)& Interface_CheckIterator::Value () const
481{
9775fa61 482 if (thecurr->Value() > thelist->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value");
7fd59977 483 return thelist->Value(thecurr->Value());
484}
485
486
487//=======================================================================
488//function : Number
489//purpose :
490//=======================================================================
491
492Standard_Integer Interface_CheckIterator::Number () const
493{
9775fa61 494 if (thecurr->Value() > thenums->Length()) throw Standard_NoSuchObject("Interface Check Iterator : Value");
7fd59977 495 return thenums->Value(thecurr->Value());
496}
497
498
499//=======================================================================
500//function : Print
501//purpose :
502//=======================================================================
503
504void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
505 const Standard_Boolean failsonly,
506 const Standard_Integer final) const
507{
508 Print (S,themod,failsonly,final);
509}
510
511
512//=======================================================================
513//function : Print
514//purpose :
515//=======================================================================
516
517void Interface_CheckIterator::Print(const Handle(Message_Messenger)& S,
518 const Handle(Interface_InterfaceModel)& model,
519 const Standard_Boolean failsonly,
520 const Standard_Integer /*final*/) const
521{
522 Standard_Boolean titre = Standard_False;
523 /*Standard_CString mesnum;
524 Standard_CString mesnum0 = ":";
525 Standard_CString mesnum1 = " (original):";
526 Standard_CString mesnum2 = " (computed):"; */
527 Standard_Integer i, nbch = 0, nb = thelist->Length();//,j; svv #2
528 Standard_Boolean yamod = !model.IsNull();
529 for (i = 1; i <= nb; i ++) {
530 const Handle(Interface_Check) ach = thelist->Value(i);
531 Standard_Integer nbw = 0, nbf = ach->NbFails();
532 if (!failsonly) nbw = ach->NbWarnings();
533 if (nbf + nbw == 0) continue;
534 Handle(Standard_Transient) ent = ach->Entity();
535 Standard_Integer nm0 = thenums->Value(i);
536 Standard_Boolean entnul = ent.IsNull();
537 Standard_Integer num = nm0;
538 if (nm0 <= 0 && !entnul && yamod) num = model->Number(ent);
539 if (nm0 <= 0 && entnul) num = -1; // Global
540// mesnum = mesnum0;
541// if (yamod) mesnum = (nm0 > 0 ? mesnum1 : mesnum2);
542
543 if (!titre) S<<" ** " << Name() << " **"<<endl;
544 titre = Standard_True;
545 S<<"Check:"; if(nb > 9 && i < 10) S<<" "; if (nb > 99 && i < 100) S<<" ";
546 S<<i;
547 if (num < 0) S<<" -- Global Check"<<endl;
548 else if (num == 0) S<<" -- Entity n0 ??:";
549 else {
550 if (yamod) { S<<" -- Entity (n0:id) "; model->Print (ent,S); }
551 else S<<" -- Entity n0 "<<num;
552// S<<" -- Entity n0 "<<num<<mesnum;
553// if (yamod) model->PrintLabel(ent,S);
554 }
555 if (num >= 0 && entnul) S<<" (unknown Type)"<<endl;
556 else if (num >= 0 && !entnul) {
557 if (yamod) S<<" Type:"<<model->TypeName(ent)<<endl;
558 else S<<" Type:"<<ent->DynamicType()->Name()<<endl;
559 }
560
561 nbch ++;
562 ach->Print (S, (failsonly ? 1 : 3));
563 }
564// if (nbch > 0) S<<" ---- Checks : "<<nbch<<" ----"<<endl;
565}
566
567
568//=======================================================================
569//function : Destroy
570//purpose :
571//=======================================================================
572
573void Interface_CheckIterator::Destroy ()
574{
575 thecurr.Nullify();
576} // redevient standard