|
||||
File indexing completed on 2025-01-18 10:05:09
0001 /* 0002 Copyright (c) 1999-2020 OPEN CASCADE SAS 0003 0004 This file is part of Open CASCADE Technology software library. 0005 0006 This library is free software; you can redistribute it and/or modify it under 0007 the terms of the GNU Lesser General Public License version 2.1 as published 0008 by the Free Software Foundation, with special exception defined in the file 0009 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 distribution for complete text of the license and disclaimer of any warranty. 0011 0012 Alternatively, this file may be used under the terms of Open CASCADE 0013 commercial license or contractual agreement. 0014 */ 0015 0016 #ifndef _StepFile_ReadData_HeaderFile 0017 #define _StepFile_ReadData_HeaderFile 0018 0019 #include <Standard.hxx> 0020 #include <Standard_Handle.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <NCollection_IncAllocator.hxx> 0023 0024 #include <Interface_ParamType.hxx> 0025 0026 //! Provides data structures and tools to collect and store the data 0027 //! read from the STEP file. 0028 //! This class is designed to work in collaboration with STEP parser 0029 //! built using flex and bison (receives the data generated by the parser). 0030 //! 0031 //! All text (sequence of characters) received in the parsing process 0032 //! is stored in the CharacterPage, but the last received text value is 0033 //! stored in a pointer to an own page position. 0034 //! 0035 //! This value is used to initialize a new record (representation of the 0036 //! STEP entity) and its arguments (parameters of the STEP entity). 0037 //! All created arguments are stored in the ArgumentsPage, records in the RecordsPage. 0038 //! 0039 //! NOTE: 0040 //! - Arguments used in the record are pointers to the element of the page, 0041 //! - All records are pointers to the element of the record page. 0042 //! 0043 //! EXAMPLE of parsing STEP file (flex & bison): 0044 //! 0045 //! 1. Initial state: 0046 //! - Input stream to the Flex is "#123=ADVANCED_FACE('',(#124),#125,.F.)" 0047 //! - State of Flex is "INITIAL" 0048 //! - Stack of Bison states : STEP HEADER ENDSEC endhead model block 0049 //! 2. Flex rule detected "#123" - call CreateNewText("#123", 4) 0050 //! and sends a token "ENTITY". 0051 //! Now class contains "#123", as current text value. 0052 //! 3. Bison receive a token and call RecordIdent (), it 0053 //! creates a new record in the records page with "#123" identifier. 0054 //! Now current record has ident, but args and types are empty. 0055 //! 4. Flex rule detected "ADVANCED_FACE" call CreateNewText and send a token "TYPE". 0056 //! Now class contains "ADVANCED_FACE", as current text value. 0057 //! 5. Bison receive a token and call RecordType (), it 0058 //! set "ADVANCED_FACE" to the current record as a type. 0059 //! Now current record has ident and type, but args are empty. 0060 //! 6. Flex rule detected "(" send token "(". 0061 //! Now class continues to contain "ADVANCED_FACE", as current text value. 0062 //! 7. Bison receive a token and call RecordListStart (), 0063 //! it does nothing via the current state. 0064 //! Now current record is not update. 0065 //! 8. Flex rule detected ('') call CreateNewText and SetTypeArg and 0066 //! send token TEXT. 0067 //! Now class contains empty current text value. 0068 //! 9. Bison receive a token and call CreateNewArg (), it 0069 //! creates a new argument with empty text value and 'Text' type. 0070 //! Now current record has ident, type and one argument. 0071 //! 10. Flex rule detected "," call PrepareNewArg(",",1), it 0072 //! controls arguments count to protect from a skip or double creating a new argument. 0073 //! Bison does nothing and the current text value and record are not updated. 0074 //! 11. Flex rule detected "(" send token "(". 0075 //! Now class continues to contain empty current text value. 0076 //! 12. Bison receive a token and call RecordListStart (), it 0077 //! creates a new record with "$1" ident and "ADVANCED_FACE" type 0078 //! old record is the next of the new record. 0079 //! Now current record has ident, type, but args are empty. 0080 //! 13. Flex rule detected "#124" call CreateNewText("#124",4) and send token "IDENT", 0081 //! Now class contains "#124", as current text value. 0082 //! 14. Bison receive a token and call CreateNewArg (), it 0083 //! creates a new argument with "#124" text value and 'Ident' type. 0084 //! Now current record has ident, type and one argument. 0085 //! 15. Flex rule detected ")" send token ")". 0086 //! Now class continues to contain "#124", as a current text value. 0087 //! 16. Bison receive a token and call RecordNewEntity (), it 0088 //! contain record to the records page, prepare to the new record 0089 //! and get next record as a current record and set a new arg as a sub_record. 0090 //! Now current record is a old record, it has ident, type and two args. 0091 //! 17. Flex rule detected "#125" call CreateNewText, SetTypeArg and send token IDEND. 0092 //! Now class contains "#125", as a current text value. 0093 //! 18. Bison receive a token and call CreateNewArg (), it 0094 //! creates a new argument with "#125" text value and 'Ident' type. 0095 //! Now current record has ident, type and three argument. 0096 //! 19. Flex rule detected "#125" call CreateNewText, SetTypeArg and send token IDEND. 0097 //! Now class contains "#125", as a current text value. 0098 //! 20. Bison receive a token and call CreateNewArg (), it 0099 //! creates a new argument with "#125" text value and 'Ident' type. 0100 //! Now current record has ident, type and three argument. 0101 //! ... 0102 //! 0103 //! Reading of several STEP files simultaneously is possible (e.g. in multiple 0104 //! threads) provided that each file is read using its own instances of Flex, Bison 0105 //! and StepFile_ReadData tools. 0106 0107 class Interface_Check; 0108 0109 class StepFile_ReadData 0110 { 0111 public: 0112 // Standard OCCT memory allocation stuff 0113 DEFINE_STANDARD_ALLOC 0114 0115 private: 0116 0117 class Record; //!< List of records, contains all text processed by Bison 0118 class Argument; //!< List of arguments, contains all argument descriptions 0119 class Scope; //!< List of scopes pages, contains all records for external processing 0120 class ErrorsPage; //!< List of errors messages, contains all errors 0121 0122 public: 0123 0124 //! Constructs an uninitialized tool 0125 StepFile_ReadData(); 0126 0127 //! Destructor cleans allocated memory of all fields 0128 ~StepFile_ReadData() { ClearRecorder(3); } 0129 0130 //! Preperes the text value for analysis. 0131 //! It is the main tool for transferring data from flex to bison 0132 //! If characters page is full, allocates a new page. 0133 void CreateNewText(const char* theNewText, int theLenText); 0134 0135 //! Adds the current record to the list 0136 void RecordNewEntity(); 0137 0138 //! Creates a new record and sets Ident from myResText 0139 void RecordIdent(); 0140 0141 //! Starts reading of the type (entity) 0142 void RecordType(); 0143 0144 //! Prepares and saves a record or sub-record 0145 void RecordListStart(); 0146 0147 //! Prepares new arguments. 0148 //! Type and value already known. 0149 //! If arguments page is full, allocates a new page 0150 void CreateNewArg(); 0151 0152 //! Prepares error arguments, controls count of error arguments. 0153 //! If bison handles a sequence of error types, 0154 //! creates only one argument and updates text value 0155 void CreateErrorArg(); 0156 0157 //! Creates a new scope, containing the current record 0158 void AddNewScope(); 0159 0160 //! Ends the scope 0161 void FinalOfScope(); 0162 0163 //! Releases memory. 0164 //! @param theMode 0165 //! * 1 - clear pages of records and arguments 0166 //! * 2 - clear pages of characters 0167 //! * 3 - clear all data 0168 void ClearRecorder(const Standard_Integer theMode); 0169 0170 //! Returns a value of fields of current argument 0171 Standard_Boolean GetArgDescription(Interface_ParamType* theType, char** theValue); 0172 0173 //! Returns a value of all file counters 0174 void GetFileNbR(Standard_Integer* theNbHead, Standard_Integer* theNbRec, Standard_Integer* theNbPage); 0175 0176 //! Returns a value of fields of current record 0177 Standard_Boolean GetRecordDescription(char** theIdent, char** theType, int* theNbArg); 0178 0179 //! Initializes the record type with myResText 0180 void RecordTypeText(); 0181 0182 //! Skips to next record 0183 void NextRecord(); 0184 0185 //! Prints data of current record according to the modeprint 0186 void PrintCurrentRecord(); 0187 0188 //! Controls the correct argument count for the record. 0189 //! Resets error argyment mode 0190 void PrepareNewArg(); 0191 0192 //! Prepares the end of the head section 0193 void FinalOfHead(); 0194 0195 //! Sets type of the current argument 0196 void SetTypeArg(const Interface_ParamType theArgType); 0197 0198 //! Initializes the print mode 0199 //! 0 - don't print descriptions 0200 //! 1 - print only descriptions of record 0201 //! 2 - print descriptions of records and its arguments 0202 void SetModePrint(const Standard_Integer theMode); 0203 0204 //! Returns mode print 0205 Standard_Integer GetModePrint() const; 0206 0207 //! Returns number of records 0208 Standard_Integer GetNbRecord() const; 0209 0210 //! Adds an error message 0211 void AddError(Standard_CString theErrorMessage); 0212 0213 //! Transfers error messages to checker 0214 Standard_Boolean ErrorHandle(const Handle(Interface_Check)& theCheck) const; 0215 0216 //! Returns the message of the last error 0217 Standard_CString GetLastError() const; 0218 0219 private: 0220 0221 //! Prepare text to analyze 0222 char* RecordNewText(char* theText); 0223 0224 //! Get current text value 0225 void GetResultText(char** theText); 0226 0227 //! Add a record to the current records page 0228 void AddNewRecord(Record* theNewRecord); 0229 0230 //! Create new empty record 0231 //! If records page is fill, add a new page 0232 Record* CreateNewRecord(); 0233 0234 //! Print data of the record according to the modeprint 0235 void PrintRecord(Record* theRecord); 0236 0237 private: 0238 NCollection_IncAllocator myTextAlloc; //!< Allocator for store text 0239 NCollection_IncAllocator myOtherAlloc; //!< Allocator for internal tools 0240 Standard_Integer myModePrint; //!< Control print output (for call from yacc) 0241 Standard_Integer myNbRec; //!< Total number of data records read 0242 Standard_Integer myNbHead; //!< Number of records taken by the Header 0243 Standard_Integer myNbPar; //!< Total number of parameters read 0244 Standard_Integer myYaRec; //!< Presence record already created (after 1 Ident) 0245 Standard_Integer myNumSub; //!< Number of current sublist 0246 Standard_Boolean myErrorArg; //!< Control of error argument (true - error argument was created) 0247 char* myResText; //!< Text value written by Flex and passed to Bison to create record 0248 char* myCurrType; //!< Type of last record read 0249 char* mySubArg; //!< Ident last record (possible sub-list) 0250 Interface_ParamType myTypeArg; //!< Type of last argument read 0251 Argument* myCurrArg; //!< Current node of the arguments list 0252 Record* myFirstRec; //!< First node of the records list 0253 Record* myCurRec; //!< Current node of the records list 0254 Record* myLastRec; //!< Last node of the records list 0255 Scope* myCurScope; //!< Current node of the scopes list 0256 ErrorsPage* myFirstError; //!< First node of the errors pages list 0257 ErrorsPage* myCurError; //!< Current node of the errors pages list 0258 }; 0259 0260 #endif // _StepFile_ReadData_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |