0024428: Implementation of LGPL license
[occt.git] / src / DDF / DDF_IOStream.hxx
1 // Created on: 1997-08-22
2 // Created by: DAUTRY Philippe
3 // Copyright (c) 1997-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
9 // under the terms of the GNU Lesser General Public 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 // This file has been written using FSD_File.hxx as template.
18 // This is a specific adaptation for Draw use (save & restore commands).
19 // It is not sure at all this code is portable on any other plateform than
20 // SUN OS. Don't use it anywhere else.
21 // Thanks for comprehension. (22 august 97)
22
23
24 #ifndef DDF_IOStream_HeaderFile
25 #define DDF_IOStream_HeaderFile
26
27 #include <stdio.h>
28
29 #ifndef _Storage_BaseDriver_HeaderFile
30 #include <Storage_BaseDriver.hxx>
31 #endif
32 #ifndef _Storage_Error_HeaderFile
33 #include <Storage_Error.hxx>
34 #endif
35 #ifndef _Storage_OpenMode_HeaderFile
36 #include <Storage_OpenMode.hxx>
37 #endif
38 #ifndef _Standard_Boolean_HeaderFile
39 #include <Standard_Boolean.hxx>
40 #endif
41 #ifndef _Standard_Integer_HeaderFile
42 #include <Standard_Integer.hxx>
43 #endif
44 #ifndef _Standard_Character_HeaderFile
45 #include <Standard_Character.hxx>
46 #endif
47 #ifndef _Standard_ExtCharacter_HeaderFile
48 #include <Standard_ExtCharacter.hxx>
49 #endif
50 #ifndef _Standard_Real_HeaderFile
51 #include <Standard_Real.hxx>
52 #endif
53 #ifndef _Standard_ShortReal_HeaderFile
54 #include <Standard_ShortReal.hxx>
55 #endif
56 #ifndef _Standard_CString_HeaderFile
57 #include <Standard_CString.hxx>
58 #endif
59 #include <Storage_Position.hxx>
60
61 class Storage_StreamTypeMismatchError;
62 class Storage_StreamFormatError;
63 class Storage_StreamWriteError;
64 class Storage_StreamExtCharParityError;
65
66 class TColStd_SequenceOfExtendedString;
67
68 #ifndef Standard_EXPORT
69 #ifdef WNT
70 #define Standard_EXPORT __declspec(dllexport)
71 #else
72 #define Standard_EXPORT
73 #endif
74 #endif
75 #ifdef WNT
76 #pragma warning (disable : 4275)
77 #endif
78
79 class Standard_EXPORT DDF_IOStream  : public Storage_BaseDriver {
80
81 public:
82
83  // Methods PUBLIC
84  // 
85 DDF_IOStream();
86   Storage_Error Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode) ;
87   Storage_Error Open(istream* anIStream) ;
88   Storage_Error Open(ostream* anOStream) ;
89   Standard_Boolean IsEnd() ;
90   Storage_Position Tell() { return -1; }
91 static  Storage_Error IsGoodFileType(istream* anIStream) ;
92   Storage_Error BeginWriteInfoSection() ;
93   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) ;
94   Storage_Error EndWriteInfoSection() ;
95   Storage_Error BeginReadInfoSection() ;
96   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) ;
97   Storage_Error EndReadInfoSection() ;
98   Storage_Error BeginWriteCommentSection() ;
99   void WriteComment(const TColStd_SequenceOfExtendedString& userComments) ;
100   Storage_Error EndWriteCommentSection() ;
101   Storage_Error BeginReadCommentSection() ;
102   void ReadComment(TColStd_SequenceOfExtendedString& userComments) ;
103   Storage_Error EndReadCommentSection() ;
104   Storage_Error BeginWriteTypeSection() ;
105   void SetTypeSectionSize(const Standard_Integer aSize) ;
106   void WriteTypeInformations(const Standard_Integer typeNum,const TCollection_AsciiString& typeName) ;
107   Storage_Error EndWriteTypeSection() ;
108   Storage_Error BeginReadTypeSection() ;
109   Standard_Integer TypeSectionSize() ;
110   void ReadTypeInformations(Standard_Integer& typeNum,TCollection_AsciiString& typeName) ;
111   Storage_Error EndReadTypeSection() ;
112   Storage_Error BeginWriteRootSection() ;
113   void SetRootSectionSize(const Standard_Integer aSize) ;
114   void WriteRoot(const TCollection_AsciiString& rootName,const Standard_Integer aRef,const TCollection_AsciiString& aType) ;
115   Storage_Error EndWriteRootSection() ;
116   Storage_Error BeginReadRootSection() ;
117   Standard_Integer RootSectionSize() ;
118   void ReadRoot(TCollection_AsciiString& rootName,Standard_Integer& aRef,TCollection_AsciiString& aType) ;
119   Storage_Error EndReadRootSection() ;
120   Storage_Error BeginWriteRefSection() ;
121   void SetRefSectionSize(const Standard_Integer aSize) ;
122   void WriteReferenceType(const Standard_Integer reference,const Standard_Integer typeNum) ;
123   Storage_Error EndWriteRefSection() ;
124   Storage_Error BeginReadRefSection() ;
125   Standard_Integer RefSectionSize() ;
126   void ReadReferenceType(Standard_Integer& reference,Standard_Integer& typeNum) ;
127   Storage_Error EndReadRefSection() ;
128   Storage_Error BeginWriteDataSection() ;
129   void WritePersistentObjectHeader(const Standard_Integer aRef,const Standard_Integer aType) ;
130   void BeginWritePersistentObjectData() ;
131   void BeginWriteObjectData() ;
132   void EndWriteObjectData() ;
133   void EndWritePersistentObjectData() ;
134   Storage_Error EndWriteDataSection() ;
135   Storage_Error BeginReadDataSection() ;
136   void ReadPersistentObjectHeader(Standard_Integer& aRef,Standard_Integer& aType) ;
137   void BeginReadPersistentObjectData() ;
138   void BeginReadObjectData() ;
139   void EndReadObjectData() ;
140   void EndReadPersistentObjectData() ;
141   Storage_Error EndReadDataSection() ;
142   void SkipObject() ;
143   Storage_BaseDriver& PutReference(const Standard_Integer aValue) ;
144   Storage_BaseDriver& PutCharacter(const Standard_Character aValue) ;
145   Storage_BaseDriver& operator <<(const Standard_Character aValue) 
146 {
147   return PutCharacter(aValue);
148 }
149
150   Storage_BaseDriver& PutExtCharacter(const Standard_ExtCharacter aValue) ;
151   Storage_BaseDriver& operator <<(const Standard_ExtCharacter aValue) 
152 {
153   return PutExtCharacter(aValue);
154 }
155
156   Storage_BaseDriver& PutInteger(const Standard_Integer aValue) ;
157   Storage_BaseDriver& operator <<(const Standard_Integer aValue) 
158 {
159   return PutInteger(aValue);
160 }
161
162   Storage_BaseDriver& PutBoolean(const Standard_Boolean aValue) ;
163   Storage_BaseDriver& operator <<(const Standard_Boolean aValue) 
164 {
165   return PutBoolean(aValue);
166 }
167
168   Storage_BaseDriver& PutReal(const Standard_Real aValue) ;
169   Storage_BaseDriver& operator <<(const Standard_Real aValue) 
170 {
171   return PutReal(aValue);
172 }
173
174   Storage_BaseDriver& PutShortReal(const Standard_ShortReal aValue) ;
175   Storage_BaseDriver& operator <<(const Standard_ShortReal aValue) 
176 {
177   return PutShortReal(aValue);
178 }
179
180   Storage_BaseDriver& GetReference(Standard_Integer& aValue) ;
181   Storage_BaseDriver& GetCharacter(Standard_Character& aValue) ;
182   Storage_BaseDriver& operator >>(Standard_Character& aValue) 
183 {
184   return GetCharacter(aValue);
185 }
186
187   Storage_BaseDriver& GetExtCharacter(Standard_ExtCharacter& aValue) ;
188   Storage_BaseDriver& operator >>(Standard_ExtCharacter& aValue) 
189 {
190   return GetExtCharacter(aValue);
191 }
192
193   Storage_BaseDriver& GetInteger(Standard_Integer& aValue) ;
194   Storage_BaseDriver& operator >>(Standard_Integer& aValue) 
195 {
196   return GetInteger(aValue);
197 }
198
199   Storage_BaseDriver& GetBoolean(Standard_Boolean& aValue) ;
200   Storage_BaseDriver& operator >>(Standard_Boolean& aValue) 
201 {
202   return GetBoolean(aValue);
203 }
204
205   Storage_BaseDriver& GetReal(Standard_Real& aValue) ;
206   Storage_BaseDriver& operator >>(Standard_Real& aValue) 
207 {
208   return GetReal(aValue);
209 }
210
211   Storage_BaseDriver& GetShortReal(Standard_ShortReal& aValue) ;
212   Storage_BaseDriver& operator >>(Standard_ShortReal& aValue) 
213 {
214   return GetShortReal(aValue);
215 }
216
217   Storage_Error Close() ;
218   void Destroy() ;
219 ~DDF_IOStream()
220 {
221   Destroy();
222 }
223
224
225
226
227
228
229 protected:
230
231  // Methods PROTECTED
232  // 
233   void ReadLine(TCollection_AsciiString& buffer) ;
234   void ReadWord(TCollection_AsciiString& buffer) ;
235   void ReadExtendedLine(TCollection_ExtendedString& buffer) ;
236   void WriteExtendedLine(const TCollection_ExtendedString& buffer) ;
237   void ReadChar(TCollection_AsciiString& buffer,const Standard_Integer rsize) ;
238   void ReadString(TCollection_AsciiString& buffer) ;
239   void FlushEndOfLine() ;
240   Storage_Error FindTag(const Standard_CString aTag) ;
241
242
243  // Fields PROTECTED
244  //
245
246
247 private: 
248
249  // Methods PRIVATE
250  // 
251 static const Standard_CString MagicNumber() ;
252
253
254  // Fields PRIVATE
255  //
256 //FSD_FStream myStream;
257 istream* myIStream;
258 ostream* myOStream;
259
260
261 };
262
263 #ifdef WNT
264 #pragma warning (default : 4275)
265 #endif
266
267
268 // other inline functions and methods (like "C++: function call" methods)
269 //
270 #endif