|
5 | 5 | #include <set> |
6 | 6 | #include <assert.h> |
7 | 7 |
|
| 8 | +#include "Registry.h" |
8 | 9 | #include "sdaiApplication_instance.h" |
| 10 | +#include "read_func.h" |
| 11 | + |
9 | 12 | #include "sectionReader.h" |
10 | 13 | #include "lazyFileReader.h" |
11 | 14 | #include "lazyInstMgr.h" |
@@ -69,6 +72,7 @@ std::streampos sectionReader::findNormalString( const std::string& str, bool sem |
69 | 72 | } |
70 | 73 | } |
71 | 74 |
|
| 75 | + |
72 | 76 | //NOTE different behavior than const char * GetKeyword( istream & in, const char * delims, ErrorDescriptor & err ) in read_func.cc |
73 | 77 | const char * sectionReader::getDelimitedKeyword( const char * delimiters ) { |
74 | 78 | static std::string str; |
@@ -123,6 +127,7 @@ std::streampos sectionReader::seekInstanceEnd( std::set< instanceID > * refs ) { |
123 | 127 | case '=': |
124 | 128 | return -1; |
125 | 129 | case '#': |
| 130 | + skipWS(); |
126 | 131 | if( isdigit( _file.peek() ) ) { |
127 | 132 | if( refs != 0 ) { |
128 | 133 | instanceID n; |
@@ -201,243 +206,42 @@ instanceID sectionReader::readInstanceNumber() { |
201 | 206 | } |
202 | 207 |
|
203 | 208 | //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 ) { |
222 | 210 | 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; |
261 | 214 |
|
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( "=" ); |
306 | 220 | } |
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; |
433 | 237 | } |
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 ); |
436 | 241 | } |
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; |
441 | 246 | } |
442 | 247 |
|
443 | | -#endif //stepfile |
0 commit comments