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