0024129: Eliminate remaining compiler warnings in MSVC++ 2008 32 bit with warning...
[occt.git] / src / RWHeaderSection / RWHeaderSection_ReadWriteModule.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <RWHeaderSection_ReadWriteModule.ixx>
19 #include <Interface_ReaderLib.hxx>
20 #include <StepData_WriterLib.hxx>
21 #include <HeaderSection_Protocol.hxx>
22 #include <Interface_Macros.hxx>
23 #include <Interface_ParamType.hxx>
24
25
26 #include <HeaderSection_FileName.hxx>
27 #include <HeaderSection_FileDescription.hxx>
28 #include <HeaderSection_FileSchema.hxx>
29
30 #include <StepData_UndefinedEntity.hxx>
31
32
33 #include <RWHeaderSection_RWFileName.hxx>
34 #include <RWHeaderSection_RWFileDescription.hxx>
35 #include <RWHeaderSection_RWFileSchema.hxx>
36
37 // -- General Declarations (Recognize, StepType) ---
38
39 static TCollection_AsciiString PasReco("");    // neutralise StartEntity de SW
40 static TCollection_AsciiString Reco_FileName ("FILE_NAME");
41 static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
42 static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");
43
44         // -- Definition of the libraries --
45
46 RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
47 {
48         Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
49         StepData_WriterLib::SetGlobal(this,protocol);
50         Interface_ReaderLib::SetGlobal(this,protocol);
51 }
52
53         // --- Case Recognition ---
54
55 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
56         (const TCollection_AsciiString& key) const
57 {
58         if (key.IsEqual(Reco_FileName)) return 1;
59         if (key.IsEqual(Reco_FileDescription)) return 2;
60         if (key.IsEqual(Reco_FileSchema)) return 3;
61 return 0;
62 }
63
64         // --- External Mapping Case Recognition ---
65 #ifdef DEB
66 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const
67 {
68   Standard_Integer NbComp = types.Length();
69   if (NbComp < 2) {
70     cout << "Plex Instance illegal " << endl;
71   }
72   return 0;
73 }
74 #else
75 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const
76 { return 0; }
77 #endif
78
79         // --- External Mapping Recognition ---
80
81 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
82         (const Standard_Integer /*CN*/) const
83 {
84         return Standard_False;
85 }
86
87
88
89 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
90         (const Standard_Integer CN) const
91 {
92         switch (CN) {
93           case 1 : return Reco_FileName;
94           case 2 : return Reco_FileDescription;
95           case 3 : return Reco_FileSchema;
96           default : return PasReco;
97         }
98 }
99
100         // -- Reading of a file --
101
102 void RWHeaderSection_ReadWriteModule::ReadStep
103         (const Standard_Integer CN,
104          const Handle(StepData_StepReaderData)& data,
105          const Standard_Integer num,
106          Handle(Interface_Check)& ach,
107          const Handle(Standard_Transient)&ent) const
108 {
109         if (CN == 0) return;
110         switch (CN) {
111           case 1 : 
112             {
113               DeclareAndCast(HeaderSection_FileName, anent, ent);
114               RWHeaderSection_RWFileName tool;
115               if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
116               else tool.ReadStep (data,num,ach,anent);
117             }
118
119             break;
120           case 2 : 
121             {
122               DeclareAndCast(HeaderSection_FileDescription, anent, ent);
123               RWHeaderSection_RWFileDescription tool;
124               if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
125               else tool.ReadStep (data,num,ach,anent);
126             }
127
128             break;
129           case 3 : 
130             {
131               DeclareAndCast(HeaderSection_FileSchema, anent, ent);
132               RWHeaderSection_RWFileSchema tool;
133               if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
134               else tool.ReadStep (data,num,ach,anent);
135             }
136
137             break;
138           case 4 : 
139             {
140               DeclareAndCast(StepData_UndefinedEntity,und,ent);
141               if (und.IsNull()) ach->AddFail
142                 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
143               else und->ReadRecord(data,num,ach);
144             }
145
146             break;
147           default : ach->AddFail("Type Mismatch when reading - Entity");
148         }
149
150 return;}
151
152         // -- Writing of a file --
153
154 void RWHeaderSection_ReadWriteModule::WriteStep
155         (const Standard_Integer CN,
156          StepData_StepWriter& SW,
157          const Handle(Standard_Transient)&ent) const
158 {
159         if (CN == 0) return;
160         switch (CN) {
161           case 1 : 
162             {
163               DeclareAndCast(HeaderSection_FileName, anent, ent);
164               RWHeaderSection_RWFileName tool;
165               if (anent.IsNull()) return; 
166               else tool.WriteStep (SW,anent);
167             }
168
169             break;
170           case 2 : 
171             {
172               DeclareAndCast(HeaderSection_FileDescription, anent, ent);
173               RWHeaderSection_RWFileDescription tool;
174               if (anent.IsNull()) return; 
175               else tool.WriteStep (SW,anent);
176             }
177
178             break;
179           case 3 : 
180             {
181               DeclareAndCast(HeaderSection_FileSchema, anent, ent);
182               RWHeaderSection_RWFileSchema tool;
183               if (anent.IsNull()) return; 
184               else tool.WriteStep (SW,anent);
185             }
186
187             break;
188           case 4 : 
189             {
190               DeclareAndCast(StepData_UndefinedEntity,und,ent);
191               if (und.IsNull()) break;
192 //  Parentheses gerees par StepWriter lui-meme
193 //   car en recevant le type PasReco, StepWriter ne l'affiche pas,
194 //   mais il gere les parentheses comme si de rien n etait
195               if (und->IsComplex())   SW.StartComplex();
196               und->WriteParams(SW);
197               if (und->IsComplex())   SW.EndComplex();
198             }
199
200             break;
201           default : return;
202         }
203 }
204