42cf5bc1 |
1 | // Created on: 1993-11-03 |
2 | // Created by: Christian CAILLET |
3 | // Copyright (c) 1993-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 _IFSelect_SessionFile_HeaderFile |
18 | #define _IFSelect_SessionFile_HeaderFile |
19 | |
997e128f |
20 | #include <NCollection_DataMap.hxx> |
42cf5bc1 |
21 | #include <Standard.hxx> |
22 | #include <Standard_DefineAlloc.hxx> |
23 | #include <Standard_Handle.hxx> |
24 | |
25 | #include <Standard_Boolean.hxx> |
26 | #include <TColStd_HArray1OfInteger.hxx> |
27 | #include <TColStd_SequenceOfAsciiString.hxx> |
28 | #include <Standard_Integer.hxx> |
29 | #include <TCollection_AsciiString.hxx> |
30 | #include <Standard_CString.hxx> |
31 | #include <Standard_Character.hxx> |
997e128f |
32 | |
42cf5bc1 |
33 | class IFSelect_WorkSession; |
42cf5bc1 |
34 | class TCollection_AsciiString; |
35 | class Standard_Transient; |
36 | |
42cf5bc1 |
37 | //! A SessionFile is intended to manage access between a |
38 | //! WorkSession and an Ascii Form, to be considered as a Dump. |
39 | //! It allows to write the File from the WorkSession, and later |
40 | //! read the File to the WorkSession, by keeping required |
41 | //! descriptions (such as dependances). |
42 | //! |
43 | //! The produced File is under an Ascii Form, then it may be |
44 | //! easily consulted. |
45 | //! It is possible to cumulate reading of several Files. But in |
46 | //! case of Names conflict, the newer Names are forgottens. |
47 | //! |
0177fe26 |
48 | //! The Dump supports the description of XSTEP functionalities |
42cf5bc1 |
49 | //! (Sharing an Interface File, with Selections, Dispatches, |
50 | //! Modifiers ...) but does not refer to the Interface File |
51 | //! which is currently loaded. |
52 | //! |
53 | //! SessionFile works with a library of SessionDumper type objects |
54 | //! |
55 | //! The File is Produced as follows : |
21c7c457 |
56 | //! SessionFile produces all general Information (such as Int and |
42cf5bc1 |
57 | //! Text Parameters, Types and Inputs of Selections, Dispatches, |
58 | //! Modifiers ...) and calls the SessionDumpers to produce all |
59 | //! the particular Data : creation arguments, parameters to be set |
60 | //! It is Read in the same terms : |
21c7c457 |
61 | //! SessionFile reads and interprets all general Information, |
42cf5bc1 |
62 | //! and calls the SessionDumpers to recognize Types and for a |
63 | //! recognized Type create the corresponding Object with its |
64 | //! particular parameters as they were written. |
65 | //! The best way to work is to have one SessionDumper for each |
66 | //! consistent set of classes (e.g. a package). |
67 | class IFSelect_SessionFile |
68 | { |
69 | public: |
70 | |
71 | DEFINE_STANDARD_ALLOC |
72 | |
42cf5bc1 |
73 | //! Creates a SessionFile, ready to read Files in order to load |
74 | //! them into a given WorkSession. |
75 | //! The following Read Operations must then be called. |
76 | //! It is also possible to perform a Write, which produces a |
77 | //! complete File of all the content of the WorkSession. |
78 | Standard_EXPORT IFSelect_SessionFile(const Handle(IFSelect_WorkSession)& WS); |
79 | |
80 | //! Creates a SessionFile which Writes the content of a WorkSession |
81 | //! to a File (directly calls Write) |
82 | //! Then, IsDone aknowledges on the result of the Operation. |
83 | //! But such a SessionFile may not Read a File to a WorkSession. |
84 | Standard_EXPORT IFSelect_SessionFile(const Handle(IFSelect_WorkSession)& WS, const Standard_CString filename); |
85 | |
86 | //! Clears the lines recorded whatever for writing or for reading |
87 | Standard_EXPORT void ClearLines(); |
88 | |
89 | //! Returns the count of recorded lines |
90 | Standard_EXPORT Standard_Integer NbLines() const; |
91 | |
92 | //! Returns a line given its rank in the list of recorded lines |
93 | Standard_EXPORT const TCollection_AsciiString& Line (const Standard_Integer num) const; |
94 | |
95 | //! Adds a line to the list of recorded lines |
96 | Standard_EXPORT void AddLine (const Standard_CString line); |
97 | |
98 | //! Removes the last line. Can be called recursively. |
99 | //! Does nothing if the list is empty |
100 | Standard_EXPORT void RemoveLastLine(); |
101 | |
102 | //! Writes the recorded lines to a file named <name> then clears |
103 | //! the list of lines. |
104 | //! Returns False (with no clearing) if the file could not be |
105 | //! created |
106 | Standard_EXPORT Standard_Boolean WriteFile (const Standard_CString name); |
107 | |
108 | //! Reads the recorded lines from a file named <name>, after |
109 | //! having cleared the list (stops if RecognizeFile fails) |
110 | //! Returns False (with no clearing) if the file could not be read |
111 | Standard_EXPORT Standard_Boolean ReadFile (const Standard_CString name); |
112 | |
113 | //! Recognizes the header line. returns True if OK, False else |
114 | Standard_EXPORT Standard_Boolean RecognizeFile (const Standard_CString headerline); |
115 | |
116 | //! Performs a Write Operation from a WorkSession to a File |
117 | //! i.e. calls WriteSession then WriteEnd, and WriteFile |
118 | //! Returned Value is : 0 for OK, -1 File could not be created, |
119 | //! >0 Error during Write (see WriteSession) |
120 | //! IsDone can be called too (will return True for OK) |
121 | Standard_EXPORT Standard_Integer Write (const Standard_CString filename); |
122 | |
123 | //! Performs a Read Operation from a file to a WorkSession |
124 | //! i.e. calls ReadFile, then ReadSession and ReadEnd |
125 | //! Returned Value is : 0 for OK, -1 File could not be opened, |
126 | //! >0 Error during Read (see WriteSession) |
127 | //! IsDone can be called too (will return True for OK) |
128 | Standard_EXPORT Standard_Integer Read (const Standard_CString filename); |
129 | |
130 | //! Prepares the Write operation from a WorkSession (IFSelect) to |
131 | //! a File, i.e. fills the list of lines (the file itself remains |
132 | //! to be written; or NbLines/Line may be called) |
133 | //! Important Remark : this excludes the reading of the last line, |
134 | //! which is performed by WriteEnd |
135 | //! Returns 0 if OK, status > 0 in case of error |
136 | Standard_EXPORT Standard_Integer WriteSession(); |
137 | |
138 | //! Writes the trailing line. It is separate from WriteSession, |
139 | //! in order to allow to redefine WriteSession without touching |
140 | //! WriteEnd (WriteSession defines the body of the file) |
141 | //! WriteEnd fills the list of lines. Returns a status of error, |
142 | //! 0 if OK, >0 else |
143 | Standard_EXPORT Standard_Integer WriteEnd(); |
144 | |
145 | //! Writes a line to the File. If <follow> is given, it is added |
146 | //! at the following of the line. '\n' must be added for the end. |
147 | Standard_EXPORT void WriteLine (const Standard_CString line, const Standard_Character follow = 0); |
148 | |
149 | //! Writes the Parameters own to each type of Item. Uses the |
150 | //! Library of SessionDumpers |
151 | //! Returns True if Done, False if <item> could not be treated |
152 | //! (hence it remains written with no Own Parameter) |
153 | Standard_EXPORT Standard_Boolean WriteOwn (const Handle(Standard_Transient)& item); |
154 | |
155 | //! Performs a Read Operation from a File to a WorkSession, i.e. |
156 | //! reads the list of line (which must have already been loaded, |
157 | //! by ReadFile or by calls to AddLine) |
158 | //! Important Remark : this excludes the reading of the last line, |
159 | //! which is performed by ReadEnd |
160 | //! Returns 0 for OK, >0 status for Read Error (not a suitable |
161 | //! File, or WorkSession given as Immutable at Creation Time) |
162 | //! IsDone can be called too (will return True for OK) |
163 | Standard_EXPORT Standard_Integer ReadSession(); |
164 | |
165 | //! Reads the end of a file (its last line). Returns 0 if OK, |
166 | //! status >0 in case of error (not a suitable end line). |
167 | Standard_EXPORT Standard_Integer ReadEnd(); |
168 | |
169 | //! Reads a Line and splits it into a set of alphanumeric items, |
170 | //! which can then be queried by NbParams/ParamValue ... |
171 | Standard_EXPORT Standard_Boolean ReadLine(); |
172 | |
173 | //! Internal routine which processes a line into words |
174 | //! and prepares its exploration |
175 | Standard_EXPORT void SplitLine (const Standard_CString line); |
176 | |
177 | //! Tries to Read an Item, by calling the Library of Dumpers |
178 | //! Sets the list of parameters of the line to be read from the |
179 | //! first own one |
180 | Standard_EXPORT Standard_Boolean ReadOwn (Handle(Standard_Transient)& item); |
181 | |
182 | //! Adds an Item to the WorkSession, taken as Name the first |
183 | //! item of the read Line. If this Name is not a Name but a Number |
184 | //! or if this Name is already recorded in the WorkSession, it |
185 | //! adds the Item but with no Name. Then the Name is recorded |
186 | //! in order to be used by the method ItemValue |
187 | //! <active> commands to make <item> active or not in the session |
188 | Standard_EXPORT void AddItem (const Handle(Standard_Transient)& item, const Standard_Boolean active = Standard_True); |
0177fe26 |
189 | |
190 | //! Returns True if the last Read or Write operation has been correctly performed. |
191 | //! Else returns False. |
42cf5bc1 |
192 | Standard_EXPORT Standard_Boolean IsDone() const; |
0177fe26 |
193 | |
42cf5bc1 |
194 | //! Returns the WorkSession on which a SessionFile works. |
195 | //! Remark that it is returned as Immutable. |
196 | Standard_EXPORT Handle(IFSelect_WorkSession) WorkSession() const; |
0177fe26 |
197 | |
42cf5bc1 |
198 | //! At beginning of writing an Item, writes its basics : |
199 | //! - either its name in the session if it has one |
0177fe26 |
200 | //! - or its relative number of item in the file, else (preceded by a '_') |
42cf5bc1 |
201 | //! - then, its Dynamic Type (in the sense of cdl : pk_class) |
202 | //! This basic description can be followed by the parameters |
203 | //! which are used in the definition of the item. |
204 | Standard_EXPORT void NewItem (const Standard_Integer ident, const Handle(Standard_Transient)& par); |
0177fe26 |
205 | |
42cf5bc1 |
206 | //! Sets Parameters to be sent as Own if <mode> is True (their |
0177fe26 |
207 | //! Name or Number or Void Mark or Text Value is preceded by a |
42cf5bc1 |
208 | //! Column sign ':') else they are sent normally |
209 | //! Hence, the Own Parameter are clearly identified in the File |
210 | Standard_EXPORT void SetOwn (const Standard_Boolean mode); |
211 | |
212 | //! During a Write action, commands to send a Void Parameter |
213 | //! i.e. a Parameter which is present but undefined |
214 | //! Its form will be the dollar sign : $ |
215 | Standard_EXPORT void SendVoid(); |
0177fe26 |
216 | |
42cf5bc1 |
217 | //! During a Write action, commands to send the identification of |
218 | //! a Parameter : if it is Null (undefined) it is send as Void ($) |
0177fe26 |
219 | //! if it is Named in the WorkSession, its Name is sent preceded |
220 | //! by ':', else a relative Ident Number is sent preceded by '#' |
42cf5bc1 |
221 | //! (relative to the present Write, i.e. starting at one, without |
222 | //! skip, and counted part from Named Items) |
223 | Standard_EXPORT void SendItem (const Handle(Standard_Transient)& par); |
0177fe26 |
224 | |
42cf5bc1 |
225 | //! During a Write action, commands to send a Text without |
226 | //! interpretation. It will be sent as well |
227 | Standard_EXPORT void SendText (const Standard_CString text); |
228 | |
229 | //! Sets the rank of Last General Parameter to a new value. It is |
230 | //! followed by the Fist Own Parameter of the item. |
231 | //! Used by SessionFile after reading general parameters. |
232 | Standard_EXPORT void SetLastGeneral (const Standard_Integer lastgen); |
0177fe26 |
233 | |
234 | //! During a Read operation, SessionFile processes sequentially the Items to read. |
235 | //! For each one, it gives access to the list |
42cf5bc1 |
236 | //! of its Parameters : they were defined by calls to |
237 | //! SendVoid/SendParam/SendText during Writing the File. |
238 | //! NbParams returns the count of Parameters for the line |
239 | //! currently read. |
240 | Standard_EXPORT Standard_Integer NbParams() const; |
0177fe26 |
241 | |
42cf5bc1 |
242 | //! Returns True if a Parameter, given its rank in the Own List |
243 | //! (see NbOwnParams), is Void. Returns also True if <num> is |
244 | //! out of range (undefined parameters) |
245 | Standard_EXPORT Standard_Boolean IsVoid (const Standard_Integer num) const; |
246 | |
247 | //! Returns True if a Parameter, in the Own List (see NbOwnParams) |
248 | //! is a Text (between "..."). Else it is an Item (Parameter, |
249 | //! Selection, Dispatch ...), which can be Void. |
250 | Standard_EXPORT Standard_Boolean IsText (const Standard_Integer num) const; |
251 | |
252 | //! Returns a Parameter (alphanumeric item of a line) as it |
253 | //! has been read |
254 | Standard_EXPORT const TCollection_AsciiString& ParamValue (const Standard_Integer num) const; |
255 | |
256 | //! Returns the content of a Text Parameter (without the quotes). |
257 | //! Returns an empty string if the Parameter is not a Text. |
258 | Standard_EXPORT TCollection_AsciiString TextValue (const Standard_Integer num) const; |
259 | |
260 | //! Returns a Parameter as an Item. Returns a Null Handle if the |
261 | //! Parameter is a Text, or if it is defined as Void |
262 | Standard_EXPORT Handle(Standard_Transient) ItemValue (const Standard_Integer num) const; |
263 | |
264 | //! Specific Destructor (closes the File if not yet done) |
265 | Standard_EXPORT void Destroy(); |
266 | ~IFSelect_SessionFile() |
267 | { |
268 | Destroy(); |
269 | } |
270 | |
42cf5bc1 |
271 | protected: |
272 | |
42cf5bc1 |
273 | Handle(IFSelect_WorkSession) thesess; |
274 | Handle(TColStd_HArray1OfInteger) thenums; |
997e128f |
275 | NCollection_DataMap<TCollection_AsciiString, Standard_Integer> thenames; |
42cf5bc1 |
276 | Standard_Integer thenl; |
277 | TColStd_SequenceOfAsciiString theline; |
278 | |
42cf5bc1 |
279 | private: |
280 | |
42cf5bc1 |
281 | Standard_Boolean themode; |
282 | TColStd_SequenceOfAsciiString thelist; |
283 | TCollection_AsciiString thebuff; |
284 | Standard_Integer thelastgen; |
285 | Standard_Boolean thedone; |
286 | Standard_Boolean theownflag; |
287 | Standard_Integer thenewnum; |
288 | |
42cf5bc1 |
289 | }; |
290 | |
42cf5bc1 |
291 | #endif // _IFSelect_SessionFile_HeaderFile |