42cf5bc1 |
1 | // Created on: 1996-11-29 |
2 | // Created by: Christophe LEYNADIER |
3 | // Copyright (c) 1996-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _FSD_BinaryFile_HeaderFile |
18 | #define _FSD_BinaryFile_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <FSD_BStream.hxx> |
25 | #include <FSD_FileHeader.hxx> |
26 | #include <Storage_BaseDriver.hxx> |
27 | #include <Storage_Error.hxx> |
28 | #include <Storage_OpenMode.hxx> |
29 | #include <Standard_Boolean.hxx> |
30 | #include <Storage_Position.hxx> |
31 | #include <Standard_Integer.hxx> |
32 | #include <TColStd_SequenceOfAsciiString.hxx> |
33 | #include <TColStd_SequenceOfExtendedString.hxx> |
34 | #include <Standard_Character.hxx> |
35 | #include <Standard_ExtCharacter.hxx> |
36 | #include <Standard_Real.hxx> |
37 | #include <Standard_ShortReal.hxx> |
38 | #include <Standard_CString.hxx> |
39 | #include <Standard_Size.hxx> |
40 | class Storage_StreamTypeMismatchError; |
41 | class Storage_StreamFormatError; |
42 | class Storage_StreamWriteError; |
43 | class Storage_StreamExtCharParityError; |
44 | class TCollection_AsciiString; |
45 | class TCollection_ExtendedString; |
46 | class Storage_BaseDriver; |
47 | |
48 | |
10a4116e |
49 | // Macro that tells if bytes must be reversed when read/write |
50 | // data to/from a binary file. It is needed to provide binary file compatibility |
51 | // between little and big endian platforms. |
52 | #ifndef OCCT_BINARY_FILE_DO_INVERSE |
53 | #if defined ( SOLARIS ) || defined ( IRIX ) |
54 | // Do inverse on big endian platform |
55 | #define OCCT_BINARY_FILE_DO_INVERSE 1 |
56 | #else |
57 | #define OCCT_BINARY_FILE_DO_INVERSE 0 |
58 | #endif |
59 | #endif |
60 | |
42cf5bc1 |
61 | |
62 | class FSD_BinaryFile : public Storage_BaseDriver |
63 | { |
64 | public: |
65 | |
66 | DEFINE_STANDARD_ALLOC |
67 | |
68 | |
69 | Standard_EXPORT FSD_BinaryFile(); |
70 | |
71 | Standard_EXPORT Storage_Error Open (const TCollection_AsciiString& aName, const Storage_OpenMode aMode); |
72 | |
73 | Standard_EXPORT Standard_Boolean IsEnd(); |
74 | |
75 | //! return position in the file. Return -1 upon error. |
76 | Standard_EXPORT Storage_Position Tell(); |
77 | |
78 | Standard_EXPORT static Storage_Error IsGoodFileType (const TCollection_AsciiString& aName); |
79 | |
80 | Standard_EXPORT Storage_Error BeginWriteInfoSection(); |
81 | |
82 | Standard_EXPORT void WriteInfo (const Standard_Integer nbObj, const TCollection_AsciiString& dbVersion, const TCollection_AsciiString& date, const TCollection_AsciiString& schemaName, const TCollection_AsciiString& schemaVersion, const TCollection_ExtendedString& appName, const TCollection_AsciiString& appVersion, const TCollection_ExtendedString& objectType, const TColStd_SequenceOfAsciiString& userInfo); |
83 | |
84 | Standard_EXPORT Storage_Error EndWriteInfoSection(); |
85 | |
86 | Standard_EXPORT Storage_Error BeginReadInfoSection(); |
87 | |
88 | Standard_EXPORT void ReadInfo (Standard_Integer& nbObj, TCollection_AsciiString& dbVersion, TCollection_AsciiString& date, TCollection_AsciiString& schemaName, TCollection_AsciiString& schemaVersion, TCollection_ExtendedString& appName, TCollection_AsciiString& appVersion, TCollection_ExtendedString& objectType, TColStd_SequenceOfAsciiString& userInfo); |
89 | |
90 | Standard_EXPORT Storage_Error EndReadInfoSection(); |
91 | |
92 | Standard_EXPORT Storage_Error BeginWriteCommentSection(); |
93 | |
94 | Standard_EXPORT void WriteComment (const TColStd_SequenceOfExtendedString& userComments); |
95 | |
96 | Standard_EXPORT Storage_Error EndWriteCommentSection(); |
97 | |
98 | Standard_EXPORT Storage_Error BeginReadCommentSection(); |
99 | |
100 | Standard_EXPORT void ReadComment (TColStd_SequenceOfExtendedString& userComments); |
101 | |
102 | Standard_EXPORT Storage_Error EndReadCommentSection(); |
103 | |
104 | Standard_EXPORT Storage_Error BeginWriteTypeSection(); |
105 | |
106 | Standard_EXPORT void SetTypeSectionSize (const Standard_Integer aSize); |
107 | |
108 | Standard_EXPORT void WriteTypeInformations (const Standard_Integer typeNum, const TCollection_AsciiString& typeName); |
109 | |
110 | Standard_EXPORT Storage_Error EndWriteTypeSection(); |
111 | |
112 | Standard_EXPORT Storage_Error BeginReadTypeSection(); |
113 | |
114 | Standard_EXPORT Standard_Integer TypeSectionSize(); |
115 | |
116 | Standard_EXPORT void ReadTypeInformations (Standard_Integer& typeNum, TCollection_AsciiString& typeName); |
117 | |
118 | Standard_EXPORT Storage_Error EndReadTypeSection(); |
119 | |
120 | Standard_EXPORT Storage_Error BeginWriteRootSection(); |
121 | |
122 | Standard_EXPORT void SetRootSectionSize (const Standard_Integer aSize); |
123 | |
124 | Standard_EXPORT void WriteRoot (const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& aType); |
125 | |
126 | Standard_EXPORT Storage_Error EndWriteRootSection(); |
127 | |
128 | Standard_EXPORT Storage_Error BeginReadRootSection(); |
129 | |
130 | Standard_EXPORT Standard_Integer RootSectionSize(); |
131 | |
132 | Standard_EXPORT void ReadRoot (TCollection_AsciiString& rootName, Standard_Integer& aRef, TCollection_AsciiString& aType); |
133 | |
134 | Standard_EXPORT Storage_Error EndReadRootSection(); |
135 | |
136 | Standard_EXPORT Storage_Error BeginWriteRefSection(); |
137 | |
138 | Standard_EXPORT void SetRefSectionSize (const Standard_Integer aSize); |
139 | |
140 | Standard_EXPORT void WriteReferenceType (const Standard_Integer reference, const Standard_Integer typeNum); |
141 | |
142 | Standard_EXPORT Storage_Error EndWriteRefSection(); |
143 | |
144 | Standard_EXPORT Storage_Error BeginReadRefSection(); |
145 | |
146 | Standard_EXPORT Standard_Integer RefSectionSize(); |
147 | |
148 | Standard_EXPORT void ReadReferenceType (Standard_Integer& reference, Standard_Integer& typeNum); |
149 | |
150 | Standard_EXPORT Storage_Error EndReadRefSection(); |
151 | |
152 | Standard_EXPORT Storage_Error BeginWriteDataSection(); |
153 | |
154 | Standard_EXPORT void WritePersistentObjectHeader (const Standard_Integer aRef, const Standard_Integer aType); |
155 | |
156 | Standard_EXPORT void BeginWritePersistentObjectData(); |
157 | |
158 | Standard_EXPORT void BeginWriteObjectData(); |
159 | |
160 | Standard_EXPORT void EndWriteObjectData(); |
161 | |
162 | Standard_EXPORT void EndWritePersistentObjectData(); |
163 | |
164 | Standard_EXPORT Storage_Error EndWriteDataSection(); |
165 | |
166 | Standard_EXPORT Storage_Error BeginReadDataSection(); |
167 | |
168 | Standard_EXPORT void ReadPersistentObjectHeader (Standard_Integer& aRef, Standard_Integer& aType); |
169 | |
170 | Standard_EXPORT void BeginReadPersistentObjectData(); |
171 | |
172 | Standard_EXPORT void BeginReadObjectData(); |
173 | |
174 | Standard_EXPORT void EndReadObjectData(); |
175 | |
176 | Standard_EXPORT void EndReadPersistentObjectData(); |
177 | |
178 | Standard_EXPORT Storage_Error EndReadDataSection(); |
179 | |
180 | Standard_EXPORT void SkipObject(); |
181 | |
182 | Standard_EXPORT Storage_BaseDriver& PutReference (const Standard_Integer aValue); |
183 | |
184 | Standard_EXPORT Storage_BaseDriver& PutCharacter (const Standard_Character aValue); |
185 | Storage_BaseDriver& operator << (const Standard_Character aValue) |
186 | { |
187 | return PutCharacter(aValue); |
188 | } |
189 | |
190 | Standard_EXPORT Storage_BaseDriver& PutExtCharacter (const Standard_ExtCharacter aValue); |
191 | Storage_BaseDriver& operator << (const Standard_ExtCharacter aValue) |
192 | { |
193 | return PutExtCharacter(aValue); |
194 | } |
195 | |
196 | Standard_EXPORT Storage_BaseDriver& PutInteger (const Standard_Integer aValue); |
197 | Storage_BaseDriver& operator << (const Standard_Integer aValue) |
198 | { |
199 | return PutInteger(aValue); |
200 | } |
201 | |
202 | Standard_EXPORT Storage_BaseDriver& PutBoolean (const Standard_Boolean aValue); |
203 | Storage_BaseDriver& operator << (const Standard_Boolean aValue) |
204 | { |
205 | return PutBoolean(aValue); |
206 | } |
207 | |
208 | Standard_EXPORT Storage_BaseDriver& PutReal (const Standard_Real aValue); |
209 | Storage_BaseDriver& operator << (const Standard_Real aValue) |
210 | { |
211 | return PutReal(aValue); |
212 | } |
213 | |
214 | Standard_EXPORT Storage_BaseDriver& PutShortReal (const Standard_ShortReal aValue); |
215 | Storage_BaseDriver& operator << (const Standard_ShortReal aValue) |
216 | { |
217 | return PutShortReal(aValue); |
218 | } |
219 | |
220 | Standard_EXPORT Storage_BaseDriver& GetReference (Standard_Integer& aValue); |
221 | |
222 | Standard_EXPORT Storage_BaseDriver& GetCharacter (Standard_Character& aValue); |
223 | Storage_BaseDriver& operator >> (Standard_Character& aValue) |
224 | { |
225 | return GetCharacter(aValue); |
226 | } |
227 | |
228 | Standard_EXPORT Storage_BaseDriver& GetExtCharacter (Standard_ExtCharacter& aValue); |
229 | Storage_BaseDriver& operator >> (Standard_ExtCharacter& aValue) |
230 | { |
231 | return GetExtCharacter(aValue); |
232 | } |
233 | |
234 | Standard_EXPORT Storage_BaseDriver& GetInteger (Standard_Integer& aValue); |
235 | Storage_BaseDriver& operator >> (Standard_Integer& aValue) |
236 | { |
237 | return GetInteger(aValue); |
238 | } |
239 | |
240 | Standard_EXPORT Storage_BaseDriver& GetBoolean (Standard_Boolean& aValue); |
241 | Storage_BaseDriver& operator >> (Standard_Boolean& aValue) |
242 | { |
243 | return GetBoolean(aValue); |
244 | } |
245 | |
246 | Standard_EXPORT Storage_BaseDriver& GetReal (Standard_Real& aValue); |
247 | Storage_BaseDriver& operator >> (Standard_Real& aValue) |
248 | { |
249 | return GetReal(aValue); |
250 | } |
251 | |
252 | Standard_EXPORT Storage_BaseDriver& GetShortReal (Standard_ShortReal& aValue); |
253 | Storage_BaseDriver& operator >> (Standard_ShortReal& aValue) |
254 | { |
255 | return GetShortReal(aValue); |
256 | } |
257 | |
258 | Standard_EXPORT Storage_Error Close(); |
259 | |
260 | Standard_EXPORT void Destroy(); |
261 | ~FSD_BinaryFile() |
262 | { |
263 | Destroy(); |
264 | } |
265 | |
10a4116e |
266 | ///Inverse bytes in integer value |
267 | static Standard_Integer InverseInt(const Standard_Integer theValue) |
268 | { |
269 | return (0 | (( theValue & 0x000000ff ) << 24 ) |
270 | | (( theValue & 0x0000ff00 ) << 8 ) |
271 | | (( theValue & 0x00ff0000 ) >> 8 ) |
272 | | (( theValue >> 24 ) & 0x000000ff ) ); |
273 | } |
274 | |
275 | ///Inverse bytes in extended character value |
276 | static Standard_ExtCharacter InverseExtChar(const Standard_ExtCharacter theValue) |
277 | { |
278 | return (0 | (( theValue & 0x00ff ) << 8 ) |
279 | | (( theValue & 0xff00 ) >> 8 ) ); |
280 | } |
281 | |
282 | ///Inverse bytes in real value |
283 | Standard_EXPORT static Standard_Real InverseReal(const Standard_Real theValue); |
42cf5bc1 |
284 | |
10a4116e |
285 | ///Inverse bytes in short real value |
286 | Standard_EXPORT static Standard_ShortReal InverseShortReal(const Standard_ShortReal theValue); |
42cf5bc1 |
287 | |
10a4116e |
288 | ///Inverse bytes in size value |
289 | Standard_EXPORT static Standard_Size InverseSize(const Standard_Size theValue); |
42cf5bc1 |
290 | |
291 | protected: |
292 | |
293 | |
294 | //! read <rsize> character from the current position. |
295 | Standard_EXPORT void ReadChar (TCollection_AsciiString& buffer, const Standard_Size rsize); |
296 | |
297 | //! read string from the current position. |
298 | Standard_EXPORT void ReadString (TCollection_AsciiString& buffer); |
299 | |
300 | //! write string at the current position. |
301 | Standard_EXPORT void WriteString (const TCollection_AsciiString& buffer); |
302 | |
303 | //! read string from the current position. |
304 | Standard_EXPORT void ReadExtendedString (TCollection_ExtendedString& buffer); |
305 | |
306 | //! write string at the current position. |
307 | Standard_EXPORT void WriteExtendedString (const TCollection_ExtendedString& buffer); |
308 | |
42cf5bc1 |
309 | private: |
42cf5bc1 |
310 | |
487bf1ce |
311 | void WriteHeader(); |
42cf5bc1 |
312 | |
487bf1ce |
313 | void ReadHeader(); |
42cf5bc1 |
314 | |
487bf1ce |
315 | static Standard_CString MagicNumber(); |
42cf5bc1 |
316 | |
487bf1ce |
317 | private: |
42cf5bc1 |
318 | |
319 | FSD_BStream myStream; |
320 | FSD_FileHeader myHeader; |
42cf5bc1 |
321 | }; |
322 | |
42cf5bc1 |
323 | #endif // _FSD_BinaryFile_HeaderFile |