@@ -31,6 +31,11 @@ using namespace IfcParse;
3131File::File (const std::string& fn) {
3232 eof = false ;
3333 stream.open (fn.c_str (),std::ios_base::binary);
34+ if ( ! stream.good () ) {
35+ valid = false ;
36+ return ;
37+ }
38+ valid = true ;
3439 stream.seekg (0 ,std::ios_base::end);
3540 size = (unsigned int ) stream.tellg ();
3641 stream.seekg (0 ,std::ios_base::beg);
@@ -492,6 +497,7 @@ unsigned int Entity::id() { return _id; }
492497//
493498bool Ifc::Init (const std::string& fn) {
494499 file = new File (fn);
500+ if ( ! file->valid ) return false ;
495501 tokens = new Tokens (file);
496502 Token token = 0 ;
497503 Token previous = 0 ;
@@ -500,12 +506,12 @@ bool Ifc::Init(const std::string& fn) {
500506 int x = 0 ;
501507 EntityPtr e;
502508 IfcUtil::IfcSchemaEntity entity;
503- if ( log ) std::cout << " Scanning file..." << std::endl;
509+ if ( log1 ) std::cout << " Scanning file..." << std::endl;
504510 while ( true ) {
505511 if ( currentId ) {
506512 e = EntityPtr (new Entity (currentId,tokens));
507513 entity = Ifc2x3::SchemaEntity (e);
508- if ( log && !((++x)%1000 ) ) std::cout << " \r #" << currentId << " " << std::flush;
514+ if ( log1 && !((++x)%1000 ) ) std::cout << " \r #" << currentId << " " << std::flush;
509515 IfcEntities L = EntitiesByType (entity->type ());
510516 if ( L == 0 ) {
511517 L = IfcEntities (new IfcEntityList ());
@@ -532,7 +538,7 @@ bool Ifc::Init(const std::string& fn) {
532538 previous = token;
533539 }
534540
535- if ( log ) std::cout << " \r Done scanning file " << std::endl;
541+ if ( log1 ) std::cout << " \r Done scanning file " << std::endl;
536542
537543 Ifc2x3::IfcUnitAssignment::ptr unit_assignment = *EntitiesByType<Ifc2x3::IfcUnitAssignment>()->begin ();
538544 IfcUtil::IfcAbstractSelect::list units = unit_assignment->Units ();
@@ -626,16 +632,17 @@ float UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) {
626632 else if ( v == Ifc2x3::IfcSIPrefix::ATTO ) return (float ) 1e-18 ;
627633 else return 1 .0f ;
628634}
629- void Ifc::SetOutput (std::ostream* l ) { log = l ; }
635+ void Ifc::SetOutput (std::ostream* l1, std::ostream* l2 ) { log1 = l1; log2 = l2 ; }
630636void Ifc::LogMessage (const std::string& type, const std::string& message, const SHARED_PTR<IfcAbstractEntity>& entity) {
631- if ( log ) {
632- (*log ) << " [" << type << " ] " << message << std::endl;
633- if ( entity ) (*log ) << entity->toString () << std::endl;
637+ if ( log2 ) {
638+ (*log2 ) << " [" << type << " ] " << message << std::endl;
639+ if ( entity ) (*log2 ) << entity->toString () << std::endl;
634640 }
635641}
636642
637643File* Ifc::file = 0 ;
638- std::ostream* Ifc::log = 0 ;
644+ std::ostream* Ifc::log1 = 0 ;
645+ std::ostream* Ifc::log2 = 0 ;
639646unsigned int Ifc::lastId = 0 ;
640647Tokens* Ifc::tokens = 0 ;
641648float Ifc::LengthUnit = 1 .0f ;
0 commit comments