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