145e9e5303dc97ef5483d92abd6e073e288fae63
[occt.git] / src / IFSelect / IFSelect_Signature.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <IFSelect_Signature.ixx>
19 #include <stdio.h>
20
21
22 // unused 
23 //static Standard_CString nulsign = "";
24 static char intval[20];
25
26
27     IFSelect_Signature::IFSelect_Signature (const Standard_CString name)
28     : thename (name)     {  thecasi[0] = thecasi[1] = thecasi[2] = 0;  }
29
30     void  IFSelect_Signature::SetIntCase
31   (const Standard_Boolean hasmin, const Standard_Integer valmin,
32    const Standard_Boolean hasmax, const Standard_Integer valmax)
33 {
34   thecasi[0] = 1;
35   if (hasmin) {  thecasi[0] += 2;  thecasi[1] = valmin;  }
36   if (hasmax) {  thecasi[0] += 4;  thecasi[2] = valmax;  }
37 }
38
39     Standard_Boolean  IFSelect_Signature::IsIntCase
40   (Standard_Boolean& hasmin, Standard_Integer& valmin,
41    Standard_Boolean& hasmax, Standard_Integer& valmax) const
42 {
43   hasmin = hasmax = Standard_False;
44   valmin = valmax = 0;
45   if (!thecasi[0]) return Standard_False;
46   if (thecasi[0] & 2)  {  hasmin = Standard_True;  valmin = thecasi[1];  }
47   if (thecasi[0] & 4)  {  hasmax = Standard_True;  valmax = thecasi[2];  }
48   return Standard_True;
49 }
50
51     void  IFSelect_Signature::AddCase (const Standard_CString acase)
52 {
53   if (thecasl.IsNull()) thecasl = new TColStd_HSequenceOfAsciiString();
54   TCollection_AsciiString scase(acase);
55   thecasl->Append(scase);
56 }
57
58   Handle(TColStd_HSequenceOfAsciiString) IFSelect_Signature::CaseList () const
59       {  return thecasl;  }
60
61
62     Standard_CString IFSelect_Signature::Name () const
63       { return thename.ToCString();  }
64
65     TCollection_AsciiString  IFSelect_Signature::Label () const
66 {
67   TCollection_AsciiString label("Signature : ");
68   label.AssignCat(thename);
69   return label;
70 }
71
72
73     Standard_Boolean  IFSelect_Signature::Matches
74   (const Handle(Standard_Transient)& ent,
75    const Handle(Interface_InterfaceModel)& model,
76    const TCollection_AsciiString& text, const Standard_Boolean exact) const
77
78 {  return IFSelect_Signature::MatchValue ( Value(ent,model) , text, exact);  }
79
80
81     Standard_Boolean  IFSelect_Signature::MatchValue
82   (const Standard_CString val,
83    const TCollection_AsciiString& text, const Standard_Boolean exact)
84 {
85   if (exact) return text.IsEqual (val);
86   // NB: no regexp
87   char cardeb = text.Value(1);
88   Standard_Integer ln,lnt,i,j;
89   ln  = text.Length();
90   lnt = strlen(val) - ln;
91   for (i = 0; i <= lnt; i ++) {
92     if (val[i] == cardeb) {
93 //    un candidat
94       Standard_Boolean res = Standard_True;
95       for (j = 1; j < ln; j ++) {
96         if (val[i+j] != text.Value(j+1))
97           {  res = Standard_False;  break;  }
98       }
99       if (res) return res;
100     }
101   }
102   return Standard_False;
103 }
104
105
106     Standard_CString  IFSelect_Signature::IntValue
107   (const Standard_Integer val)
108 {
109   switch (val) {
110     case 0 : return "0";
111     case 1 : return "1";
112     case 2 : return "2";
113     case 3 : return "3";
114     case 4 : return "4";
115     case 5 : return "5";
116     case 6 : return "6";
117     case 7 : return "7";
118     case 8 : return "8";
119     case 9 : return "9";
120     default : break;
121   }
122   sprintf (intval,"%d",val);
123   return intval;
124 }