0030493: Draw, ViewerTest - minor improvement of vdisplay command
[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 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 // 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 #include <Storage_BaseDriver.hxx>
30 #include <Storage_Error.hxx>
31 #include <Storage_OpenMode.hxx>
32 #include <Storage_Position.hxx>
33
34 class Storage_StreamTypeMismatchError;
35 class Storage_StreamFormatError;
36 class Storage_StreamWriteError;
37 class Storage_StreamExtCharParityError;
38
39 #include <TColStd_SequenceOfExtendedString.hxx>
40
41 class DDF_IOStream  : public Storage_BaseDriver {
42
43 public:
44
45  // Methods PUBLIC
46  // 
47 DDF_IOStream();
48   Storage_Error Open(const TCollection_AsciiString& aName,const Storage_OpenMode aMode) ;
49   Storage_Error Open(istream* anIStream) ;
50   Storage_Error Open(ostream* anOStream) ;
51   Standard_Boolean IsEnd() ;
52   Storage_Position Tell() { return -1; }
53 static  Storage_Error IsGoodFileType(istream* anIStream) ;
54   Storage_Error BeginWriteInfoSection() ;
55   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) ;
56   Storage_Error EndWriteInfoSection() ;
57   Storage_Error BeginReadInfoSection() ;
58   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) ;
59   void ReadCompleteInfo (Standard_IStream& theIStream, Handle(Storage_Data)& theData);
60   Storage_Error EndReadInfoSection() ;
61   Storage_Error BeginWriteCommentSection() ;
62   void WriteComment(const TColStd_SequenceOfExtendedString& userComments) ;
63   Storage_Error EndWriteCommentSection() ;
64   Storage_Error BeginReadCommentSection() ;
65   void ReadComment(TColStd_SequenceOfExtendedString& userComments) ;
66   Storage_Error EndReadCommentSection() ;
67   Storage_Error BeginWriteTypeSection() ;
68   void SetTypeSectionSize(const Standard_Integer aSize) ;
69   void WriteTypeInformations(const Standard_Integer typeNum,const TCollection_AsciiString& typeName) ;
70   Storage_Error EndWriteTypeSection() ;
71   Storage_Error BeginReadTypeSection() ;
72   Standard_Integer TypeSectionSize() ;
73   void ReadTypeInformations(Standard_Integer& typeNum,TCollection_AsciiString& typeName) ;
74   Storage_Error EndReadTypeSection() ;
75   Storage_Error BeginWriteRootSection() ;
76   void SetRootSectionSize(const Standard_Integer aSize) ;
77   void WriteRoot(const TCollection_AsciiString& rootName,const Standard_Integer aRef,const TCollection_AsciiString& aType) ;
78   Storage_Error EndWriteRootSection() ;
79   Storage_Error BeginReadRootSection() ;
80   Standard_Integer RootSectionSize() ;
81   void ReadRoot(TCollection_AsciiString& rootName,Standard_Integer& aRef,TCollection_AsciiString& aType) ;
82   Storage_Error EndReadRootSection() ;
83   Storage_Error BeginWriteRefSection() ;
84   void SetRefSectionSize(const Standard_Integer aSize) ;
85   void WriteReferenceType(const Standard_Integer reference,const Standard_Integer typeNum) ;
86   Storage_Error EndWriteRefSection() ;
87   Storage_Error BeginReadRefSection() ;
88   Standard_Integer RefSectionSize() ;
89   void ReadReferenceType(Standard_Integer& reference,Standard_Integer& typeNum) ;
90   Storage_Error EndReadRefSection() ;
91   Storage_Error BeginWriteDataSection() ;
92   void WritePersistentObjectHeader(const Standard_Integer aRef,const Standard_Integer aType) ;
93   void BeginWritePersistentObjectData() ;
94   void BeginWriteObjectData() ;
95   void EndWriteObjectData() ;
96   void EndWritePersistentObjectData() ;
97   Storage_Error EndWriteDataSection() ;
98   Storage_Error BeginReadDataSection() ;
99   void ReadPersistentObjectHeader(Standard_Integer& aRef,Standard_Integer& aType) ;
100   void BeginReadPersistentObjectData() ;
101   void BeginReadObjectData() ;
102   void EndReadObjectData() ;
103   void EndReadPersistentObjectData() ;
104   Storage_Error EndReadDataSection() ;
105   void SkipObject() ;
106   Storage_BaseDriver& PutReference(const Standard_Integer aValue) ;
107   Storage_BaseDriver& PutCharacter(const Standard_Character aValue) ;
108   Storage_BaseDriver& operator <<(const Standard_Character aValue) 
109 {
110   return PutCharacter(aValue);
111 }
112
113   Storage_BaseDriver& PutExtCharacter(const Standard_ExtCharacter aValue) ;
114   Storage_BaseDriver& operator <<(const Standard_ExtCharacter aValue) 
115 {
116   return PutExtCharacter(aValue);
117 }
118
119   Storage_BaseDriver& PutInteger(const Standard_Integer aValue) ;
120   Storage_BaseDriver& operator <<(const Standard_Integer aValue) 
121 {
122   return PutInteger(aValue);
123 }
124
125   Storage_BaseDriver& PutBoolean(const Standard_Boolean aValue) ;
126   Storage_BaseDriver& operator <<(const Standard_Boolean aValue) 
127 {
128   return PutBoolean(aValue);
129 }
130
131   Storage_BaseDriver& PutReal(const Standard_Real aValue) ;
132   Storage_BaseDriver& operator <<(const Standard_Real aValue) 
133 {
134   return PutReal(aValue);
135 }
136
137   Storage_BaseDriver& PutShortReal(const Standard_ShortReal aValue) ;
138   Storage_BaseDriver& operator <<(const Standard_ShortReal aValue) 
139 {
140   return PutShortReal(aValue);
141 }
142
143   Storage_BaseDriver& GetReference(Standard_Integer& aValue) ;
144   Storage_BaseDriver& GetCharacter(Standard_Character& aValue) ;
145   Storage_BaseDriver& operator >>(Standard_Character& aValue) 
146 {
147   return GetCharacter(aValue);
148 }
149
150   Storage_BaseDriver& GetExtCharacter(Standard_ExtCharacter& aValue) ;
151   Storage_BaseDriver& operator >>(Standard_ExtCharacter& aValue) 
152 {
153   return GetExtCharacter(aValue);
154 }
155
156   Storage_BaseDriver& GetInteger(Standard_Integer& aValue) ;
157   Storage_BaseDriver& operator >>(Standard_Integer& aValue) 
158 {
159   return GetInteger(aValue);
160 }
161
162   Storage_BaseDriver& GetBoolean(Standard_Boolean& aValue) ;
163   Storage_BaseDriver& operator >>(Standard_Boolean& aValue) 
164 {
165   return GetBoolean(aValue);
166 }
167
168   Storage_BaseDriver& GetReal(Standard_Real& aValue) ;
169   Storage_BaseDriver& operator >>(Standard_Real& aValue) 
170 {
171   return GetReal(aValue);
172 }
173
174   Storage_BaseDriver& GetShortReal(Standard_ShortReal& aValue) ;
175   Storage_BaseDriver& operator >>(Standard_ShortReal& aValue) 
176 {
177   return GetShortReal(aValue);
178 }
179
180   Storage_Error Close() ;
181   void Destroy() ;
182 ~DDF_IOStream()
183 {
184   Destroy();
185 }
186
187
188
189
190
191
192 protected:
193
194  // Methods PROTECTED
195  // 
196   void ReadLine(TCollection_AsciiString& buffer) ;
197   void ReadWord(TCollection_AsciiString& buffer) ;
198   void ReadExtendedLine(TCollection_ExtendedString& buffer) ;
199   void WriteExtendedLine(const TCollection_ExtendedString& buffer) ;
200   void ReadChar(TCollection_AsciiString& buffer,const Standard_Integer rsize) ;
201   void ReadString(TCollection_AsciiString& buffer) ;
202   void FlushEndOfLine() ;
203   Storage_Error FindTag(const Standard_CString aTag) ;
204
205
206  // Fields PROTECTED
207  //
208
209
210 private: 
211
212  // Methods PRIVATE
213  // 
214 static Standard_CString MagicNumber() ;
215
216
217  // Fields PRIVATE
218  //
219 //FSD_FStream myStream;
220 istream* myIStream;
221 ostream* myOStream;
222
223
224 };
225
226 // other inline functions and methods (like "C++: function call" methods)
227 //
228 #endif