1 #ifndef SECTIONREADER_H
2 #define SECTIONREADER_H
3 
4 #include <fstream>
5 #include <set>
6 #include "lazyTypes.h"
7 #include "sc_memmgr.h"
8 #include "sc_export.h"
9 #include "errordesc.h"
10 #include "STEPcomplex.h"
11 
12 class SDAI_Application_instance;
13 class lazyFileReader;
14 class ErrorDescriptor;
15 class Registry;
16 
17 class SC_LAZYFILE_EXPORT sectionReader {
18     protected:
19         //protected data members
20         lazyFileReader * _lazyFile;
21         std::ifstream & _file;
22 
23         std::streampos _sectionStart,  ///< the start of this section as reported by tellg()
24             _sectionEnd;               ///< the end of this section as reported by tellg()
25         unsigned long _totalInstances;
26 
27         ErrorDescriptor * _error;
28         sectionID _sectionID;
29         fileID _fileID;
30 
31         // protected member functions
32 
33         sectionReader( lazyFileReader * parent, std::ifstream & file, std::streampos start, sectionID sid );
34 
35         /** Find a string, ignoring occurrences in comments or Part 21 strings (i.e. 'string with \S\' control directive' )
36          * \param str string to find
37          * \param semicolon if true, 'str' must be followed by a semicolon, possibly preceded by whitespace.
38          * \returns the position of the end of the found string
39          */
40         std::streampos findNormalString( const std::string & str, bool semicolon = false );
41 
42         /** Get a keyword ending with one of delimiters.
43          */
44         const char * getDelimitedKeyword( const char * delimiters );
45 
46         /** Seek to the end of the current instance */
47         std::streampos seekInstanceEnd( instanceRefs ** refs );
48 
49         /// operator>> is very slow?!
skipWS()50         inline void skipWS() {
51             while( isspace( _file.peek() ) && _file.good() ) {
52                 _file.ignore( 1 );
53             }
54         }
55 
56         STEPcomplex * CreateSubSuperInstance( const Registry * reg, instanceID fileid, Severity & sev );
57 
58     public:
59         SDAI_Application_instance * getRealInstance( const Registry * reg, long int begin, instanceID instance,
60                 const std::string & typeName = "", const std::string & schName = "", bool header = false );
61 
ID()62         sectionID ID() const {
63             return _sectionID;
64         }
65 
66         virtual void findSectionStart() = 0;
67 
findSectionEnd()68         void findSectionEnd() {
69             _sectionEnd = findNormalString( "ENDSEC", true );
70         }
71 
sectionStart()72         std::streampos sectionStart() const {
73             return _sectionStart;
74         }
75 
sectionEnd()76         std::streampos sectionEnd() const {
77             return _sectionEnd;
78         }
79 
80         void locateAllInstances(); /**< find instances in section, and add lazyInstance's to lazyInstMgr */
81 
82         virtual const namedLazyInstance nextInstance() = 0;
83 
84         /** returns the type string for an instance, read straight from the file
85          * if this function changes, probably need to change nextInstance() as well
86          * don't check errors - they would have been encountered during the initial file scan, and the file is still open so it can't have been modified */
getType(long int offset)87         const char * getType( long int offset ) {
88             if( offset <= 0 ) {
89                 return 0;
90             }
91             _file.seekg( offset );
92             readInstanceNumber();
93             skipWS();
94             return getDelimitedKeyword( ";( /\\" );
95         }
96 
97         instanceID readInstanceNumber();
98 
seekg(std::streampos pos)99         void seekg( std::streampos pos ) {
100             _file.seekg( pos );
101         }
tellg()102         std::streampos tellg() {
103             return _file.tellg();
104         }
105 };
106 
107 #endif //SECTIONREADER_H
108 
109