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_Signature.hxx> |
16 | #include <Interface_InterfaceModel.hxx> |
17 | #include <Standard_Transient.hxx> |
18 | #include <Standard_Type.hxx> |
19 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
20 | |
42cf5bc1 |
21 | #include <stdio.h> |
92efcf78 |
22 | IMPLEMENT_STANDARD_RTTIEXT(IFSelect_Signature,Interface_SignType) |
23 | |
7fd59977 |
24 | // unused |
25 | //static Standard_CString nulsign = ""; |
26 | static char intval[20]; |
27 | |
28 | |
29 | IFSelect_Signature::IFSelect_Signature (const Standard_CString name) |
30 | : thename (name) { thecasi[0] = thecasi[1] = thecasi[2] = 0; } |
31 | |
32 | void IFSelect_Signature::SetIntCase |
33 | (const Standard_Boolean hasmin, const Standard_Integer valmin, |
34 | const Standard_Boolean hasmax, const Standard_Integer valmax) |
35 | { |
36 | thecasi[0] = 1; |
37 | if (hasmin) { thecasi[0] += 2; thecasi[1] = valmin; } |
38 | if (hasmax) { thecasi[0] += 4; thecasi[2] = valmax; } |
39 | } |
40 | |
41 | Standard_Boolean IFSelect_Signature::IsIntCase |
42 | (Standard_Boolean& hasmin, Standard_Integer& valmin, |
43 | Standard_Boolean& hasmax, Standard_Integer& valmax) const |
44 | { |
45 | hasmin = hasmax = Standard_False; |
46 | valmin = valmax = 0; |
47 | if (!thecasi[0]) return Standard_False; |
48 | if (thecasi[0] & 2) { hasmin = Standard_True; valmin = thecasi[1]; } |
49 | if (thecasi[0] & 4) { hasmax = Standard_True; valmax = thecasi[2]; } |
50 | return Standard_True; |
51 | } |
52 | |
53 | void IFSelect_Signature::AddCase (const Standard_CString acase) |
54 | { |
55 | if (thecasl.IsNull()) thecasl = new TColStd_HSequenceOfAsciiString(); |
56 | TCollection_AsciiString scase(acase); |
57 | thecasl->Append(scase); |
58 | } |
59 | |
60 | Handle(TColStd_HSequenceOfAsciiString) IFSelect_Signature::CaseList () const |
61 | { return thecasl; } |
62 | |
63 | |
64 | Standard_CString IFSelect_Signature::Name () const |
65 | { return thename.ToCString(); } |
66 | |
67 | TCollection_AsciiString IFSelect_Signature::Label () const |
68 | { |
69 | TCollection_AsciiString label("Signature : "); |
70 | label.AssignCat(thename); |
71 | return label; |
72 | } |
73 | |
74 | |
75 | Standard_Boolean IFSelect_Signature::Matches |
76 | (const Handle(Standard_Transient)& ent, |
77 | const Handle(Interface_InterfaceModel)& model, |
78 | const TCollection_AsciiString& text, const Standard_Boolean exact) const |
79 | |
80 | { return IFSelect_Signature::MatchValue ( Value(ent,model) , text, exact); } |
81 | |
82 | |
83 | Standard_Boolean IFSelect_Signature::MatchValue |
84 | (const Standard_CString val, |
85 | const TCollection_AsciiString& text, const Standard_Boolean exact) |
86 | { |
87 | if (exact) return text.IsEqual (val); |
88 | // NB: no regexp |
89 | char cardeb = text.Value(1); |
90 | Standard_Integer ln,lnt,i,j; |
91 | ln = text.Length(); |
7dc9e047 |
92 | lnt = (Standard_Integer)(strlen(val) - ln); |
7fd59977 |
93 | for (i = 0; i <= lnt; i ++) { |
94 | if (val[i] == cardeb) { |
95 | // un candidat |
96 | Standard_Boolean res = Standard_True; |
97 | for (j = 1; j < ln; j ++) { |
98 | if (val[i+j] != text.Value(j+1)) |
99 | { res = Standard_False; break; } |
100 | } |
101 | if (res) return res; |
102 | } |
103 | } |
104 | return Standard_False; |
105 | } |
106 | |
107 | |
108 | Standard_CString IFSelect_Signature::IntValue |
109 | (const Standard_Integer val) |
110 | { |
111 | switch (val) { |
112 | case 0 : return "0"; |
113 | case 1 : return "1"; |
114 | case 2 : return "2"; |
115 | case 3 : return "3"; |
116 | case 4 : return "4"; |
117 | case 5 : return "5"; |
118 | case 6 : return "6"; |
119 | case 7 : return "7"; |
120 | case 8 : return "8"; |
121 | case 9 : return "9"; |
122 | default : break; |
123 | } |
124 | sprintf (intval,"%d",val); |
125 | return intval; |
126 | } |