From 7101ac22c8da0848b140f08961aae6d9d2c29640 Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Fri, 17 Feb 2017 09:27:37 +0200 Subject: [PATCH] Refactor template class arg_filter into string_arg_filter instead, support for IfcProxy.Tag (untested, did not find suitable test input yet). --- src/ifcconvert/IfcConvert.cpp | 15 +++++++------ src/ifcgeom/IfcGeomFilter.h | 41 +++++++++++++++-------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 58b24592f9..f6ab27c69c 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -436,7 +436,7 @@ int main(int argc, char** argv) } // IfcRoot.GlobalId - IfcGeom::arg_filter guid_filter; + IfcGeom::string_arg_filter guid_filter(IfcSchema::Type::IfcRoot, 0); guid_filter.traverse = traverse; if (include_filter.arg == GUID_ARG) { guid_filter.include = true; @@ -452,7 +452,7 @@ int main(int argc, char** argv) // Note: skipping IfcRoot OwnerHistory, argument index 1 // IfcRoot.Name - IfcGeom::arg_filter name_filter; + IfcGeom::string_arg_filter name_filter(IfcSchema::Type::IfcRoot, 2); name_filter.traverse = traverse; if (include_filter.arg == NAME_ARG) { name_filter.include = true; @@ -466,7 +466,7 @@ int main(int argc, char** argv) } // IfcRoot.Description - IfcGeom::arg_filter desc_filter; + IfcGeom::string_arg_filter desc_filter(IfcSchema::Type::IfcRoot, 3); desc_filter.traverse = traverse; if (include_filter.arg == DESC_ARG) { desc_filter.include = true; @@ -479,10 +479,11 @@ int main(int argc, char** argv) filters.push_back(boost::ref(desc_filter)); } - /// @todo IfcProxy.Tag - //IfcGeom::arg_filter tag_filter; - // IfcElement.Tag - IfcGeom::arg_filter tag_filter; + // IfcProxy.Tag & IfcElement.Tag + IfcGeom::string_arg_filter::arg_map_t tag_args; + tag_args[IfcSchema::Type::IfcProxy] = 8; + tag_args[IfcSchema::Type::IfcElement] = 7; + IfcGeom::string_arg_filter tag_filter(tag_args); tag_filter.traverse = traverse; if (include_filter.arg == TAG_ARG) { tag_filter.include = true; diff --git a/src/ifcgeom/IfcGeomFilter.h b/src/ifcgeom/IfcGeomFilter.h index 13fd9dec10..582a4fbc2b 100644 --- a/src/ifcgeom/IfcGeomFilter.h +++ b/src/ifcgeom/IfcGeomFilter.h @@ -102,32 +102,27 @@ namespace IfcGeom } }; - /// @todo Maybe not use template class for this after all. Attribute name would be better - /// than index, but IfcBaseClass doesn't have getArgument(name) (IfcLateBoundEntity would have though). - template - struct arg_filter : public wildcard_filter + struct string_arg_filter : public wildcard_filter { - arg_filter() - { -#ifndef NDEBUG - IfcType dummy(0); - assert(ArgIndex < dummy.getArgumentCount()); -#endif - } - arg_filter(bool include, bool traverse, const std::set& patterns) - : wildcard_filter(include, traverse, patterns) - { - #ifndef NDEBUG - IfcType dummy(0); - assert(ArgIndex < dummy.getArgumentCount()); - #endif - populate(patterns); - } + // Using this for now in order to overcome the fact that different classes have the argument at different indices. + typedef std::map arg_map_t; + arg_map_t args; - ArgType value(IfcSchema::IfcProduct* prod) const + /// @todo Take only attribute name when IfcBaseClass and IfcLateBoundEntity are merged. + string_arg_filter(arg_map_t args) : args(args) {} + string_arg_filter(IfcSchema::Type::Enum type, unsigned short index) { args[type] = index; } + + std::string value(IfcSchema::IfcProduct* prod) const { - Argument *arg = prod->is(IfcType::Class()) ? prod->entity->getArgument(ArgIndex) : 0; - return arg && !arg->isNull() ? *arg : ArgType(); + for (arg_map_t::const_iterator it = args.begin(); it != args.end(); ++it) { + if (prod->is(it->first)) { + Argument *arg = (it->second <= prod->entity->getArgumentCount() ? prod->entity->getArgument(it->second) : 0); + if (arg && !arg->isNull()) { + return *arg; + } + } + } + return ""; } bool operator()(IfcSchema::IfcProduct* prod) const