|
|
|||
File indexing completed on 2026-09-25 09:20:07
0001 // Created on: 1993-11-03 0002 // Created by: Christian CAILLET 0003 // Copyright (c) 1993-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _IFSelect_SessionFile_HeaderFile 0018 #define _IFSelect_SessionFile_HeaderFile 0019 0020 #include <NCollection_DataMap.hxx> 0021 #include <Standard.hxx> 0022 #include <Standard_DefineAlloc.hxx> 0023 #include <Standard_Handle.hxx> 0024 0025 #include <Standard_Integer.hxx> 0026 #include <NCollection_Array1.hxx> 0027 #include <NCollection_HArray1.hxx> 0028 #include <TCollection_AsciiString.hxx> 0029 #include <NCollection_Sequence.hxx> 0030 #include <Standard_CString.hxx> 0031 0032 class IFSelect_WorkSession; 0033 class Standard_Transient; 0034 0035 //! A SessionFile is intended to manage access between a 0036 //! WorkSession and an Ascii Form, to be considered as a Dump. 0037 //! It allows to write the File from the WorkSession, and later 0038 //! read the File to the WorkSession, by keeping required 0039 //! descriptions (such as dependences). 0040 //! 0041 //! The produced File is under an Ascii Form, then it may be 0042 //! easily consulted. 0043 //! It is possible to cumulate reading of several Files. But in 0044 //! case of Names conflict, the newer Names are forgottens. 0045 //! 0046 //! The Dump supports the description of XSTEP functionalities 0047 //! (Sharing an Interface File, with Selections, Dispatches, 0048 //! Modifiers ...) but does not refer to the Interface File 0049 //! which is currently loaded. 0050 //! 0051 //! SessionFile works with a library of SessionDumper type objects 0052 //! 0053 //! The File is Produced as follows : 0054 //! SessionFile produces all general Information (such as Int and 0055 //! Text Parameters, Types and Inputs of Selections, Dispatches, 0056 //! Modifiers ...) and calls the SessionDumpers to produce all 0057 //! the particular Data : creation arguments, parameters to be set 0058 //! It is Read in the same terms : 0059 //! SessionFile reads and interprets all general Information, 0060 //! and calls the SessionDumpers to recognize Types and for a 0061 //! recognized Type create the corresponding Object with its 0062 //! particular parameters as they were written. 0063 //! The best way to work is to have one SessionDumper for each 0064 //! consistent set of classes (e.g. a package). 0065 class IFSelect_SessionFile 0066 { 0067 public: 0068 DEFINE_STANDARD_ALLOC 0069 0070 //! Creates a SessionFile, ready to read Files in order to load 0071 //! them into a given WorkSession. 0072 //! The following Read Operations must then be called. 0073 //! It is also possible to perform a Write, which produces a 0074 //! complete File of all the content of the WorkSession. 0075 Standard_EXPORT IFSelect_SessionFile(const occ::handle<IFSelect_WorkSession>& WS); 0076 0077 //! Creates a SessionFile which Writes the content of a WorkSession 0078 //! to a File (directly calls Write) 0079 //! Then, IsDone acknowledges on the result of the Operation. 0080 //! But such a SessionFile may not Read a File to a WorkSession. 0081 Standard_EXPORT IFSelect_SessionFile(const occ::handle<IFSelect_WorkSession>& WS, 0082 const char* const filename); 0083 0084 //! Clears the lines recorded whatever for writing or for reading 0085 Standard_EXPORT void ClearLines(); 0086 0087 //! Returns the count of recorded lines 0088 Standard_EXPORT int NbLines() const; 0089 0090 //! Returns a line given its rank in the list of recorded lines 0091 Standard_EXPORT const TCollection_AsciiString& Line(const int num) const; 0092 0093 //! Adds a line to the list of recorded lines 0094 Standard_EXPORT void AddLine(const char* const line); 0095 0096 //! Removes the last line. Can be called recursively. 0097 //! Does nothing if the list is empty 0098 Standard_EXPORT void RemoveLastLine(); 0099 0100 //! Writes the recorded lines to a file named <name> then clears 0101 //! the list of lines. 0102 //! Returns False (with no clearing) if the file could not be 0103 //! created 0104 Standard_EXPORT bool WriteFile(const char* const name); 0105 0106 //! Reads the recorded lines from a file named <name>, after 0107 //! having cleared the list (stops if RecognizeFile fails) 0108 //! Returns False (with no clearing) if the file could not be read 0109 Standard_EXPORT bool ReadFile(const char* const name); 0110 0111 //! Recognizes the header line. returns True if OK, False else 0112 Standard_EXPORT bool RecognizeFile(const char* const headerline); 0113 0114 //! Performs a Write Operation from a WorkSession to a File 0115 //! i.e. calls WriteSession then WriteEnd, and WriteFile 0116 //! Returned Value is : 0 for OK, -1 File could not be created, 0117 //! >0 Error during Write (see WriteSession) 0118 //! IsDone can be called too (will return True for OK) 0119 Standard_EXPORT int Write(const char* const filename); 0120 0121 //! Performs a Read Operation from a file to a WorkSession 0122 //! i.e. calls ReadFile, then ReadSession and ReadEnd 0123 //! Returned Value is : 0 for OK, -1 File could not be opened, 0124 //! >0 Error during Read (see WriteSession) 0125 //! IsDone can be called too (will return True for OK) 0126 Standard_EXPORT int Read(const char* const filename); 0127 0128 //! Prepares the Write operation from a WorkSession (IFSelect) to 0129 //! a File, i.e. fills the list of lines (the file itself remains 0130 //! to be written; or NbLines/Line may be called) 0131 //! Important Remark : this excludes the reading of the last line, 0132 //! which is performed by WriteEnd 0133 //! Returns 0 if OK, status > 0 in case of error 0134 Standard_EXPORT int WriteSession(); 0135 0136 //! Writes the trailing line. It is separate from WriteSession, 0137 //! in order to allow to redefine WriteSession without touching 0138 //! WriteEnd (WriteSession defines the body of the file) 0139 //! WriteEnd fills the list of lines. Returns a status of error, 0140 //! 0 if OK, >0 else 0141 Standard_EXPORT int WriteEnd(); 0142 0143 //! Writes a line to the File. If <follow> is given, it is added 0144 //! at the following of the line. '\n' must be added for the end. 0145 Standard_EXPORT void WriteLine(const char* const line, const char follow = 0); 0146 0147 //! Writes the Parameters own to each type of Item. Uses the 0148 //! Library of SessionDumpers 0149 //! Returns True if Done, False if <item> could not be treated 0150 //! (hence it remains written with no Own Parameter) 0151 Standard_EXPORT bool WriteOwn(const occ::handle<Standard_Transient>& item); 0152 0153 //! Performs a Read Operation from a File to a WorkSession, i.e. 0154 //! reads the list of line (which must have already been loaded, 0155 //! by ReadFile or by calls to AddLine) 0156 //! Important Remark : this excludes the reading of the last line, 0157 //! which is performed by ReadEnd 0158 //! Returns 0 for OK, >0 status for Read Error (not a suitable 0159 //! File, or WorkSession given as Immutable at Creation Time) 0160 //! IsDone can be called too (will return True for OK) 0161 Standard_EXPORT int ReadSession(); 0162 0163 //! Reads the end of a file (its last line). Returns 0 if OK, 0164 //! status >0 in case of error (not a suitable end line). 0165 Standard_EXPORT int ReadEnd(); 0166 0167 //! Reads a Line and splits it into a set of alphanumeric items, 0168 //! which can then be queried by NbParams/ParamValue ... 0169 Standard_EXPORT bool ReadLine(); 0170 0171 //! Internal routine which processes a line into words 0172 //! and prepares its exploration 0173 Standard_EXPORT void SplitLine(const char* const line); 0174 0175 //! Tries to Read an Item, by calling the Library of Dumpers 0176 //! Sets the list of parameters of the line to be read from the 0177 //! first own one 0178 Standard_EXPORT bool ReadOwn(occ::handle<Standard_Transient>& item); 0179 0180 //! Adds an Item to the WorkSession, taken as Name the first 0181 //! item of the read Line. If this Name is not a Name but a Number 0182 //! or if this Name is already recorded in the WorkSession, it 0183 //! adds the Item but with no Name. Then the Name is recorded 0184 //! in order to be used by the method ItemValue 0185 //! <active> commands to make <item> active or not in the session 0186 Standard_EXPORT void AddItem(const occ::handle<Standard_Transient>& item, 0187 const bool active = true); 0188 0189 //! Returns True if the last Read or Write operation has been correctly performed. 0190 //! Else returns False. 0191 Standard_EXPORT bool IsDone() const; 0192 0193 //! Returns the WorkSession on which a SessionFile works. 0194 //! Remark that it is returned as Immutable. 0195 Standard_EXPORT occ::handle<IFSelect_WorkSession> WorkSession() const; 0196 0197 //! At beginning of writing an Item, writes its basics : 0198 //! - either its name in the session if it has one 0199 //! - or its relative number of item in the file, else (preceded by a '_') 0200 //! - then, its Dynamic Type (in the sense of cdl : pk_class) 0201 //! This basic description can be followed by the parameters 0202 //! which are used in the definition of the item. 0203 Standard_EXPORT void NewItem(const int ident, const occ::handle<Standard_Transient>& par); 0204 0205 //! Sets Parameters to be sent as Own if <mode> is True (their 0206 //! Name or Number or Void Mark or Text Value is preceded by a 0207 //! Column sign ':') else they are sent normally 0208 //! Hence, the Own Parameter are clearly identified in the File 0209 Standard_EXPORT void SetOwn(const bool mode); 0210 0211 //! During a Write action, commands to send a Void Parameter 0212 //! i.e. a Parameter which is present but undefined 0213 //! Its form will be the dollar sign : $ 0214 Standard_EXPORT void SendVoid(); 0215 0216 //! During a Write action, commands to send the identification of 0217 //! a Parameter : if it is Null (undefined) it is send as Void ($) 0218 //! if it is Named in the WorkSession, its Name is sent preceded 0219 //! by ':', else a relative Ident Number is sent preceded by '#' 0220 //! (relative to the present Write, i.e. starting at one, without 0221 //! skip, and counted part from Named Items) 0222 Standard_EXPORT void SendItem(const occ::handle<Standard_Transient>& par); 0223 0224 //! During a Write action, commands to send a Text without 0225 //! interpretation. It will be sent as well 0226 Standard_EXPORT void SendText(const char* const text); 0227 0228 //! Sets the rank of Last General Parameter to a new value. It is 0229 //! followed by the Fist Own Parameter of the item. 0230 //! Used by SessionFile after reading general parameters. 0231 Standard_EXPORT void SetLastGeneral(const int lastgen); 0232 0233 //! During a Read operation, SessionFile processes sequentially the Items to read. 0234 //! For each one, it gives access to the list 0235 //! of its Parameters : they were defined by calls to 0236 //! SendVoid/SendParam/SendText during Writing the File. 0237 //! NbParams returns the count of Parameters for the line 0238 //! currently read. 0239 Standard_EXPORT int NbParams() const; 0240 0241 //! Returns True if a Parameter, given its rank in the Own List 0242 //! (see NbOwnParams), is Void. Returns also True if <num> is 0243 //! out of range (undefined parameters) 0244 Standard_EXPORT bool IsVoid(const int num) const; 0245 0246 //! Returns True if a Parameter, in the Own List (see NbOwnParams) 0247 //! is a Text (between "..."). Else it is an Item (Parameter, 0248 //! Selection, Dispatch ...), which can be Void. 0249 Standard_EXPORT bool IsText(const int num) const; 0250 0251 //! Returns a Parameter (alphanumeric item of a line) as it 0252 //! has been read 0253 Standard_EXPORT const TCollection_AsciiString& ParamValue(const int num) const; 0254 0255 //! Returns the content of a Text Parameter (without the quotes). 0256 //! Returns an empty string if the Parameter is not a Text. 0257 Standard_EXPORT TCollection_AsciiString TextValue(const int num) const; 0258 0259 //! Returns a Parameter as an Item. Returns a Null Handle if the 0260 //! Parameter is a Text, or if it is defined as Void 0261 Standard_EXPORT occ::handle<Standard_Transient> ItemValue(const int num) const; 0262 0263 //! Specific Destructor (closes the File if not yet done) 0264 Standard_EXPORT void Destroy(); 0265 0266 ~IFSelect_SessionFile() { Destroy(); } 0267 0268 protected: 0269 occ::handle<IFSelect_WorkSession> thesess; 0270 occ::handle<NCollection_HArray1<int>> thenums; 0271 NCollection_DataMap<TCollection_AsciiString, int> thenames; 0272 int thenl; 0273 NCollection_Sequence<TCollection_AsciiString> theline; 0274 0275 private: 0276 bool themode; 0277 NCollection_Sequence<TCollection_AsciiString> thelist; 0278 TCollection_AsciiString thebuff; 0279 int thelastgen; 0280 bool thedone; 0281 bool theownflag; 0282 int thenewnum; 0283 }; 0284 0285 #endif // _IFSelect_SessionFile_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|