|
|
|||
File indexing completed on 2026-09-16 09:18:43
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 class Record; //!< List of records, contains all text processed by Bison 0117 class Argument; //!< List of arguments, contains all argument descriptions 0118 class Scope; //!< List of scopes pages, contains all records for external processing 0119 class ErrorsPage; //!< List of errors messages, contains all errors 0120 0121 public: 0122 //! Constructs an uninitialized tool 0123 StepFile_ReadData(); 0124 0125 //! Destructor cleans allocated memory of all fields 0126 ~StepFile_ReadData() { ClearRecorder(3); } 0127 0128 //! Prepares the text value for analysis. 0129 //! It is the main tool for transferring data from flex to bison 0130 //! If characters page is full, allocates a new page. 0131 void CreateNewText(const char* theNewText, int theLenText); 0132 0133 //! Adds the current record to the list 0134 void RecordNewEntity(); 0135 0136 //! Creates a new record and sets Ident from myResText 0137 void RecordIdent(); 0138 0139 //! Starts reading of the type (entity) 0140 void RecordType(); 0141 0142 //! Prepares and saves a record or sub-record 0143 void RecordListStart(); 0144 0145 //! Prepares new arguments. 0146 //! Type and value already known. 0147 //! If arguments page is full, allocates a new page 0148 void CreateNewArg(); 0149 0150 //! Prepares error arguments, controls count of error arguments. 0151 //! If bison handles a sequence of error types, 0152 //! creates only one argument and updates text value 0153 void CreateErrorArg(); 0154 0155 //! Creates a new scope, containing the current record 0156 void AddNewScope(); 0157 0158 //! Ends the scope 0159 void FinalOfScope(); 0160 0161 //! Releases memory. 0162 //! @param theMode 0163 //! * 1 - clear pages of records and arguments 0164 //! * 2 - clear pages of characters 0165 //! * 3 - clear all data 0166 void ClearRecorder(const int theMode); 0167 0168 //! Returns a value of fields of current argument 0169 bool GetArgDescription(Interface_ParamType* theType, char** theValue); 0170 0171 //! Returns a value of all file counters 0172 void GetFileNbR(int* theNbHead, int* theNbRec, int* theNbPage); 0173 0174 //! Returns a value of fields of current record 0175 bool GetRecordDescription(char** theIdent, char** theType, int* theNbArg); 0176 0177 //! Initializes the record type with myResText 0178 void RecordTypeText(); 0179 0180 //! Skips to next record 0181 void NextRecord(); 0182 0183 //! Prints data of current record according to the modeprint 0184 void PrintCurrentRecord(); 0185 0186 //! Controls the correct argument count for the record. 0187 //! Resets error argyment mode 0188 void PrepareNewArg(); 0189 0190 //! Prepares the end of the head section 0191 void FinalOfHead(); 0192 0193 //! Sets type of the current argument 0194 void SetTypeArg(const Interface_ParamType theArgType); 0195 0196 //! Initializes the print mode 0197 //! 0 - don't print descriptions 0198 //! 1 - print only descriptions of record 0199 //! 2 - print descriptions of records and its arguments 0200 void SetModePrint(const int theMode); 0201 0202 //! Returns mode print 0203 int GetModePrint() const; 0204 0205 //! Returns number of records 0206 int GetNbRecord() const; 0207 0208 //! Adds an error message 0209 void AddError(const char* theErrorMessage); 0210 0211 //! Transfers error messages to checker 0212 bool ErrorHandle(const occ::handle<Interface_Check>& theCheck) const; 0213 0214 //! Returns the message of the last error 0215 const char* GetLastError() const; 0216 0217 private: 0218 //! Prepare text to analyze 0219 char* RecordNewText(char* theText); 0220 0221 //! Get current text value 0222 void GetResultText(char** theText); 0223 0224 //! Add a record to the current records page 0225 void AddNewRecord(Record* theNewRecord); 0226 0227 //! Create new empty record 0228 //! If records page is fill, add a new page 0229 Record* CreateNewRecord(); 0230 0231 //! Print data of the record according to the modeprint 0232 void PrintRecord(Record* theRecord); 0233 0234 private: 0235 NCollection_IncAllocator myTextAlloc; //!< Allocator for store text 0236 NCollection_IncAllocator myOtherAlloc; //!< Allocator for internal tools 0237 int myModePrint; //!< Control print output (for call from yacc) 0238 int myNbRec; //!< Total number of data records read 0239 int myNbHead; //!< Number of records taken by the Header 0240 int myNbPar; //!< Total number of parameters read 0241 int myYaRec; //!< Presence record already created (after 1 Ident) 0242 int myNumSub; //!< Number of current sublist 0243 // clang-format off 0244 bool myErrorArg; //!< Control of error argument (true - error argument was created) 0245 char* myResText; //!< Text value written by Flex and passed to Bison to create record 0246 // clang-format on 0247 char* myCurrType; //!< Type of last record read 0248 char* mySubArg; //!< Ident last record (possible sub-list) 0249 Interface_ParamType myTypeArg; //!< Type of last argument read 0250 Argument* myCurrArg; //!< Current node of the arguments list 0251 Record* myFirstRec; //!< First node of the records list 0252 Record* myCurRec; //!< Current node of the records list 0253 Record* myLastRec; //!< Last node of the records list 0254 Scope* myCurScope; //!< Current node of the scopes list 0255 ErrorsPage* myFirstError; //!< First node of the errors pages list 0256 ErrorsPage* myCurError; //!< Current node of the errors pages list 0257 }; 0258 0259 #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 |
|