Skip to content

Commit 379d4cd

Browse files
committed
getRealInstance() works for simple instances now
1 parent 0d42506 commit 379d4cd

File tree

4 files changed

+60
-236
lines changed

4 files changed

+60
-236
lines changed

src/cllazyfile/headerSectionReader.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ class headerSectionReader: public sectionReader {
1717
sectionReader( parent, file, start, sid ) {
1818
}
1919
public:
20-
//nothing public
20+
instancesLoaded_t getInstances() {
21+
return _headerInstances;
22+
}
23+
24+
~headerSectionReader() {
25+
int i = 0;
26+
instancesLoaded_t::iterator it = _headerInstances.begin();
27+
for( ; it != _headerInstances.end(); it++ ) {
28+
delete it->second;
29+
i++;
30+
}
31+
std::cerr << "deleted " << i << " header instances" << std::endl;
32+
}
2133
};
2234

2335
#endif //HEADERSECTIONREADER_H

src/cllazyfile/p21HeaderSectionReader.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <assert.h>
22

33
#include "p21HeaderSectionReader.h"
4+
#include "headerSectionReader.h"
5+
#include "sectionReader.h"
6+
#include "lazyInstMgr.h"
47
#include <string.h>
58

69

@@ -18,7 +21,10 @@ p21HeaderSectionReader::p21HeaderSectionReader( lazyFileReader * parent, std::if
1821
namedLazyInstance nl;
1922
std::cerr << "lazy instance size: " << sizeof( nl.loc ) << std::endl;
2023
while( nl = nextInstance(), ( nl.loc.begin > 0 ) ) {
21-
_headerInstances.insert( instancesLoaded_pair( nl.loc.instance, getRealInstance( &nl.loc ) ) );
24+
std::streampos pos = _file.tellg();
25+
_headerInstances.insert( instancesLoaded_pair( nl.loc.instance,
26+
getRealInstance( _lazyFile->getInstMgr()->getHeaderRegistry(), &nl.loc, nl.name, "", true ) ) );
27+
_file.seekg( pos );
2228
}
2329
_file.seekg( _sectionEnd );
2430
}

src/cllazyfile/sectionReader.cc

Lines changed: 37 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include <set>
66
#include <assert.h>
77

8+
#include "Registry.h"
89
#include "sdaiApplication_instance.h"
10+
#include "read_func.h"
11+
912
#include "sectionReader.h"
1013
#include "lazyFileReader.h"
1114
#include "lazyInstMgr.h"
@@ -69,6 +72,7 @@ std::streampos sectionReader::findNormalString( const std::string& str, bool sem
6972
}
7073
}
7174

