0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / StepData / StepData_DescrReadWrite.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
15 #include <Interface_Check.hxx>
16 #include <Interface_Macros.hxx>
17 #include <Standard_Transient.hxx>
18 #include <Standard_Type.hxx>
19 #include <StepData_DescrReadWrite.hxx>
20 #include <StepData_ECDescr.hxx>
21 #include <StepData_EDescr.hxx>
22 #include <StepData_ESDescr.hxx>
23 #include <StepData_FieldListN.hxx>
24 #include <StepData_Plex.hxx>
25 #include <StepData_Protocol.hxx>
26 #include <StepData_Simple.hxx>
27 #include <StepData_StepReaderData.hxx>
28 #include <StepData_StepWriter.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <TColStd_HSequenceOfAsciiString.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(StepData_DescrReadWrite,StepData_ReadWriteModule)
33
34 static TCollection_AsciiString nocp("?");
35
36
37     StepData_DescrReadWrite::StepData_DescrReadWrite
38   (const Handle(StepData_Protocol)& proto)
39     : theproto (proto)    {  }
40
41     Standard_Integer  StepData_DescrReadWrite::CaseStep
42   (const TCollection_AsciiString& atype) const
43 {
44   Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False);
45   if (descr.IsNull()) return 0;
46   return theproto->DescrNumber (descr);
47 }
48
49     Standard_Integer  StepData_DescrReadWrite::CaseStep
50   (const TColStd_SequenceOfAsciiString& types) const
51 {
52   Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False);
53   if (descr.IsNull()) return 0;
54   return theproto->DescrNumber (descr);
55 }
56
57
58     Standard_Boolean  StepData_DescrReadWrite::IsComplex
59   (const Standard_Integer CN) const
60 {
61   Handle(StepData_EDescr)  descr = theproto->Descr (CN);
62   if (descr.IsNull()) return Standard_False;
63   return descr->IsComplex();
64 }
65
66     const TCollection_AsciiString& StepData_DescrReadWrite::StepType
67   (const Standard_Integer CN) const
68 {
69   Handle(StepData_ESDescr)  descr = Handle(StepData_ESDescr)::DownCast
70     (theproto->Descr (CN));
71   if (descr.IsNull()) return nocp;
72   return descr->StepType();
73 }
74
75     Standard_Boolean StepData_DescrReadWrite::ComplexType
76   (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const
77 {
78   Handle(StepData_ECDescr)  descr = Handle(StepData_ECDescr)::DownCast
79     (theproto->Descr (CN));
80   if (descr.IsNull()) return Standard_False;
81   Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList();
82   if (list.IsNull()) return Standard_False;
83   Standard_Integer i, nb = list->Length();
84   for (i = 1; i <= nb; i ++)  types.Append (list->Value(i));
85   return Standard_True;
86 }
87
88
89 void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN,
90                                        const Handle(StepData_StepReaderData)& data,
91                                        const Standard_Integer num,
92                                        Handle(Interface_Check)& ach,
93                                        const Handle(Standard_Transient)&ent) const
94 {
95   if (CN == 0) return;
96   DeclareAndCast(StepData_Simple,sent,ent);
97   if (!sent.IsNull()) {
98     Handle(StepData_ESDescr) sdescr = sent->ESDescr();
99     StepData_FieldListN& fl = sent->CFields();
100     data->ReadList (num,ach,sdescr,fl);
101     return;
102   }
103
104   DeclareAndCast(StepData_Plex,cent,ent);
105   Standard_Integer i, nb=0;
106   if (!cent.IsNull()) nb = cent->NbMembers();
107   Standard_Integer n0 = num;
108   for (i = 1; i <= nb; i ++) {
109     Handle(StepData_Simple) si = cent->Member(i);
110     Handle(StepData_ESDescr) sdescr = si->ESDescr();
111     StepData_FieldListN& fl = si->CFields();
112     data->ReadList (n0,ach,sdescr,fl);
113     if (i < nb) n0 = data->NextForComplex(n0);
114   }
115 }
116
117
118     void StepData_DescrReadWrite::WriteStep
119   (const Standard_Integer CN,
120    StepData_StepWriter& SW,
121    const Handle(Standard_Transient)&ent) const
122 {
123   if (CN == 0) return;
124
125   DeclareAndCast(StepData_Simple,sent,ent);
126   if (!sent.IsNull()) {
127     Handle(StepData_ESDescr) sdescr = sent->ESDescr();
128     const StepData_FieldListN& fl = sent->Fields();
129     SW.SendList (fl,sdescr);
130     return;
131   }
132
133   DeclareAndCast(StepData_Plex,cent,ent);
134   Standard_Integer i, nb=0;
135   if (!cent.IsNull()) nb = cent->NbMembers();
136   for (i = 1; i <= nb; i ++) {
137     Handle(StepData_Simple) si = cent->Member(i);
138     Handle(StepData_ESDescr) sdescr = si->ESDescr();
139       const StepData_FieldListN& fl = si->Fields();
140       SW.StartEntity (sdescr->TypeName());
141       SW.SendList (fl,sdescr);
142   }
143 }