0028564: Support of applications using old persistence (ShapeSchema)
[occt.git] / src / StdStorage / StdStorage_HeaderData.cxx
1 // Copyright (c) 2017 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 <Standard_ErrorHandler.hxx>
15 #include <StdStorage_HeaderData.hxx>
16 #include <Storage_BaseDriver.hxx>
17 #include <Storage_StreamTypeMismatchError.hxx>
18 #include <Storage_StreamExtCharParityError.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TCollection_ExtendedString.hxx>
21
22 IMPLEMENT_STANDARD_RTTIEXT(StdStorage_HeaderData, MMgt_TShared)
23
24 StdStorage_HeaderData::StdStorage_HeaderData()
25   : myNBObj(0), myErrorStatus(Storage_VSOk)
26 {
27 }
28
29 Standard_Boolean StdStorage_HeaderData::Read(Storage_BaseDriver& theDriver)
30 {
31   // Check driver open mode
32   if (theDriver.OpenMode() != Storage_VSRead
33     && theDriver.OpenMode() != Storage_VSReadWrite)
34   {
35     myErrorStatus = Storage_VSModeError;
36     myErrorStatusExt = "OpenMode";
37     return Standard_False;
38   }
39
40   // Read info section
41   myErrorStatus = theDriver.BeginReadInfoSection();
42   if (myErrorStatus != Storage_VSOk)
43   {
44     myErrorStatusExt = "BeginReadInfoSection";
45     return Standard_False;
46   }
47
48   try
49   {
50     OCC_CATCH_SIGNALS
51     theDriver.ReadInfo(myNBObj,
52                         myStorageVersion,
53                         myDate,
54                         mySchemaName,
55                         mySchemaVersion,
56                         myApplicationName,
57                         myApplicationVersion,
58                         myDataType,
59                         myUserInfo);
60   }
61   catch (Storage_StreamTypeMismatchError)
62   {
63     myErrorStatus = Storage_VSTypeMismatch;
64     myErrorStatusExt = "ReadInfo";
65     return Standard_False;
66   }
67   catch (Storage_StreamExtCharParityError)
68   {
69     myErrorStatus = Storage_VSExtCharParityError;
70     myErrorStatusExt = "ReadInfo";
71     return Standard_False;
72   }
73
74   myErrorStatus = theDriver.EndReadInfoSection();
75   if (myErrorStatus != Storage_VSOk)
76   {
77     myErrorStatusExt = "EndReadInfoSection";
78     return Standard_False;
79   }
80
81   // Read comment section
82   myErrorStatus = theDriver.BeginReadCommentSection();
83   if (myErrorStatus != Storage_VSOk)
84   {
85     myErrorStatusExt = "BeginReadCommentSection";
86     return Standard_False;
87   }
88
89   try
90   {
91     OCC_CATCH_SIGNALS
92     theDriver.ReadComment(myComments);
93   }
94   catch (Storage_StreamTypeMismatchError)
95   {
96     myErrorStatus = Storage_VSTypeMismatch;
97     myErrorStatusExt = "ReadComment";
98     return Standard_False;
99   }
100   catch (Storage_StreamExtCharParityError)
101   {
102     myErrorStatus = Storage_VSExtCharParityError;
103     myErrorStatusExt = "ReadComment";
104     return Standard_False;
105   }
106
107   myErrorStatus = theDriver.EndReadCommentSection();
108   if (myErrorStatus != Storage_VSOk)
109   {
110     myErrorStatusExt = "EndReadCommentSection";
111     return Standard_False;
112   }
113
114   return Standard_True;
115 }
116
117 Standard_Boolean StdStorage_HeaderData::Write(Storage_BaseDriver& theDriver)
118 {
119   // Check driver open mode
120   if (theDriver.OpenMode() != Storage_VSWrite
121     && theDriver.OpenMode() != Storage_VSReadWrite)
122   {
123     myErrorStatus = Storage_VSModeError;
124     myErrorStatusExt = "OpenMode";
125     return Standard_False;
126   }
127
128   // Write info section
129   myErrorStatus = theDriver.BeginWriteInfoSection();
130   if (myErrorStatus != Storage_VSOk)
131   {
132     myErrorStatusExt = "BeginWriteInfoSection";
133     return Standard_False;
134   }
135
136   try
137   {
138     OCC_CATCH_SIGNALS
139     theDriver.WriteInfo(myNBObj,
140                         myStorageVersion,
141                         myDate,
142                         mySchemaName,
143                         mySchemaVersion,
144                         myApplicationName,
145                         myApplicationVersion,
146                         myDataType,
147                         myUserInfo);
148   }
149   catch (Storage_StreamTypeMismatchError)
150   {
151     myErrorStatus = Storage_VSTypeMismatch;
152     myErrorStatusExt = "WriteInfo";
153     return Standard_False;
154   }
155   catch (Storage_StreamExtCharParityError)
156   {
157     myErrorStatus = Storage_VSExtCharParityError;
158     myErrorStatusExt = "WriteInfo";
159     return Standard_False;
160   }
161
162   myErrorStatus = theDriver.EndWriteInfoSection();
163   if (myErrorStatus != Storage_VSOk)
164   {
165     myErrorStatusExt = "EndWriteInfoSection";
166     return Standard_False;
167   }
168
169   // Write comment section
170   myErrorStatus = theDriver.BeginWriteCommentSection();
171   if (myErrorStatus != Storage_VSOk)
172   {
173     myErrorStatusExt = "BeginWriteCommentSection";
174     return Standard_False;
175   }
176
177   try
178   {
179     OCC_CATCH_SIGNALS
180     theDriver.WriteComment(myComments);
181   }
182   catch (Storage_StreamTypeMismatchError)
183   {
184     myErrorStatus = Storage_VSTypeMismatch;
185     myErrorStatusExt = "WriteComment";
186     return Standard_False;
187   }
188   catch (Storage_StreamExtCharParityError)
189   {
190     myErrorStatus = Storage_VSExtCharParityError;
191     myErrorStatusExt = "WriteComment";
192     return Standard_False;
193   }
194
195   myErrorStatus = theDriver.EndWriteCommentSection();
196   if (myErrorStatus != Storage_VSOk)
197   {
198     myErrorStatusExt = "EndWriteCommentSection";
199     return Standard_False;
200   }
201
202   return Standard_True;
203 }
204
205 TCollection_AsciiString StdStorage_HeaderData::CreationDate() const
206 {
207   return myDate;
208 }
209
210 void StdStorage_HeaderData::SetSchemaVersion(const TCollection_AsciiString& aVersion)
211 {
212   mySchemaVersion = aVersion;
213 }
214
215 TCollection_AsciiString StdStorage_HeaderData::SchemaVersion() const
216 {
217   return mySchemaVersion;
218 }
219
220 void StdStorage_HeaderData::SetSchemaName(const TCollection_AsciiString& aSchemaName)
221 {
222   mySchemaName = aSchemaName;
223 }
224
225 void StdStorage_HeaderData::SetApplicationVersion(const TCollection_AsciiString& aVersion)
226 {
227   myApplicationVersion = aVersion;
228 }
229
230 TCollection_AsciiString StdStorage_HeaderData::ApplicationVersion() const
231 {
232   return myApplicationVersion;
233 }
234
235 void StdStorage_HeaderData::SetApplicationName(const TCollection_ExtendedString& aName)
236 {
237   myApplicationName = aName;
238 }
239
240 TCollection_ExtendedString StdStorage_HeaderData::ApplicationName() const
241 {
242   return myApplicationName;
243 }
244
245 void StdStorage_HeaderData::SetDataType(const TCollection_ExtendedString& aName)
246 {
247   myDataType = aName;
248 }
249
250 TCollection_ExtendedString StdStorage_HeaderData::DataType() const
251 {
252   return myDataType;
253 }
254
255 void StdStorage_HeaderData::AddToUserInfo(const TCollection_AsciiString& theUserInfo)
256 {
257   myUserInfo.Append(theUserInfo);
258 }
259
260 const TColStd_SequenceOfAsciiString& StdStorage_HeaderData::UserInfo() const
261 {
262   return myUserInfo;
263 }
264
265 void StdStorage_HeaderData::AddToComments(const TCollection_ExtendedString& aComments)
266 {
267   myComments.Append(aComments);
268 }
269
270 const TColStd_SequenceOfExtendedString& StdStorage_HeaderData::Comments() const
271 {
272   return myComments;
273 }
274
275 Standard_Integer StdStorage_HeaderData::NumberOfObjects() const
276 {
277   return myNBObj;
278 }
279
280 void StdStorage_HeaderData::SetNumberOfObjects(const Standard_Integer anObjectNumber)
281 {
282   myNBObj = anObjectNumber;
283 }
284
285 void StdStorage_HeaderData::SetStorageVersion(const TCollection_AsciiString& v)
286 {
287   myStorageVersion = v;
288 }
289
290 void StdStorage_HeaderData::SetCreationDate(const TCollection_AsciiString& d)
291 {
292   myDate = d;
293 }
294
295 TCollection_AsciiString StdStorage_HeaderData::StorageVersion() const
296 {
297   return myStorageVersion;
298 }
299
300 Storage_Error StdStorage_HeaderData::ErrorStatus() const
301 {
302   return myErrorStatus;
303 }
304
305 void StdStorage_HeaderData::SetErrorStatus(const Storage_Error anError)
306 {
307   myErrorStatus = anError;
308 }
309
310 TCollection_AsciiString StdStorage_HeaderData::ErrorStatusExtension() const
311 {
312   return myErrorStatusExt;
313 }
314
315 void StdStorage_HeaderData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
316 {
317   myErrorStatusExt = anErrorExt;
318 }
319
320 void StdStorage_HeaderData::ClearErrorStatus()
321 {
322   myErrorStatus = Storage_VSOk;
323   myErrorStatusExt.Clear();
324 }