2 Copyright (c) 1999-2020 OPEN CASCADE SAS
4 This file is part of Open CASCADE Technology software library.
6 This library is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License version 2.1 as published
8 by the Free Software Foundation, with special exception defined in the file
9 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 distribution for complete text of the license and disclaimer of any warranty.
12 Alternatively, this file may be used under the terms of Open CASCADE
13 commercial license or contractual agreement.
16 #ifndef _StepFile_ReadData_HeaderFile
17 #define _StepFile_ReadData_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Handle.hxx>
21 #include <Standard_DefineAlloc.hxx>
23 #include <Interface_ParamType.hxx>
25 //! Provides data structures and tools to collect and store the data
26 //! read from the STEP file.
27 //! This class is designed to work in collaboration with STEP parser
28 //! built using flex and bison (receives the data generated by the parser).
30 //! All text (sequence of characters) received in the parsing process
31 //! is stored in the CharacterPage, but the last received text value is
32 //! stored in a pointer to an own page position.
34 //! This value is used to initialize a new record (representation of the
35 //! STEP entity) and its arguments (parameters of the STEP entity).
36 //! All created arguments are stored in the ArgumentsPage, records in the RecordsPage.
39 //! - Arguments used in the record are pointers to the element of the page,
40 //! - All records are pointers to the element of the record page.
42 //! EXAMPLE of parsing STEP file (flex & bison):
45 //! - Input stream to the Flex is "#123=ADVANCED_FACE('',(#124),#125,.F.)"
46 //! - State of Flex is "INITIAL"
47 //! - Stack of Bison states : STEP HEADER ENDSEC endhead model block
48 //! 2. Flex rule detected "#123" - call CreateNewText("#123", 4)
49 //! and sends a token "ENTITY".
50 //! Now class contains "#123", as current text value.
51 //! 3. Bison receive a token and call RecordIdent (), it
52 //! creates a new record in the records page with "#123" identifier.
53 //! Now current record has ident, but args and types are empty.
54 //! 4. Flex rule detected "ADVANCED_FACE" call CreateNewText and send a token "TYPE".
55 //! Now class contains "ADVANCED_FACE", as current text value.
56 //! 5. Bison receive a token and call RecordType (), it
57 //! set "ADVANCED_FACE" to the current record as a type.
58 //! Now current record has ident and type, but args are empty.
59 //! 6. Flex rule detected "(" send token "(".
60 //! Now class continues to contain "ADVANCED_FACE", as current text value.
61 //! 7. Bison receive a token and call RecordListStart (),
62 //! it does nothing via the current state.
63 //! Now current record is not update.
64 //! 8. Flex rule detected ('') call CreateNewText and SetTypeArg and
66 //! Now class contains empty current text value.
67 //! 9. Bison receive a token and call CreateNewArg (), it
68 //! creates a new argument with empty text value and 'Text' type.
69 //! Now current record has ident, type and one argument.
70 //! 10. Flex rule detected "," call PrepareNewArg(",",1), it
71 //! controls arguments count to protect from a skip or double creating a new argument.
72 //! Bison does nothing and the current text value and record are not updated.
73 //! 11. Flex rule detected "(" send token "(".
74 //! Now class continues to contain empty current text value.
75 //! 12. Bison receive a token and call RecordListStart (), it
76 //! creates a new record with "$1" ident and "ADVANCED_FACE" type
77 //! old record is the next of the new record.
78 //! Now current record has ident, type, but args are empty.
79 //! 13. Flex rule detected "#124" call CreateNewText("#124",4) and send token "IDENT",
80 //! Now class contains "#124", as current text value.
81 //! 14. Bison receive a token and call CreateNewArg (), it
82 //! creates a new argument with "#124" text value and 'Ident' type.
83 //! Now current record has ident, type and one argument.
84 //! 15. Flex rule detected ")" send token ")".
85 //! Now class continues to contain "#124", as a current text value.
86 //! 16. Bison receive a token and call RecordNewEntity (), it
87 //! contain record to the records page, prepare to the new record
88 //! and get next record as a current record and set a new arg as a sub_record.
89 //! Now current record is a old record, it has ident, type and two args.
90 //! 17. Flex rule detected "#125" call CreateNewText, SetTypeArg and send token IDEND.
91 //! Now class contains "#125", as a current text value.
92 //! 18. Bison receive a token and call CreateNewArg (), it
93 //! creates a new argument with "#125" text value and 'Ident' type.
94 //! Now current record has ident, type and three argument.
95 //! 19. Flex rule detected "#125" call CreateNewText, SetTypeArg and send token IDEND.
96 //! Now class contains "#125", as a current text value.
97 //! 20. Bison receive a token and call CreateNewArg (), it
98 //! creates a new argument with "#125" text value and 'Ident' type.
99 //! Now current record has ident, type and three argument.
102 //! Reading of several STEP files simultaneously is possible (e.g. in multiple
103 //! threads) provided that each file is read using its own instances of Flex, Bison
104 //! and StepFile_ReadData tools.
106 class Interface_Check;
108 class StepFile_ReadData
111 // Standard OCCT memory allocation stuff
112 DEFINE_STANDARD_ALLOC
116 class CharactersPage; //!< List of characters pages, contains all text derived from Flex
117 class Record; //!< List of records, contains all text processed by Bison
118 class Argument; //!< List of arguments, contains all argument descriptions
119 class ArgumentsPage; //!< List of arguments pages, contains all text derived from Flex
120 class Scope; //!< List of scopes pages, contains all records for external processing
121 class RecordsPage; //!< List of records pages, contains all records
122 class ErrorsPage; //!< List of errors messages, contains all errors
126 //! Constructs an uninitialized tool
129 //! Destructor cleans allocated memory of all fields
130 ~StepFile_ReadData() { ClearRecorder(3); }
132 //! Preperes the text value for analysis.
133 //! It is the main tool for transferring data from flex to bison
134 //! If characters page is full, allocates a new page.
135 void CreateNewText(const char* theNewText, int theLenText);
137 //! Adds the current record to the list
138 void RecordNewEntity();
140 //! Creates a new record and sets Ident from myResText
143 //! Starts reading of the type (entity)
146 //! Prepares and saves a record or sub-record
147 void RecordListStart();
149 //! Prepares new arguments.
150 //! Type and value already known.
151 //! If arguments page is full, allocates a new page
154 //! Prepares error arguments, controls count of error arguments.
155 //! If bison handles a sequence of error types,
156 //! creates only one argument and updates text value
157 void CreateErrorArg();
159 //! Creates a new scope, containing the current record
167 //! * 1 - clear pages of records and arguments
168 //! * 2 - clear pages of characters
169 //! * 3 - clear all data
170 void ClearRecorder(const Standard_Integer theMode);
172 //! Returns a value of fields of current argument
173 Standard_Boolean GetArgDescription(Interface_ParamType* theType, char** theValue);
175 //! Returns a value of all file counters
176 void GetFileNbR(Standard_Integer* theNbHead, Standard_Integer* theNbRec, Standard_Integer* theNbPage);
178 //! Returns a value of fields of current record
179 Standard_Boolean GetRecordDescription(char** theIdent, char** theType, int* theNbArg);
181 //! Initializes the record type with myResText
182 void RecordTypeText();
184 //! Skips to next record
187 //! Prints data of current record according to the modeprint
188 void PrintCurrentRecord();
190 //! Controls the correct argument count for the record.
191 //! Resets error argyment mode
192 void PrepareNewArg();
194 //! Prepares the end of the head section
197 //! Sets type of the current argument
198 void SetTypeArg(const Interface_ParamType theArgType);
200 //! Initializes the print mode
201 //! 0 - don't print descriptions
202 //! 1 - print only descriptions of record
203 //! 2 - print descriptions of records and its arguments
204 void SetModePrint(const Standard_Integer theMode);
206 //! Returns mode print
207 Standard_Integer GetModePrint() const;
209 //! Returns number of records
210 Standard_Integer GetNbRecord() const;
212 //! Adds an error message
213 void AddError(Standard_CString theErrorMessage);
215 //! Transfers error messages to checker
216 Standard_Boolean ErrorHandle(const Handle(Interface_Check)& theCheck) const;
218 //! Returns the message of the last error
219 Standard_CString GetLastError() const;
223 //! Prepare text to analyze
224 char* RecordNewText(char* theText);
226 //! Get current text value
227 void GetResultText(char** theText);
229 //! Add a record to the current records page
230 void AddNewRecord(Record* theNewRecord);
232 //! Create new empty record
233 //! If records page is fill, add a new page
234 Record* CreateNewRecord();
236 //! Print data of the record according to the modeprint
237 void PrintRecord(Record* theRecord);
241 Standard_Integer myMaxChar; //!< Maximum number of characters in a characters page
242 Standard_Integer myMaxRec; //!< Maximum number of records in a records page
243 Standard_Integer myMaxArg; //!< Maximum number of arguments in a arguments page
244 Standard_Integer myModePrint; //!< Control print output (for call from yacc)
245 Standard_Integer myNbRec; //!< Total number of data records read
246 Standard_Integer myNbHead; //!< Number of records taken by the Header
247 Standard_Integer myNbPar; //!< Total number of parameters read
248 Standard_Integer myYaRec; //!< Presence record already created (after 1 Ident)
249 Standard_Integer myNumSub; //!< Number of current sublist
250 Standard_Boolean myErrorArg; //!< Control of error argument (true - error argument was created)
251 char* myResText; //!< Text value written by Flex and passed to Bison to create record
252 char* myCurrType; //!< Type of last record read
253 char* mySubArg; //!< Ident last record (possible sub-list)
254 Interface_ParamType myTypeArg; //!< Type of last argument read
255 Argument* myCurrArg; //!< Current node of the arguments list
256 Record* myFirstRec; //!< First node of the records list
257 Record* myCurRec; //!< Current node of the records list
258 Record* myLastRec; //!< Last node of the records list
259 Scope* myCurScope; //!< Current node of the scopes list
260 ErrorsPage* myFirstError; //!< First node of the errors pages list
261 ErrorsPage* myCurError; //!< Current node of the errors pages list
262 RecordsPage* myOneRecPage; //!< Current node of the records pages list
263 CharactersPage* myOneCharPage; //!< Current node of the characters pages list
264 ArgumentsPage* myOneArgPage; //!< Current node of the arguments pages list
267 #endif // _StepFile_ReadData_HeaderFile