From b789839e4a728339f0dc88df1dd519a4c8609a5c Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 25 Jan 2015 10:50:12 +0000 Subject: [PATCH] Fix errors in serialization --- src/ifcparse/IfcParse.cpp | 12 +++++++++--- src/ifcparse/IfcWrite.cpp | 22 +++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 3c035637ba..7dac922958 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -707,19 +707,23 @@ std::string Entity::datatype() const { // Note that this initializes the entity if it is not initialized // std::string Entity::toString(bool upper) const { - if ( ! args ) { + if (!args) { std::vector ids; Load(ids, true); } + std::stringstream ss; std::string dt = datatype(); - if ( upper ) { + if (upper) { for (std::string::iterator p = dt.begin(); p != dt.end(); ++p ) *p = toupper(*p); } + if (!IfcSchema::Type::IsSimple(type()) || _id != 0) { ss << "#" << _id << "="; } + ss << dt << args->toString(upper); + return ss.str(); } @@ -1024,7 +1028,9 @@ std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) { for ( IfcFile::entity_by_id_t::const_iterator it = f.begin(); it != f.end(); ++ it ) { const IfcUtil::IfcBaseClass* e = it->second; - os << e->entity->toString(true) << ";" << std::endl; + if (!IfcSchema::Type::IsSimple(e->type())) { + os << e->entity->toString(true) << ";" << std::endl; + } } os << "ENDSEC;" << std::endl; diff --git a/src/ifcparse/IfcWrite.cpp b/src/ifcparse/IfcWrite.cpp index b91facf1a5..3543fd1f86 100644 --- a/src/ifcparse/IfcWrite.cpp +++ b/src/ifcparse/IfcWrite.cpp @@ -51,7 +51,6 @@ IfcWritableEntity::IfcWritableEntity(IfcAbstractEntity* e) { file = e->file; _type = e->type(); - delete _id; _id = new int(e->id()); const unsigned int count = e->getArgumentCount(); @@ -77,17 +76,23 @@ bool IfcWritableEntity::is(IfcSchema::Type::Enum v) const { return _type == v; } std::string IfcWritableEntity::toString(bool upper) const { std::stringstream ss; std::string dt = datatype(); - if ( upper ) { + if (upper) { for (std::string::iterator p = dt.begin(); p != dt.end(); ++p ) *p = toupper(*p); } - if ( _id ) ss << "#" << *_id; - ss << "=" << dt << "("; - for ( std::map::const_iterator it = args.begin(); it != args.end(); ++ it ) { + + if (_id && !IfcSchema::Type::IsSimple(type())) { + ss << "#" << *_id; + ss << "="; + } + + ss << dt << "("; + for (std::map::const_iterator it = args.begin(); it != args.end(); ++ it) { if ( it != args.begin() ) ss << ","; const Argument* a = it->second; ss << it->second->toString(upper); } ss << ")"; + return ss.str(); } unsigned int IfcWritableEntity::id() { @@ -228,8 +233,11 @@ public: void operator()(const double& i) { data << format_double(i); } void operator()(const std::string& i) { std::string s = i; - if (upper) s = IfcCharacterEncoder(s); - data << s; + if (upper) { + data << static_cast(IfcCharacterEncoder(s)); + } else { + data << '\'' << s << '\''; + } } void operator()(const std::vector& i); void operator()(const std::vector& i);