0024830: Remove redundant keyword 'mutable' in CDL declarations
[occt.git] / src / StepData / StepData_Protocol.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 <StepData_Protocol.ixx>
15 #include <StepData_StepModel.hxx>
16 #include <StepData_UndefinedEntity.hxx>
17 #include <StepData_Described.hxx>
18 #include <Interface_DataMapIteratorOfDataMapOfTransientInteger.hxx>
19 #include <stdio.h>
20
21
22 //  Le Protocol de base reconnait UnknownEntity
23
24 //static TCollection_AsciiString  thename("(DEFAULT)");
25 static Standard_CString thename = "(DEFAULT)";
26
27 StepData_Protocol::StepData_Protocol ()
28 {
29 }
30
31 Standard_Integer  StepData_Protocol::NbResources () const
32 {
33   return 0;
34 }
35
36
37 Handle(Interface_Protocol) StepData_Protocol::Resource
38   (const Standard_Integer /*num*/) const
39 {
40   Handle(Interface_Protocol) nulproto;  
41   return nulproto;
42 }
43
44
45 Standard_Integer  StepData_Protocol::CaseNumber
46   (const Handle(Standard_Transient)& obj) const
47 {
48   if (obj.IsNull()) return 0;
49   Standard_Integer num = TypeNumber (obj->DynamicType());
50   if (num > 0) return num;
51   Handle(StepData_Described) dc = Handle(StepData_Described)::DownCast(obj);
52   if (dc.IsNull()) return 0;
53   return DescrNumber (dc->Description());
54 }
55
56
57 Standard_Integer  StepData_Protocol::TypeNumber
58   (const Handle(Standard_Type)& atype) const
59 {
60   if (atype == STANDARD_TYPE(StepData_UndefinedEntity)) return 1;
61   return 0;
62 }
63
64
65 Standard_CString StepData_Protocol::SchemaName () const
66 {
67   return thename;
68 }
69
70
71 Handle(Interface_InterfaceModel)  StepData_Protocol::NewModel () const 
72 {
73   return new StepData_StepModel;
74 }
75
76
77 Standard_Boolean  StepData_Protocol::IsSuitableModel
78   (const Handle(Interface_InterfaceModel)& model) const 
79 {
80   return model->IsKind(STANDARD_TYPE(StepData_StepModel));
81 }
82
83
84 Handle(Standard_Transient)  StepData_Protocol::UnknownEntity () const
85 {
86   return new StepData_UndefinedEntity;
87 }
88
89
90 Standard_Boolean  StepData_Protocol::IsUnknownEntity
91   (const Handle(Standard_Transient)& ent) const 
92 {
93   if (!ent.IsNull())
94     return ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity));
95   return Standard_False;
96 }
97
98
99 //  ####    Description pour LateBinding
100
101 Standard_Integer  StepData_Protocol::DescrNumber
102   (const Handle(StepData_EDescr)& adescr) const
103 {
104   if (thedscnum.IsBound(adescr)) return thedscnum.Find(adescr);
105   return 0;
106 }
107
108
109 void  StepData_Protocol::AddDescr
110   (const Handle(StepData_EDescr)& adescr, const Standard_Integer CN)
111 {
112   Handle(StepData_ESDescr) sd = Handle(StepData_ESDescr)::DownCast(adescr);
113   thedscnum.Bind (adescr,CN);
114
115 //  Simple : memorisee selon son nom
116 //  sinon que faire ? on memorise selon le numero passe en alpha-num ...
117 //   (temporaire)
118   if (thedscnam.IsNull()) thedscnam = new Dico_DictionaryOfTransient;
119   if (!sd.IsNull()) thedscnam->SetItem (sd->TypeName(),sd);
120   char fonom[10];
121   sprintf(fonom,"%d",CN);
122   thedscnam->SetItem (fonom,adescr);
123 }
124
125
126 Standard_Boolean  StepData_Protocol::HasDescr () const
127 {
128   return !thedscnam.IsNull();
129 }
130
131
132 Handle(StepData_EDescr)  StepData_Protocol::Descr
133   (const Standard_Integer num) const
134 {
135   Handle(StepData_EDescr) dsc;
136   if (thedscnam.IsNull()) return dsc;
137   char fonom[10];
138   sprintf(fonom,"%d",num);
139   if (!thedscnam->GetItem (fonom,dsc)) dsc.Nullify();
140   return dsc;
141 }
142
143
144 Handle(StepData_EDescr)  StepData_Protocol::Descr
145   (const Standard_CString name, const Standard_Boolean anylevel) const
146 {
147   Handle(StepData_EDescr) sd;
148   if (!thedscnam.IsNull()) {
149     if (thedscnam->GetItem (name,sd)) return sd;
150   }
151   if (!anylevel) return sd;
152
153   Standard_Integer i, nb = NbResources();
154   for (i = 1; i <= nb; i ++) {
155     Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
156     if (sp.IsNull()) continue;
157     sd = sp->Descr (name,anylevel);
158     if (!sd.IsNull()) return sd;
159   }
160   return sd;
161 }
162
163
164 Handle(StepData_ESDescr)  StepData_Protocol::ESDescr
165   (const Standard_CString name, const Standard_Boolean anylevel) const
166 {
167   return Handle(StepData_ESDescr)::DownCast(Descr(name,anylevel));
168 }
169
170
171 Handle(StepData_ECDescr)  StepData_Protocol::ECDescr
172   (const TColStd_SequenceOfAsciiString& names, const Standard_Boolean anylevel) const
173 {
174   Standard_Integer i, nb = names.Length();
175   Handle(StepData_ECDescr) cd;
176   Interface_DataMapIteratorOfDataMapOfTransientInteger iter(thedscnum);
177   for (; iter.More(); iter.Next()) {
178     cd = Handle(StepData_ECDescr)::DownCast (iter.Key());
179     if (cd.IsNull()) continue;
180     if (cd->NbMembers() != nb) continue;
181     Standard_Boolean ok = Standard_True;
182     for (i = 1; i <= nb; i ++) {
183       if (!names(i).IsEqual (cd->Member(i)->TypeName())) { ok = Standard_False; break; }
184     }
185     if (ok) return cd;
186   }
187   cd.Nullify();
188   if (!anylevel) return cd;
189
190   nb = NbResources();
191   for (i = 1; i <= nb; i ++) {
192     Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
193     if (sp.IsNull()) continue;
194     cd = sp->ECDescr (names,anylevel);
195     if (!cd.IsNull()) return cd;
196   }
197   return cd;
198 }
199
200
201 void  StepData_Protocol::AddPDescr
202   (const Handle(StepData_PDescr)& pdescr)
203 {
204   if (thepdescr.IsNull()) thepdescr = new Dico_DictionaryOfTransient;
205   thepdescr->SetItem (pdescr->Name(),pdescr);
206 }
207
208
209 Handle(StepData_PDescr)  StepData_Protocol::PDescr
210   (const Standard_CString name, const Standard_Boolean anylevel) const
211 {
212   Handle(StepData_PDescr) sd;
213   if (!thepdescr.IsNull()) {
214     if (thepdescr->GetItem (name,sd)) return sd;
215   }
216   if (!anylevel) return sd;
217
218   Standard_Integer i, nb = NbResources();
219   for (i = 1; i <= nb; i ++) {
220     Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
221     if (sp.IsNull()) continue;
222     sd = sp->PDescr (name,anylevel);
223     if (!sd.IsNull()) return sd;
224   }
225   return sd;
226 }
227
228
229 void  StepData_Protocol::AddBasicDescr
230   (const Handle(StepData_ESDescr)& esdescr)
231 {
232   if (thedscbas.IsNull()) thedscbas = new Dico_DictionaryOfTransient;
233   thedscbas->SetItem (esdescr->TypeName(),esdescr);
234 }
235
236
237 Handle(StepData_EDescr)  StepData_Protocol::BasicDescr
238   (const Standard_CString name, const Standard_Boolean anylevel) const
239 {
240   Handle(StepData_EDescr) sd;
241   if (!thedscbas.IsNull()) {
242     if (thedscbas->GetItem (name,sd)) return sd;
243   }
244   if (!anylevel) return sd;
245
246   Standard_Integer i, nb = NbResources();
247   for (i = 1; i <= nb; i ++) {
248     Handle(StepData_Protocol) sp = Handle(StepData_Protocol)::DownCast(Resource(i));
249     if (sp.IsNull()) continue;
250     sd = sp->BasicDescr (name,anylevel);
251     if (!sd.IsNull()) return sd;
252   }
253   return sd;
254 }