1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Standard_ErrorHandler.hxx>
17 #include <Storage_HeaderData.hxx>
18 #include <Storage_BaseDriver.hxx>
19 #include <Storage_StreamTypeMismatchError.hxx>
20 #include <Storage_StreamExtCharParityError.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TCollection_ExtendedString.hxx>
23
IMPLEMENT_STANDARD_RTTIEXT(Storage_HeaderData,Standard_Transient)24 IMPLEMENT_STANDARD_RTTIEXT(Storage_HeaderData,Standard_Transient)
25
26 Storage_HeaderData::Storage_HeaderData() : myNBObj(0), myErrorStatus(Storage_VSOk)
27 {
28 }
29
Read(const Handle (Storage_BaseDriver)& theDriver)30 Standard_Boolean Storage_HeaderData::Read (const Handle(Storage_BaseDriver)& theDriver)
31 {
32 // Check driver open mode
33 if (theDriver->OpenMode() != Storage_VSRead
34 && theDriver->OpenMode() != Storage_VSReadWrite)
35 {
36 myErrorStatus = Storage_VSModeError;
37 myErrorStatusExt = "OpenMode";
38 return Standard_False;
39 }
40
41 // Read info section
42 myErrorStatus = theDriver->BeginReadInfoSection();
43 if (myErrorStatus != Storage_VSOk)
44 {
45 myErrorStatusExt = "BeginReadInfoSection";
46 return Standard_False;
47 }
48
49 {
50 try
51 {
52 OCC_CATCH_SIGNALS
53 theDriver->ReadInfo (myNBObj, myStorageVersion, myDate, mySchemaName, mySchemaVersion,
54 myApplicationName, myApplicationVersion, myDataType, myUserInfo);
55 }
56 catch (Storage_StreamTypeMismatchError const&)
57 {
58 myErrorStatus = Storage_VSTypeMismatch;
59 myErrorStatusExt = "ReadInfo";
60 return Standard_False;
61 }
62 catch (Storage_StreamExtCharParityError const&)
63 {
64 myErrorStatus = Storage_VSExtCharParityError;
65 myErrorStatusExt = "ReadInfo";
66 return Standard_False;
67 }
68 }
69
70 myErrorStatus = theDriver->EndReadInfoSection();
71 if (myErrorStatus != Storage_VSOk)
72 {
73 myErrorStatusExt = "EndReadInfoSection";
74 return Standard_False;
75 }
76
77 // Read comment section
78 myErrorStatus = theDriver->BeginReadCommentSection();
79 if (myErrorStatus != Storage_VSOk)
80 {
81 myErrorStatusExt = "BeginReadCommentSection";
82 return Standard_False;
83 }
84
85 {
86 try
87 {
88 OCC_CATCH_SIGNALS
89 theDriver->ReadComment (myComments);
90 }
91 catch (Storage_StreamTypeMismatchError const&)
92 {
93 myErrorStatus = Storage_VSTypeMismatch;
94 myErrorStatusExt = "ReadComment";
95 return Standard_False;
96 }
97 catch (Storage_StreamExtCharParityError const&)
98 {
99 myErrorStatus = Storage_VSExtCharParityError;
100 myErrorStatusExt = "ReadComment";
101 return Standard_False;
102 }
103 }
104
105 myErrorStatus = theDriver->EndReadCommentSection();
106 if (myErrorStatus != Storage_VSOk)
107 {
108 myErrorStatusExt = "EndReadCommentSection";
109 return Standard_False;
110 }
111
112 return Standard_True;
113 }
114
CreationDate() const115 TCollection_AsciiString Storage_HeaderData::CreationDate() const
116 {
117 return myDate;
118 }
119
SetSchemaVersion(const TCollection_AsciiString & aVersion)120 void Storage_HeaderData::SetSchemaVersion(const TCollection_AsciiString& aVersion)
121 {
122 mySchemaVersion = aVersion;
123 }
124
SchemaVersion() const125 TCollection_AsciiString Storage_HeaderData::SchemaVersion() const
126 {
127 return mySchemaVersion;
128 }
129
SetSchemaName(const TCollection_AsciiString & aSchemaName)130 void Storage_HeaderData::SetSchemaName(const TCollection_AsciiString& aSchemaName)
131 {
132 mySchemaName = aSchemaName;
133 }
134
SchemaName() const135 TCollection_AsciiString Storage_HeaderData::SchemaName() const
136 {
137 return mySchemaName;
138 }
139
SetApplicationVersion(const TCollection_AsciiString & aVersion)140 void Storage_HeaderData::SetApplicationVersion(const TCollection_AsciiString& aVersion)
141 {
142 myApplicationVersion = aVersion;
143 }
144
ApplicationVersion() const145 TCollection_AsciiString Storage_HeaderData::ApplicationVersion() const
146 {
147 return myApplicationVersion;
148 }
149
SetApplicationName(const TCollection_ExtendedString & aName)150 void Storage_HeaderData::SetApplicationName(const TCollection_ExtendedString& aName)
151 {
152 myApplicationName = aName;
153 }
154
ApplicationName() const155 TCollection_ExtendedString Storage_HeaderData::ApplicationName() const
156 {
157 return myApplicationName;
158 }
159
SetDataType(const TCollection_ExtendedString & aName)160 void Storage_HeaderData::SetDataType(const TCollection_ExtendedString& aName)
161 {
162 myDataType = aName;
163 }
164
DataType() const165 TCollection_ExtendedString Storage_HeaderData::DataType() const
166 {
167 return myDataType;
168 }
169
AddToUserInfo(const TCollection_AsciiString & theUserInfo)170 void Storage_HeaderData::AddToUserInfo(const TCollection_AsciiString& theUserInfo)
171 {
172 myUserInfo.Append(theUserInfo);
173 }
174
UserInfo() const175 const TColStd_SequenceOfAsciiString& Storage_HeaderData::UserInfo() const
176 {
177 return myUserInfo;
178 }
179
AddToComments(const TCollection_ExtendedString & aComments)180 void Storage_HeaderData::AddToComments(const TCollection_ExtendedString& aComments)
181 {
182 myComments.Append(aComments);
183 }
184
Comments() const185 const TColStd_SequenceOfExtendedString& Storage_HeaderData::Comments() const
186 {
187 return myComments;
188 }
189
NumberOfObjects() const190 Standard_Integer Storage_HeaderData::NumberOfObjects() const
191 {
192 return myNBObj;
193 }
194
SetNumberOfObjects(const Standard_Integer anObjectNumber)195 void Storage_HeaderData::SetNumberOfObjects(const Standard_Integer anObjectNumber)
196 {
197 myNBObj = anObjectNumber;
198 }
199
SetStorageVersion(const TCollection_AsciiString & v)200 void Storage_HeaderData::SetStorageVersion(const TCollection_AsciiString& v)
201 {
202 myStorageVersion = v;
203 }
204
SetCreationDate(const TCollection_AsciiString & d)205 void Storage_HeaderData::SetCreationDate(const TCollection_AsciiString& d)
206 {
207 myDate = d;
208 }
209
StorageVersion() const210 TCollection_AsciiString Storage_HeaderData::StorageVersion() const
211 {
212 return myStorageVersion;
213 }
214
ErrorStatus() const215 Storage_Error Storage_HeaderData::ErrorStatus() const
216 {
217 return myErrorStatus;
218 }
219
SetErrorStatus(const Storage_Error anError)220 void Storage_HeaderData::SetErrorStatus(const Storage_Error anError)
221 {
222 myErrorStatus = anError;
223 }
224
ErrorStatusExtension() const225 TCollection_AsciiString Storage_HeaderData::ErrorStatusExtension() const
226 {
227 return myErrorStatusExt;
228 }
229
SetErrorStatusExtension(const TCollection_AsciiString & anErrorExt)230 void Storage_HeaderData::SetErrorStatusExtension(const TCollection_AsciiString& anErrorExt)
231 {
232 myErrorStatusExt = anErrorExt;
233 }
234
ClearErrorStatus()235 void Storage_HeaderData::ClearErrorStatus()
236 {
237 myErrorStatus = Storage_VSOk;
238 myErrorStatusExt.Clear();
239 }
240
241