8f093b024803cd75a2dd9c3a15a946dade5eddfb
[occt.git] / src / FSD / FSD_File.hxx
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_File_HeaderFile
18 #define _FSD_File_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <FSD_FStream.hxx>
25 #include <Storage_BaseDriver.hxx>
26 #include <Storage_Error.hxx>
27 #include <Storage_OpenMode.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <Storage_Position.hxx>
30 #include <Standard_Integer.hxx>
31 #include <TColStd_SequenceOfAsciiString.hxx>
32 #include <TColStd_SequenceOfExtendedString.hxx>
33 #include <Standard_Character.hxx>
34 #include <Standard_ExtCharacter.hxx>
35 #include <Standard_Real.hxx>
36 #include <Standard_ShortReal.hxx>
37 #include <Standard_Size.hxx>
38 #include <Standard_CString.hxx>
39 class Storage_StreamTypeMismatchError;
40 class Storage_StreamFormatError;
41 class Storage_StreamWriteError;
42 class Storage_StreamExtCharParityError;
43 class TCollection_AsciiString;
44 class TCollection_ExtendedString;
45 class Storage_BaseDriver;
46
47
48
49 //! A general driver which defines as a file, the
50 //! physical container for data to be stored or retrieved.
51 class FSD_File  : public Storage_BaseDriver
52 {
53 public:
54
55   DEFINE_STANDARD_ALLOC
56
57   
58
59   //! Constructs a driver defining as a file, the physical
60   //! container for data to be stored or retrieved.
61   //! Use the function Open to give the name of the driven file.
62   Standard_EXPORT FSD_File();
63   
64
65   //! Assigns as aName the name of the file to be
66   //! driven by this driver. aMode precises if the file is
67   //! opened in read or write mode.
68   //! The function returns Storage_VSOk if the file
69   //! is opened correctly, or any other value of the
70   //! Storage_Error enumeration which specifies the problem encountered.
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
259   //! Closes the file driven by this driver. This file was
260   //! opened by the last call to the function Open.
261   //! The function returns Storage_VSOk if the
262   //! closure is correctly done, or any other value of
263   //! the Storage_Error enumeration which specifies the problem encountered.
264   Standard_EXPORT Storage_Error Close();
265   
266   Standard_EXPORT void Destroy();
267 ~FSD_File()
268 {
269   Destroy();
270 }
271
272
273
274
275 protected:
276
277   
278   //! read from the current position to the end of line.
279   Standard_EXPORT void ReadLine (TCollection_AsciiString& buffer);
280   
281   //! read from the current position to the next white space or end of line.
282   Standard_EXPORT void ReadWord (TCollection_AsciiString& buffer);
283   
284   //! read extended chars (unicode) from the current position to the end of line.
285   Standard_EXPORT void ReadExtendedLine (TCollection_ExtendedString& buffer);
286   
287   //! write from the current position to the end of line.
288   Standard_EXPORT void WriteExtendedLine (const TCollection_ExtendedString& buffer);
289   
290   //! read <rsize> character from the current position.
291   Standard_EXPORT void ReadChar (TCollection_AsciiString& buffer, const Standard_Size rsize);
292   
293   //! read from the first none space character position to the end of line.
294   Standard_EXPORT void ReadString (TCollection_AsciiString& buffer);
295   
296   Standard_EXPORT void FlushEndOfLine();
297   
298   Standard_EXPORT Storage_Error FindTag (const Standard_CString aTag);
299
300 private:
301   
302   static Standard_CString MagicNumber();
303
304 private:
305
306   FSD_FStream myStream;
307 };
308
309 #endif // _FSD_File_HeaderFile