traverse() as a global function rather than method on IfcFile

This commit is contained in:
Thomas Krijnen
2017-06-20 18:54:30 +02:00
parent a27e516011
commit 1e8b1d9c9c
3 changed files with 13 additions and 7 deletions
-1
View File
@@ -55,7 +55,6 @@ private:
IfcSpfHeader _header; IfcSpfHeader _header;
void setDefaultHeaderValues(); void setDefaultHeaderValues();
void traverse(IfcUtil::IfcBaseClass*, std::set<IfcUtil::IfcBaseClass*>& visited, IfcEntityList::ptr list, int level, int max_level);
void register_inverse(unsigned, Token); void register_inverse(unsigned, Token);
public: public:
IfcParse::IfcSpfLexer* tokens; IfcParse::IfcSpfLexer* tokens;
+11 -6
View File
@@ -1261,7 +1261,7 @@ bool IfcFile::Init(IfcParse::IfcSpfStream* s) {
return true; return true;
} }
void IfcFile::traverse(IfcUtil::IfcBaseClass* instance, std::set<IfcUtil::IfcBaseClass*>& visited, IfcEntityList::ptr list, int level, int max_level) { void traverse_(IfcUtil::IfcBaseClass* instance, std::set<IfcUtil::IfcBaseClass*>& visited, IfcEntityList::ptr list, int level, int max_level) {
if (visited.find(instance) != visited.end()) { if (visited.find(instance) != visited.end()) {
return; return;
} }
@@ -1274,30 +1274,35 @@ void IfcFile::traverse(IfcUtil::IfcBaseClass* instance, std::set<IfcUtil::IfcBas
Argument* arg = instance->getArgument(i); Argument* arg = instance->getArgument(i);
if (arg->type() == IfcUtil::Argument_ENTITY_INSTANCE) { if (arg->type() == IfcUtil::Argument_ENTITY_INSTANCE) {
traverse(*arg, visited, list, level + 1, max_level); traverse_(*arg, visited, list, level + 1, max_level);
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) { } else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityList::ptr entity_list_attribute = *arg; IfcEntityList::ptr entity_list_attribute = *arg;
for (IfcEntityList::it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) { for (IfcEntityList::it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) {
traverse(*it, visited, list, level + 1, max_level); traverse_(*it, visited, list, level + 1, max_level);
} }
} else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE) { } else if (arg->type() == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE) {
IfcEntityListList::ptr entity_list_attribute = *arg; IfcEntityListList::ptr entity_list_attribute = *arg;
for (IfcEntityListList::outer_it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) { for (IfcEntityListList::outer_it it = entity_list_attribute->begin(); it != entity_list_attribute->end(); ++it) {
for (IfcEntityListList::inner_it jt = it->begin(); jt != it->end(); ++jt) { for (IfcEntityListList::inner_it jt = it->begin(); jt != it->end(); ++jt) {
traverse(*jt, visited, list, level + 1, max_level); traverse_(*jt, visited, list, level + 1, max_level);
} }
} }
} }
} }
} }
IfcEntityList::ptr IfcFile::traverse(IfcUtil::IfcBaseClass* instance, int max_level) { IfcEntityList::ptr IfcParse::traverse(IfcUtil::IfcBaseClass* instance, int max_level) {
std::set<IfcUtil::IfcBaseClass*> visited; std::set<IfcUtil::IfcBaseClass*> visited;
IfcEntityList::ptr return_value(new IfcEntityList); IfcEntityList::ptr return_value(new IfcEntityList);
traverse(instance, visited, return_value, 0, max_level); traverse_(instance, visited, return_value, 0, max_level);
return return_value; return return_value;
} }
/// @note: for backwards compatibility
IfcEntityList::ptr IfcFile::traverse(IfcUtil::IfcBaseClass* instance, int max_level) {
return IfcParse::traverse(instance, max_level);
}
void IfcFile::addEntities(IfcEntityList::ptr es) { void IfcFile::addEntities(IfcEntityList::ptr es) {
for( IfcEntityList::it i = es->begin(); i != es->end(); ++ i ) { for( IfcEntityList::it i = es->begin(); i != es->end(); ++ i ) {
addEntity(*i); addEntity(*i);
+2
View File
@@ -257,6 +257,8 @@ namespace IfcParse {
}; };
IfcEntityInstanceData* read(unsigned int i, IfcFile* t, boost::optional<unsigned> offset = boost::none); IfcEntityInstanceData* read(unsigned int i, IfcFile* t, boost::optional<unsigned> offset = boost::none);
IfcEntityList::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1);
} }
IFC_PARSE_API std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f); IFC_PARSE_API std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);