@@ -420,25 +420,31 @@ EntityArgument::EntityArgument(const Token& t) {
420420// Reads the arguments from a list of token
421421// Aditionally, stores the ids (i.e. #[\d]+) in a vector
422422//
423- ArgumentList::ArgumentList (IfcSpfLexer* t, std::vector<unsigned int >& ids) {
423+ void ArgumentList::read (IfcSpfLexer* t, std::vector<unsigned int >& ids) {
424424 IfcParse::IfcFile* file = t->file ;
425425
426426 Token next = t->Next ();
427427 while ( next.second || next.first ) {
428- if ( TokenFunc::isOperator (next,' ,' ) ) {}
429- else if ( TokenFunc::isOperator (next,' )' ) ) break ;
430- else if ( TokenFunc::isOperator (next,' (' ) ) Push ( new ArgumentList (t,ids) );
431- else {
432- if ( TokenFunc::isIdentifier (next) ) ids.push_back (TokenFunc::asInt (next));
433- if ( TokenFunc::isKeyword (next) ) {
428+ if ( TokenFunc::isOperator (next,' ,' ) ) {
429+ // do nothing
430+ } else if ( TokenFunc::isOperator (next,' )' ) ) {
431+ break ;
432+ } else if ( TokenFunc::isOperator (next,' (' ) ) {
433+ ArgumentList* list = new ArgumentList ();
434+ list->read (t, ids);
435+ push (list);
436+ } else {
437+ if ( TokenFunc::isIdentifier (next) ) {
438+ ids.push_back (TokenFunc::asInt (next));
439+ } if ( TokenFunc::isKeyword (next) ) {
434440 t->Next ();
435441 try {
436- Push ( new EntityArgument (next) );
442+ push ( new EntityArgument (next) );
437443 } catch ( IfcException& e ) {
438444 Logger::Message (Logger::LOG_ERROR,e.what ());
439445 }
440446 } else {
441- Push ( new TokenArgument (next) );
447+ push ( new TokenArgument (next) );
442448 }
443449 }
444450 next = t->Next ();
@@ -461,7 +467,7 @@ IfcUtil::ArgumentType ArgumentList::type() const {
461467 }
462468}
463469
464- void ArgumentList::Push (Argument* l) {
470+ void ArgumentList::push (Argument* l) {
465471 list.push_back (l);
466472}
467473
@@ -523,10 +529,22 @@ ArgumentList::operator IfcEntityListList::ptr() const {
523529}
524530unsigned int ArgumentList::size () const { return (unsigned int ) list.size (); }
525531Argument* ArgumentList::operator [] (unsigned int i) const {
526- if ( i >= list.size () )
532+ if ( i >= list.size () ) {
527533 throw IfcException (" Argument index out of range" );
534+ }
528535 return list[i];
529536}
537+ void ArgumentList::set (unsigned int i, Argument* argument) {
538+ while (size () < i) {
539+ push (new TokenArgument (Token (static_cast <IfcSpfLexer*>(0 ), ' $' )));
540+ }
541+ if (i < size ()) {
542+ delete list[i];
543+ list[i] = argument;
544+ } else {
545+ list.push_back (argument);
546+ }
547+ }
530548std::string ArgumentList::toString (bool upper) const {
531549 std::stringstream ss;
532550 ss << " (" ;
@@ -666,7 +684,8 @@ void Entity::Load(std::vector<unsigned int>& ids, bool seek) const {
666684 _type = IfcSchema::Type::FromString (TokenFunc::asString (datatype));
667685 }
668686 Token open = file->tokens ->Next ();
669- args = new ArgumentList (file->tokens , ids);
687+ args = new ArgumentList ();
688+ args->read (file->tokens , ids);
670689 unsigned int old_offset = file->tokens ->stream ->Tell ();
671690 Token semilocon = file->tokens ->Next ();
672691 if ( ! TokenFunc::isOperator (semilocon,' ;' ) ) file->tokens ->stream ->Seek (old_offset);
@@ -697,7 +716,10 @@ std::string Entity::toString(bool upper) const {
697716 if ( upper ) {
698717 for (std::string::iterator p = dt.begin (); p != dt.end (); ++p ) *p = toupper (*p);
699718 }
700- ss << " #" << _id << " =" << dt << args->toString (upper);
719+ if (!IfcSchema::Type::IsSimple (type ()) || _id != 0 ) {
720+ ss << " #" << _id << " =" ;
721+ }
722+ ss << dt << args->toString (upper);
701723 return ss.str ();
702724}
703725
@@ -721,12 +743,12 @@ IfcWrite::IfcWritableEntity* Entity::isWritable() {
721743
722744IfcFile::IfcFile (bool create_latebound_entities)
723745 : _create_latebound_entities (create_latebound_entities)
746+ , stream (0 )
747+ , lastId (0 )
748+ , tokens (0 )
749+ , MaxId (0 )
724750{
725- stream = 0 ;
726- lastId = 0 ;
727- tokens = 0 ;
728- MaxId = 0 ;
729- initTimestamp ();
751+ setDefaultHeaderValues ();
730752}
731753
732754//
@@ -998,25 +1020,7 @@ IfcFile::entity_by_id_t::const_iterator IfcFile::end() const {
9981020}
9991021
10001022std::ostream& operator << (std::ostream& os, const IfcParse::IfcFile& f) {
1001- os << " ISO-10303-21;" << std::endl;
1002- os << " HEADER;" << std::endl;
1003- os << " FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');" << std::endl;
1004- os << " FILE_NAME("
1005- << static_cast <std::string>(IfcWrite::IfcCharacterEncoder (f.filename ())) << " ,"
1006- << static_cast <std::string>(IfcWrite::IfcCharacterEncoder (f.timestamp ())) << " ,("
1007- << static_cast <std::string>(IfcWrite::IfcCharacterEncoder (f.authorOrganisation ())) << " ),("
1008- << static_cast <std::string>(IfcWrite::IfcCharacterEncoder (f.authorName ())) << " ,"
1009- << static_cast <std::string>(IfcWrite::IfcCharacterEncoder (f.authorEmail ()))
1010- << " ),'IfcOpenShell " << IFCOPENSHELL_VERSION
1011- << " ','IfcOpenShell " << IFCOPENSHELL_VERSION
1012- << " ','');" << std::endl;
1013- #ifdef USE_IFC4
1014- os << " FILE_SCHEMA(('IFC4'));" << std::endl;
1015- #else
1016- os << " FILE_SCHEMA(('IFC2X3'));" << std::endl;
1017- #endif
1018- os << " ENDSEC;" << std::endl;
1019- os << " DATA;" << std::endl;
1023+ f.header ().write (os);
10201024
10211025 for ( IfcFile::entity_by_id_t ::const_iterator it = f.begin (); it != f.end (); ++ it ) {
10221026 const IfcUtil::IfcBaseClass* e = it->second ;
@@ -1029,26 +1033,20 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) {
10291033 return os;
10301034}
10311035
1032- void IfcFile::filename (const std::string& s) { _filename = s; }
1033- std::string IfcFile::filename () const { return _filename; }
1034- void IfcFile::timestamp (const std::string& s) { _timestamp = s; }
1035- std::string IfcFile::timestamp () const { return _timestamp; }
1036- void IfcFile::author (const std::string& name, const std::string& email, const std::string& organisation) {
1037- _author = name;
1038- _author_email = email;
1039- _author_organisation = organisation;
1040- }
1041- std::string IfcFile::authorName () const { return _author; }
1042- std::string IfcFile::authorEmail () const { return _author_email; }
1043- std::string IfcFile::authorOrganisation () const { return _author_organisation; }
1044- void IfcFile::initTimestamp () {
1036+ std::string IfcFile::createTimestamp () const {
10451037 char buf[255 ];
1038+
10461039 time_t t;
10471040 time (&t);
1048- struct tm * ti = localtime (&t);
1041+
1042+ struct tm * ti = localtime (&t);
1043+
1044+ std::string result = " " ;
10491045 if (strftime (buf,255 ," %Y-%m-%dT%H:%M:%S" ,ti)) {
1050- _timestamp = std::string (buf);
1046+ result = std::string (buf);
10511047 }
1048+
1049+ return result;
10521050}
10531051
10541052IfcEntityList::ptr IfcFile::getInverse (int instance_id, IfcSchema::Type::Enum type, int attribute_index) {
@@ -1078,4 +1076,26 @@ IfcEntityList::ptr IfcFile::getInverse(int instance_id, IfcSchema::Type::Enum ty
10781076 }
10791077
10801078 return l;
1081- }
1079+ }
1080+
1081+ void IfcFile::setDefaultHeaderValues () {
1082+ const std::string empty_string = " " ;
1083+ std::vector<std::string> file_description, schema_identifiers, empty_vector;
1084+
1085+ file_description.push_back (" ViewDefinition [CoordinationView]" );
1086+ schema_identifiers.push_back (IfcSchema::Identifier);
1087+
1088+ header ().file_description ().description (file_description);
1089+ header ().file_description ().implementation_level (" 2;1" );
1090+
1091+ header ().file_name ().name (empty_string);
1092+ header ().file_name ().time_stamp (createTimestamp ());
1093+ header ().file_name ().author (empty_vector);
1094+ header ().file_name ().organization (empty_vector);
1095+ header ().file_name ().preprocessor_version (" IfcOpenShell " IFCOPENSHELL_VERSION);
1096+ header ().file_name ().originating_system (" IfcOpenShell " IFCOPENSHELL_VERSION);
1097+ header ().file_name ().authorization (empty_string);
1098+
1099+ header ().file_schema ().schema_identifiers (schema_identifiers);
1100+ }
1101+
0 commit comments