75+
7276
//NOTE different behavior than const char * GetKeyword( istream & in, const char * delims, ErrorDescriptor & err ) in read_func.cc
7377
const char * sectionReader::getDelimitedKeyword( const char * delimiters ) {
7478
static std::string str;
@@ -123,6 +127,7 @@ std::streampos sectionReader::seekInstanceEnd( std::set< instanceID > * refs ) {
123127
case '=':
124128
return -1;
125129
case '#':
130+
skipWS();
126131
if( isdigit( _file.peek() ) ) {
127132
if( refs != 0 ) {
128133
instanceID n;
@@ -201,243 +206,42 @@ instanceID sectionReader::readInstanceNumber() {
201206
}
202207

203208
//TODO: most of the rest of readdata1, all of readdata2
204-
SDAI_Application_instance * sectionReader::getRealInstance( lazyInstanceLoc* inst ) {
205-
// assert( inst->instance < 4 );
206-
std::cerr << "getRealInstance() isn't implemented. Instance #" << inst->instance << std::endl;
207-
return 0;
208-
}
209-
210-
#ifdef stepfile
211-
/**
212-
* PASS 1: create instances
213-
* starts at the data section
214-
*/
215-
int sectionReader::ReadData1( istream & in ) {
216-
int endsec = 0;
217-
int _entsNotCreated = 0;
218-
219-
int _errorCount = 0; // reset error count
220-
int _warningCount = 0; // reset error count
221-
209+
SDAI_Application_instance * sectionReader::getRealInstance( const Registry * reg, const lazyInstanceLoc* lazy, const std::string & typeName, const std::string & schName, bool header ) {
222210
char c;
223-
int instance_count = 0;
224-
char buf[BUFSIZ];
225-
buf[0] = '\0';
226-
std::string tmpbuf;
227-
228-
SDAI_Application_instance * obj = ENTITY_NULL;
229-
stateEnum inst_state = noStateSE; // used if reading working file
230-
231-
ErrorDescriptor e;
232-
233-
// PASS 1: create instances
234-
endsec = FoundEndSecKywd( in, _error );
235-
while( in.good() && !endsec ) {
236-
e.ClearErrorMsg();
237-
ReadTokenSeparator( in ); // also skips white space
238-
in >> c;
239-
240-
if( c != ENTITY_NAME_DELIM ) {
241-
in.putback( c );
242-
while( c != ENTITY_NAME_DELIM && in.good() &&
243-
!( endsec = FoundEndSecKywd( in, _error ) ) ) {
244-
tmpbuf.clear();
245-
FindStartOfInstance( in, tmpbuf );
246-
cout << "ERROR: trying to recover from invalid data. skipping: "
247-
<< tmpbuf << endl;
248-
in >> c;
249-
ReadTokenSeparator( in );
250-
}
251-
}
252-
253-
if( !endsec ) {
254-
obj = ENTITY_NULL;
255-
if( ( _fileType == WORKING_SESSION ) && ( inst_state == deleteSE ) ) {
256-
SkipInstance( in, tmpbuf );
257-
} else {
258-
obj = CreateInstance( in, cout );
259-
_iFileCurrentPosition = in.tellg();
260-
}
211+
std::string comment;
212+
Severity sev;
213+
SDAI_Application_instance * inst = 0;
261214

262-
if( obj != ENTITY_NULL ) {
263-
if( obj->Error().severity() < SEVERITY_WARNING ) {
264-
++_errorCount;
265-
} else if( obj->Error().severity() < SEVERITY_NULL ) {
266-
++_warningCount;
267-
}
268-
obj->Error().ClearErrorMsg();
269-
270-
if( _fileType == WORKING_SESSION ) {
271-
instances().Append( obj, inst_state );
272-
} else {
273-
instances().Append( obj, newSE );
274-
}
275-
276-
++instance_count;
277-
} else {
278-
++_entsNotCreated;
279-
//old
280-
++_errorCount;
281-
}
282-
283-
if( _entsNotCreated > _maxErrorCount ) {
284-
_error.AppendToUserMsg( "Warning: Too Many Errors in File. Read function aborted.\n" );
285-
cerr << Error().UserMsg();
286-
cerr << Error().DetailMsg();
287-
Error().ClearErrorMsg();
288-
Error().severity( SEVERITY_EXIT );
289-
return instance_count;
290-
}
291-
292-
endsec = FoundEndSecKywd( in, _error );
293-
294-
}
295-
} // end while loop
296-
297-
if( _entsNotCreated ) {
298-
sprintf( buf,
299-
"sectionReader Reading File: Unable to create %d instances.\n\tIn first pass through DATA section. Check for invalid entity types.\n",
300-
_entsNotCreated );
301-
_error.AppendToUserMsg( buf );
302-
_error.GreaterSeverity( SEVERITY_WARNING );
303-
}
304-
if( !in.good() ) {
305-
_error.AppendToUserMsg( "Error in input file.\n" );
215+
_file.seekg( lazy->begin );
216+
skipWS();
217+
ReadTokenSeparator( _file, &comment );
218+
if( !header ) {
219+
findNormalString( "=" );
306220
}
307-
308-
_iFileStage1Done = true;
309-
return instance_count;
310-
}
311-
312-
/**
313-
* \returns number of valid instances read
314-
* reads in the data portion of the instances in an exchange file
315-
*/
316-
int sectionReader::ReadData2( istream & in, bool useTechCor ) {
317-
_entsInvalid = 0;
318-
_entsIncomplete = 0;
319-
_entsWarning = 0;
320-
321-
int total_instances = 0;
322-
int valid_insts = 0; // used for exchange file only
323-
stateEnum inst_state = noStateSE; // used if reading working file
324-
325-
_errorCount = 0; // reset error count
326-
_warningCount = 0; // reset error count
327-
328-
char c;
329-
char buf[BUFSIZ];
330-
buf[0] = '\0';
331-
std::string tmpbuf;
332-
333-
SDAI_Application_instance * obj = ENTITY_NULL;
334-
std::string cmtStr;
335-
336-
// ReadTokenSeparator(in, &cmtStr);
337-
338-
int endsec = FoundEndSecKywd( in, _error );
339-
340-
// PASS 2: read instances
341-
while( in.good() && !endsec ) {
342-
ReadTokenSeparator( in, &cmtStr );
343-
in >> c;
344-
345-
if( _fileType == WORKING_SESSION ) {
346-
if( strchr( "CIND", c ) ) { // if there is a valid char
347-
inst_state = EntityWfState( c );
348-
ReadTokenSeparator( in, &cmtStr );
349-
in >> c; // read the ENTITY_NAME_DELIM
350-
}
351-
/*
352-
* // don't need this error msg for the 2nd pass (it was done on 1st)
353-
* else
354-
* {
355-
* cout << "Invalid editing state character: " << c << endl;
356-
* cout << "Assigning editing state to be INCOMPLETE\n";
357-
* inst_state = incompleteSE;
358-
}
359-
*/
360-
}
361-
362-
if( c != ENTITY_NAME_DELIM ) {
363-
in.putback( c );
364-
while( c != ENTITY_NAME_DELIM && in.good() &&
365-
!( endsec = FoundEndSecKywd( in, _error ) ) ) {
366-
367-
tmpbuf.clear();
368-
FindStartOfInstance( in, tmpbuf );
369-
cout << "ERROR: trying to recover from invalid data. skipping: "
370-
<< tmpbuf << endl;
371-
in >> c;
372-
ReadTokenSeparator( in, &cmtStr );
373-
}
374-
}
375-
376-
377-
if( !endsec ) {
378-
obj = ENTITY_NULL;
379-
if( ( _fileType == WORKING_SESSION ) && ( inst_state == deleteSE ) ) {
380-
SkipInstance( in, tmpbuf );
381-
} else {
382-
obj = ReadInstance( in, cout, cmtStr, useTechCor );
383-
_iFileCurrentPosition = in.tellg();
384-
}
385-
386-
cmtStr.clear();
387-
if( obj != ENTITY_NULL ) {
388-
if( obj->Error().severity() < SEVERITY_INCOMPLETE ) {
389-
++_entsInvalid;
390-
// old
391-
++_errorCount;
392-
} else if( obj->Error().severity() == SEVERITY_INCOMPLETE ) {
393-
++_entsIncomplete;
394-
++_entsInvalid;
395-
} else if( obj->Error().severity() == SEVERITY_USERMSG ) {
396-
++_entsWarning;
397-
} else { // i.e. if severity == SEVERITY_NULL
398-
++valid_insts;
399-
}
400-
401-
obj->Error().ClearErrorMsg();
402-
403-
++total_instances;
404-
} else {
405-
++_entsInvalid;
406-
// old
407-
++_errorCount;
408-
}
409-
410-
if( _entsInvalid > _maxErrorCount ) {
411-
_error.AppendToUserMsg( "Warning: Too Many Errors in File. Read function aborted.\n" );
412-
cerr << Error().UserMsg();
413-
cerr << Error().DetailMsg();
414-
Error().ClearErrorMsg();
415-
Error().severity( SEVERITY_EXIT );
416-
return valid_insts;
417-
}
418-
419-
endsec = FoundEndSecKywd( in, _error );
420-
}
421-
} // end while loop
422-
423-
if( _entsInvalid ) {
424-
sprintf( buf,
425-
"%s \n\tTotal instances: %d \n\tInvalid instances: %d \n\tIncomplete instances (includes invalid instances): %d \n\t%s: %d.\n",
426-
"Second pass complete - instance summary:", total_instances,
427-
_entsInvalid, _entsIncomplete, "Warnings",
428-
_entsWarning );
429-
cout << buf << endl;
430-
_error.AppendToUserMsg( buf );
431-
_error.AppendToDetailMsg( buf );
432-
_error.GreaterSeverity( SEVERITY_WARNING );
221+
skipWS();
222+
c = _file.get();
223+
switch( c ) {
224+
case '&':
225+
std::cerr << "Can't handle scope instances. Skipping #" << lazy->instance << std::endl;
226+
// sev = CreateScopeInstances( in, &scopelist );
227+
break;
228+
case '(':
229+
std::cerr << "Can't handle complex instances. Skipping #" << lazy->instance << std::endl;
230+
//CreateSubSuperInstance( in, fileid, result );
231+
break;
232+
case '!':
233+
std::cerr << "Can't handle user-defined instances. Skipping #" << lazy->instance << std::endl;
234+
default:
235+
inst = reg->ObjCreate( typeName.c_str(), schName.c_str() );
236+
break;
433237
}
434-
if( !in.good() ) {
435-
_error.AppendToUserMsg( "Error in input file.\n" );
238+
inst->StepFileId( lazy->instance );
239+
if( !comment.empty() ) {
240+
inst->AddP21Comment( comment );
436241
}
437-
438-
// if( in.good() )
439-
// in.putback(c);
440-
return valid_insts;
242+
findNormalString( "(" );
243+
_file.unget();
244+
sev = inst->STEPread( lazy->instance, 0, /*&instances()*/ 0, _file, schName.c_str(), true, false );
245+
return inst;
441246
}
442247

443-
#endif //stepfile

src/cllazyfile/sectionReader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class SDAI_Application_instance;
1010
class lazyFileReader;
1111
class ErrorDescriptor;
12+
class Registry;
1213

1314
class sectionReader {
1415
protected:
@@ -50,7 +51,8 @@ class sectionReader {
5051
}
5152

5253
public:
53-
SDAI_Application_instance * getRealInstance( lazyInstanceLoc * inst );
54+
SDAI_Application_instance * getRealInstance( const Registry * reg, const lazyInstanceLoc* inst,
55+
const std::string & typeName, const std::string & schName = "", bool header = false );
5456
sectionID ID() const {
5557
return _sectionID;
5658
}

0 commit comments

Comments
 (0)