]> OCCT Git - occt.git/blame - src/FSD/FSD_File.hxx
0026229: Add the possibility in OCAF to open/save a document from/to a stream object
[occt.git] / src / FSD / FSD_File.hxx
CommitLineData
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_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>
39class Storage_StreamTypeMismatchError;
40class Storage_StreamFormatError;
41class Storage_StreamWriteError;
42class Storage_StreamExtCharParityError;
43class TCollection_AsciiString;
44class TCollection_ExtendedString;
45class 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.
51class FSD_File : public Storage_BaseDriver
52{
53public:
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);
4ff92abe 89
90 Standard_EXPORT void ReadCompleteInfo (Standard_IStream& theIStream, Handle(Storage_Data)& theData);
42cf5bc1 91
92 Standard_EXPORT Storage_Error EndReadInfoSection();
93
94 Standard_EXPORT Storage_Error BeginWriteCommentSection();
95
96 Standard_EXPORT void WriteComment (const TColStd_SequenceOfExtendedString& userComments);
97
98 Standard_EXPORT Storage_Error EndWriteCommentSection();
99
100 Standard_EXPORT Storage_Error BeginReadCommentSection();
101
102 Standard_EXPORT void ReadComment (TColStd_SequenceOfExtendedString& userComments);
103
104 Standard_EXPORT Storage_Error EndReadCommentSection();
105
106 Standard_EXPORT Storage_Error BeginWriteTypeSection();
107
108 Standard_EXPORT void SetTypeSectionSize (const Standard_Integer aSize);
109
110 Standard_EXPORT void WriteTypeInformations (const Standard_Integer typeNum, const TCollection_AsciiString& typeName);
111
112 Standard_EXPORT Storage_Error EndWriteTypeSection();
113
114 Standard_EXPORT Storage_Error BeginReadTypeSection();
115
116 Standard_EXPORT Standard_Integer TypeSectionSize();
117
118 Standard_EXPORT void ReadTypeInformations (Standard_Integer& typeNum, TCollection_AsciiString& typeName);
119
120 Standard_EXPORT Storage_Error EndReadTypeSection();
121
122 Standard_EXPORT Storage_Error BeginWriteRootSection();
123
124 Standard_EXPORT void SetRootSectionSize (const Standard_Integer aSize);
125
126 Standard_EXPORT void WriteRoot (const TCollection_AsciiString& rootName, const Standard_Integer aRef, const TCollection_AsciiString& aType);
127
128 Standard_EXPORT Storage_Error EndWriteRootSection();
129
130 Standard_EXPORT Storage_Error BeginReadRootSection();
131
132 Standard_EXPORT Standard_Integer RootSectionSize();
133
134 Standard_EXPORT void ReadRoot (TCollection_AsciiString& rootName, Standard_Integer& aRef, TCollection_AsciiString& aType);
135
136 Standard_EXPORT Storage_Error EndReadRootSection();
137
138 Standard_EXPORT Storage_Error BeginWriteRefSection();
139
140 Standard_EXPORT void SetRefSectionSize (const Standard_Integer aSize);
141
142 Standard_EXPORT void WriteReferenceType (const Standard_Integer reference, const Standard_Integer typeNum);
143
144 Standard_EXPORT Storage_Error EndWriteRefSection();
145
146 Standard_EXPORT Storage_Error BeginReadRefSection();
147
148 Standard_EXPORT Standard_Integer RefSectionSize();
149
150 Standard_EXPORT void ReadReferenceType (Standard_Integer& reference, Standard_Integer& typeNum);
151
152 Standard_EXPORT Storage_Error EndReadRefSection();
153
154 Standard_EXPORT Storage_Error BeginWriteDataSection();
155
156 Standard_EXPORT void WritePersistentObjectHeader (const Standard_Integer aRef, const Standard_Integer aType);
157
158 Standard_EXPORT void BeginWritePersistentObjectData();
159
160 Standard_EXPORT void BeginWriteObjectData();
161
162 Standard_EXPORT void EndWriteObjectData();
163
164 Standard_EXPORT void EndWritePersistentObjectData();
165
166 Standard_EXPORT Storage_Error EndWriteDataSection();
167
168 Standard_EXPORT Storage_Error BeginReadDataSection();
169
170 Standard_EXPORT void ReadPersistentObjectHeader (Standard_Integer& aRef, Standard_Integer& aType);
171
172 Standard_EXPORT void BeginReadPersistentObjectData();
173
174 Standard_EXPORT void BeginReadObjectData();
175
176 Standard_EXPORT void EndReadObjectData();
177
178 Standard_EXPORT void EndReadPersistentObjectData();
179
180 Standard_EXPORT Storage_Error EndReadDataSection();
181
182 Standard_EXPORT void SkipObject();
183
184 Standard_EXPORT Storage_BaseDriver& PutReference (const Standard_Integer aValue);
185
186 Standard_EXPORT Storage_BaseDriver& PutCharacter (const Standard_Character aValue);
187Storage_BaseDriver& operator << (const Standard_Character aValue)
188{
189 return PutCharacter(aValue);
190}
191
192 Standard_EXPORT Storage_BaseDriver& PutExtCharacter (const Standard_ExtCharacter aValue);
193Storage_BaseDriver& operator << (const Standard_ExtCharacter aValue)
194{
195 return PutExtCharacter(aValue);
196}
197
198 Standard_EXPORT Storage_BaseDriver& PutInteger (const Standard_Integer aValue);
199Storage_BaseDriver& operator << (const Standard_Integer aValue)
200{
201 return PutInteger(aValue);
202}
203
204 Standard_EXPORT Storage_BaseDriver& PutBoolean (const Standard_Boolean aValue);
205Storage_BaseDriver& operator << (const Standard_Boolean aValue)
206{
207 return PutBoolean(aValue);
208}
209
210 Standard_EXPORT Storage_BaseDriver& PutReal (const Standard_Real aValue);
211Storage_BaseDriver& operator << (const Standard_Real aValue)
212{
213 return PutReal(aValue);
214}
215
216 Standard_EXPORT Storage_BaseDriver& PutShortReal (const Standard_ShortReal aValue);
217Storage_BaseDriver& operator << (const Standard_ShortReal aValue)
218{
219 return PutShortReal(aValue);
220}
221
222 Standard_EXPORT Storage_BaseDriver& GetReference (Standard_Integer& aValue);
223
224 Standard_EXPORT Storage_BaseDriver& GetCharacter (Standard_Character& aValue);
225Storage_BaseDriver& operator >> (Standard_Character& aValue)
226{
227 return GetCharacter(aValue);
228}
229
230 Standard_EXPORT Storage_BaseDriver& GetExtCharacter (Standard_ExtCharacter& aValue);
231Storage_BaseDriver& operator >> (Standard_ExtCharacter& aValue)
232{
233 return GetExtCharacter(aValue);
234}
235
236 Standard_EXPORT Storage_BaseDriver& GetInteger (Standard_Integer& aValue);
237Storage_BaseDriver& operator >> (Standard_Integer& aValue)
238{
239 return GetInteger(aValue);
240}
241
242 Standard_EXPORT Storage_BaseDriver& GetBoolean (Standard_Boolean& aValue);
243Storage_BaseDriver& operator >> (Standard_Boolean& aValue)
244{
245 return GetBoolean(aValue);
246}
247
248 Standard_EXPORT Storage_BaseDriver& GetReal (Standard_Real& aValue);
249Storage_BaseDriver& operator >> (Standard_Real& aValue)
250{
251 return GetReal(aValue);
252}
253
254 Standard_EXPORT Storage_BaseDriver& GetShortReal (Standard_ShortReal& aValue);
255Storage_BaseDriver& operator >> (Standard_ShortReal& aValue)
256{
257 return GetShortReal(aValue);
258}
259
260
261 //! Closes the file driven by this driver. This file was
262 //! opened by the last call to the function Open.
263 //! The function returns Storage_VSOk if the
264 //! closure is correctly done, or any other value of
265 //! the Storage_Error enumeration which specifies the problem encountered.
266 Standard_EXPORT Storage_Error Close();
267
268 Standard_EXPORT void Destroy();
269~FSD_File()
270{
271 Destroy();
272}
273
4ff92abe 274 Standard_EXPORT static Standard_CString MagicNumber();
42cf5bc1 275
276
277
278protected:
279
280
281 //! read from the current position to the end of line.
282 Standard_EXPORT void ReadLine (TCollection_AsciiString& buffer);
283
284 //! read from the current position to the next white space or end of line.
285 Standard_EXPORT void ReadWord (TCollection_AsciiString& buffer);
286
287 //! read extended chars (unicode) from the current position to the end of line.
288 Standard_EXPORT void ReadExtendedLine (TCollection_ExtendedString& buffer);
289
290 //! write from the current position to the end of line.
291 Standard_EXPORT void WriteExtendedLine (const TCollection_ExtendedString& buffer);
292
293 //! read <rsize> character from the current position.
294 Standard_EXPORT void ReadChar (TCollection_AsciiString& buffer, const Standard_Size rsize);
295
296 //! read from the first none space character position to the end of line.
297 Standard_EXPORT void ReadString (TCollection_AsciiString& buffer);
298
299 Standard_EXPORT void FlushEndOfLine();
300
301 Standard_EXPORT Storage_Error FindTag (const Standard_CString aTag);
302
42cf5bc1 303private:
42cf5bc1 304
42cf5bc1 305
306
307 FSD_FStream myStream;
42cf5bc1 308};
309
42cf5bc1 310#endif // _FSD_File_HeaderFile