-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathlazyFileReader.cc
More file actions
75 lines (64 loc) · 2.13 KB
/
lazyFileReader.cc
File metadata and controls
75 lines (64 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <assert.h>
#include "cllazyfile/lazyFileReader.h"
#include "cllazyfile/lazyDataSectionReader.h"
#include "cllazyfile/headerSectionReader.h"
#include "cllazyfile/lazyInstMgr.h"
void lazyFileReader::initP21() {
_header = new p21HeaderSectionReader( this, _file, 0, -1 );
for( ;; ) {
lazyDataSectionReader * r;
r = new lazyP21DataSectionReader( this, _file, _file.tellg(), _parent->countDataSections() );
if( !r->success() ) {
delete r; //last read attempt failed
std::cerr << "Corrupted data section" << std::endl;
break;
}
_parent->registerDataSection( r );
//check for new data section (DATA) or end of file (END-ISO-10303-21;)
while( isspace( _file.peek() ) && _file.good() ) {
_file.ignore( 1 );
}
if( needKW( "END-ISO-10303-21;" ) ) {
break;
} else if( !needKW( "DATA" ) ) {
std::cerr << "Corrupted file - did not find new data section (\"DATA\") or end of file (\"END-ISO-10303-21;\") at offset " << _file.tellg() << std::endl;
break;
}
}
}
bool lazyFileReader::needKW( const char * kw ) {
const char * c = kw;
bool found = true;
while( *c ) {
if( *c != _file.get() ) {
found = false;
break;
}
c++;
}
return found;
}
instancesLoaded_t * lazyFileReader::getHeaderInstances() {
return _header->getInstances();
}
lazyFileReader::lazyFileReader( std::string fname, lazyInstMgr * i, fileID fid ): _fileName( fname ), _parent( i ), _fileID( fid ) {
_file.open( _fileName.c_str(), std::ios::binary );
_file.imbue( std::locale::classic() );
_file.unsetf( std::ios_base::skipws );
assert( _file.is_open() && _file.good() );
detectType();
switch( _fileType ) {
case Part21:
initP21();
break;
case Part28:
//initP28();
//break;
default:
std::cerr << "Reached default case, " << __FILE__ << ":" << __LINE__ << std::endl;
abort();
}
}
lazyFileReader::~lazyFileReader() {
delete _header;
}