0023042: Potential mistakes in (s)printf usage
[occt.git] / src / IFSelect / IFSelect_SignMultiple.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_SignMultiple.ixx>
19 #include <TCollection_AsciiString.hxx>
20
21
22 static TCollection_AsciiString theval;    // temporaire pour construire Value
23
24     IFSelect_SignMultiple::IFSelect_SignMultiple (const Standard_CString name)
25     : IFSelect_Signature (name)    {  }
26
27     void  IFSelect_SignMultiple::Add
28   (const Handle(IFSelect_Signature)& subsign,
29    const Standard_Integer tabul, const Standard_Boolean maxi)
30 {
31   if (subsign.IsNull()) return;
32   thesubs.Append (subsign);
33   thetabs.Append (maxi ? -tabul : tabul);
34 }
35
36     Standard_CString  IFSelect_SignMultiple::Value
37   (const Handle(Standard_Transient)& ent,
38    const Handle(Interface_InterfaceModel)& model) const
39 {
40   theval.Clear();
41   Standard_Integer i, nb = thesubs.Length();
42   for (i = 1; i <= nb; i ++) {
43     Standard_Integer tabul = thetabs.Value(i);
44     Standard_Boolean maxi  = (tabul < 0);
45     if (maxi) tabul = -tabul;
46     Handle(IFSelect_Signature) sign = Handle(IFSelect_Signature)::DownCast(thesubs.Value(i));
47     Standard_CString val = sign->Value (ent,model);
48     TCollection_AsciiString str(val);
49     Standard_Integer sl = str.Length();
50     str.LeftJustify (tabul,' ');
51     if (sl > tabul && maxi) {
52       str.Remove (sl+1,tabul-sl);
53       str.SetValue (sl,'.');
54     }
55     str.AssignCat("   ");
56     theval.AssignCat (str);
57   }
58   return theval.ToCString();
59 }
60
61
62     Standard_Boolean  IFSelect_SignMultiple::Matches
63   (const Handle(Standard_Transient)& ent,
64    const Handle(Interface_InterfaceModel)& model,
65    const TCollection_AsciiString& text, const Standard_Boolean exact) const
66 {
67   if (exact) return IFSelect_Signature::Matches (ent,model,text,exact);
68   Standard_Integer i, nb = thesubs.Length();
69   for (i = 1; i <= nb; i ++) {
70     Handle(IFSelect_Signature) sign =
71       Handle(IFSelect_Signature)::DownCast(thesubs.Value(i));
72     if (sign->Matches (ent,model,text,exact)) return Standard_True;
73   }
74   return Standard_False;
75 }