0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / Interface / Interface_GTool.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <Interface_GTool.ixx>
15 #include <Interface_GeneralModule.hxx>
16
17 Interface_GTool::Interface_GTool  ()    {  }
18
19     Interface_GTool::Interface_GTool
20   (const Handle(Interface_Protocol)& proto, const Standard_Integer nb)
21     : theproto (proto) , thelib (proto)
22       {  if (nb > 0)  {  thentnum.ReSize(nb);  thentmod.ReSize(nb);  }  }
23
24
25     void  Interface_GTool::SetSignType (const Handle(Interface_SignType)& sign)
26       {  thesign = sign;  }
27
28     Handle(Interface_SignType)  Interface_GTool::SignType () const
29       {  return thesign;  }
30
31     Standard_CString  Interface_GTool::SignValue
32   (const Handle(Standard_Transient)& ent,
33    const Handle(Interface_InterfaceModel)& model) const
34 {
35   if (ent.IsNull()) return "";
36   if (thesign.IsNull()) return Interface_SignType::ClassName(ent->DynamicType()->Name());
37   return thesign->Value (ent,model);
38 }
39
40     Standard_CString  Interface_GTool::SignName () const
41 {
42   if (thesign.IsNull()) return "Class Name";
43   return thesign->Name();
44 }
45
46
47     void  Interface_GTool::SetProtocol
48   (const Handle(Interface_Protocol)& proto, const Standard_Boolean enforce)
49 {
50   if (proto == theproto && !enforce) return;
51   theproto = proto;
52   thelib.Clear();
53   thelib.AddProtocol (proto);
54 }
55
56     Handle(Interface_Protocol)  Interface_GTool::Protocol () const
57       {  return theproto;  }
58
59     Interface_GeneralLib&  Interface_GTool::Lib ()
60       {  return thelib;  }
61
62     void  Interface_GTool::Reservate
63   (const Standard_Integer nb, const Standard_Boolean enforce)
64 {
65   Standard_Integer n = thentnum.NbBuckets();
66   if (n < nb && !enforce) return;
67   thentnum.ReSize (nb);  thentmod.ReSize (nb);
68 }
69
70     void  Interface_GTool::ClearEntities ()
71       {  thentnum.Clear();  thentmod.Clear();  }
72
73
74 //=======================================================================
75 //function : Select
76 //purpose  : 
77 //=======================================================================
78
79 Standard_Boolean  Interface_GTool::Select (const Handle(Standard_Transient)& ent,
80                                            Handle(Interface_GeneralModule)& gmod,
81                                            Standard_Integer& CN,
82                                            const Standard_Boolean enforce)
83 {
84   const Handle(Standard_Type)& aType = ent->DynamicType();
85   Standard_Integer num = thentmod.FindIndex(aType);// (ent);
86   if (num == 0 || enforce) {
87     if (thelib.Select (ent,gmod,CN)) {
88       num = thentmod.Add (aType,gmod);
89       thentnum.Bind (aType,CN);
90       return Standard_True;
91     }
92     return Standard_False;
93   }
94   gmod = Handle(Interface_GeneralModule)::DownCast (thentmod.FindFromKey(aType));
95   CN   = thentnum.Find (aType);
96   return Standard_True;
97 }