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