From 50e5d5f4d56609bbc1af835e2ea7b3087d7b5252 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 13 Nov 2018 14:46:15 +0100 Subject: [PATCH] Sort instances before emitting to file --- src/ifcparse/IfcParse.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 665440ffa9..83b0740bdb 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1857,10 +1857,22 @@ IfcFile::type_iterator IfcFile::types_incl_super_end() const { return bytype.end(); } +namespace { + struct id_instance_pair_sorter { + bool operator()(const IfcParse::IfcFile::entity_by_id_t::value_type& a, const IfcParse::IfcFile::entity_by_id_t::value_type& b) const { + return a.first < b.first; + } + }; +} + std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f) { f.header().write(os); - for ( IfcFile::entity_by_id_t::const_iterator it = f.begin(); it != f.end(); ++ it ) { + typedef std::vector > vector_t; + vector_t sorted(f.begin(), f.end()); + std::sort(sorted.begin(), sorted.end(), id_instance_pair_sorter()); + + for (vector_t::const_iterator it = sorted.begin(); it != sorted.end(); ++ it) { const IfcUtil::IfcBaseClass* e = it->second; if (!IfcSchema::Type::IsSimple(e->type())) { os << e->entity->toString(true) << ";" << std::endl;