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