0026781: Coding rules - eliminate GCC warning -Wunused-result
[occt.git] / src / IFSelect / IFSelect_SelectSignature.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
7fd59977 14
42cf5bc1 15#include <IFSelect_SelectSignature.hxx>
16#include <IFSelect_Signature.hxx>
17#include <IFSelect_SignCounter.hxx>
18#include <Interface_Graph.hxx>
19#include <Interface_InterfaceModel.hxx>
20#include <Standard_Transient.hxx>
21#include <Standard_Type.hxx>
22#include <TCollection_AsciiString.hxx>
7fd59977 23
24// theexact : -1 OUI 0 NON une seule valeur > 0 NON nb de valeurs
25// signmode : 1 prendre si contenu, 2 refuser si contenu
26// 3 prendre si egal, 4 refuser si egal
27// ou test numerique, ajouter : 16 < 24 <= 32 > 40 >=
7fd59977 28static Standard_Integer multsign
29 (const TCollection_AsciiString& signtext,
30 TColStd_SequenceOfAsciiString& signlist,
31 TColStd_SequenceOfInteger& signmode)
32{
33 Standard_Integer i, nb = signtext.Length(), mode = 0;
34 for (i = 1; i <= nb; i ++) {
35 char unsign = signtext.Value(i);
36 if (unsign == '|' || unsign == '!' || unsign == '=') { mode = 1; break; }
37 if (unsign == '<' || unsign == '>') { mode = 1; break; }
38 }
39 if (mode == 0) return mode;
40// On va tronconner
41 TCollection_AsciiString item; Standard_Integer imod = 1;
42 for (i = 1; i <= nb; i ++) {
43 char unsign = signtext.Value(i);
44 if (unsign == '|' || unsign == '!') {
45 if (item.Length() > 0) {
46 signlist.Append (item);
47 signmode.Append (imod);
48 item.Clear();
49 mode ++;
50 }
51 imod = (unsign == '|' ? 1 : 2);
52 }
53 else if (unsign == '<') imod += 16;
54 else if (unsign == '>') imod += 32;
55 else if (unsign == '=') { if (imod < 8) imod += 2; else imod += 8; }
56 else item.AssignCat (unsign);
57 }
58 if (item.Length() > 0) {
59 signlist.Append (item);
60 signmode.Append (imod);
61// mode ++; valait un au depart
62 }
63 return mode;
64}
65
66
67
68 IFSelect_SelectSignature::IFSelect_SelectSignature
69 (const Handle(IFSelect_Signature)& matcher,
70 const TCollection_AsciiString& signtext, const Standard_Boolean exact)
71 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
72{ if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
73
74 IFSelect_SelectSignature::IFSelect_SelectSignature
75 (const Handle(IFSelect_Signature)& matcher,
76 const Standard_CString signtext, const Standard_Boolean exact)
77 : thematcher (matcher) , thesigntext (signtext) , theexact (exact ? -1 : 0)
78{ if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
79
80 IFSelect_SelectSignature::IFSelect_SelectSignature
81 (const Handle(IFSelect_SignCounter)& counter,
82 const Standard_CString signtext, const Standard_Boolean exact)
83 : thecounter (counter) , thesigntext (signtext) , theexact (exact ? -1 : 0)
84{ if (!exact) theexact = multsign (thesigntext,thesignlist,thesignmode); }
85
86 Handle(IFSelect_Signature) IFSelect_SelectSignature::Signature () const
87 { return thematcher; }
88
89 Handle(IFSelect_SignCounter) IFSelect_SelectSignature::Counter () const
90 { return thecounter; }
91
92
93 Standard_Boolean IFSelect_SelectSignature::SortInGraph
94 (const Standard_Integer , const Handle(Standard_Transient)& ent,
95 const Interface_Graph& G) const
96{
97 Standard_Boolean res;
98 Standard_CString txt;
99 Handle(Interface_InterfaceModel) model = G.Model();
100 if (theexact <= 0) {
101 if (!thematcher.IsNull()) return thematcher->Matches (ent,model,thesigntext, (theexact < 0));
102 txt = thecounter->ComputedSign(ent,G);
103 return IFSelect_Signature::MatchValue (txt,thesigntext , (theexact < 0));
104 }
105
106// sinon : liste
107// Analyse en sequence : si alternance prend/prend-pas, le dernier a raison
108// en consequence, si que des prend ou que des prend-pas, c est commutatif
109// DONC recommandation : mettre les prend-pas en fin
110
111// AU DEPART : prendre = ne prendre que. prend-pas = prend-tout-sauf ...
112// Donc si le premier est un prend-pas, je commence par tout prendre
113 Standard_Integer hmod = thesignmode.Value(1);
114 Standard_Integer jmod = hmod/8;
115 Standard_Integer imod = hmod - (jmod*8);
116 res = (imod == 2 || imod == 4);
117 for (Standard_Integer i = 1; i <= theexact; i ++) {
118 Standard_CString signtext = thesignlist.Value(i).ToCString();
119 hmod = thesignmode.Value(i);
120 jmod = hmod/8;
121 imod = hmod - (jmod*8);
122 Standard_Boolean quid;
123 if (jmod == 0) {
124 if (!thematcher.IsNull()) quid = thematcher->Matches (ent,model,signtext,(imod > 2));
125 else quid = IFSelect_Signature::MatchValue
126 ( thecounter->ComputedSign(ent,G),signtext, (imod > 2) );
127 }
128 else {
129 if (!thematcher.IsNull()) txt = thematcher->Value (ent,model);
130 else txt = thecounter->ComputedSign (ent,G);
131
132 Standard_Integer val = atoi(txt);
133 Standard_Integer lav = atoi (signtext);
134 switch (jmod) {
135 case 2 : quid = (val < lav); break;
136 case 3 : quid = (val <= lav); break;
137 case 4 : quid = (val > lav); break;
138 case 5 : quid = (val >= lav); break;
139 default : quid = Standard_False; break;
140 }
141 }
142 if ((imod == 1 || imod == 3) && quid) res = Standard_True;
143 if ((imod == 2 || imod == 4) && quid) res = Standard_False;
144 }
145 return res;
146}
147
148 Standard_Boolean IFSelect_SelectSignature::Sort
35e08fe8 149 (const Standard_Integer , const Handle(Standard_Transient)& /*ent*/,
150 const Handle(Interface_InterfaceModel)& /*model*/) const
7fd59977 151{ return Standard_True; }
152
153 const TCollection_AsciiString& IFSelect_SelectSignature::SignatureText () const
154 { return thesigntext; }
155
156 Standard_Boolean IFSelect_SelectSignature::IsExact () const
157 { return (theexact < 0); }
158
159 TCollection_AsciiString IFSelect_SelectSignature::ExtractLabel () const
160{
161 TCollection_AsciiString lab;
162 if (!thematcher.IsNull()) lab.AssignCat (thematcher->Name());
163 else lab.AssignCat (thecounter->Name());
164 if (theexact < 0) lab.AssignCat(" matching ");
165 else if (theexact == 0) lab.AssignCat(" containing ");
166 else lab.AssignCat(" matching list ");
167 lab.AssignCat(thesigntext);
168 return lab;
169}