From 9074f25e93969a4c493ceaac172d9542404dffca Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Tue, 21 Feb 2017 23:42:18 +0200 Subject: [PATCH] Fix --exclude=arg when --traverse used also. --- src/ifcconvert/IfcConvert.cpp | 2 +- src/ifcgeom/IfcGeomFilter.h | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 472e6a0ac7..605f90a50b 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -206,7 +206,7 @@ int main(int argc, char** argv) "to their associated IfcMaterialLayerSet.") ("include", po::value(&include_filter)->multitoken(), "Specifies that the entities that match a specific filtering criteria are to be included in the geometrical output:\n" - "1) 'entities': the following list of types should be included . SVG output defaults " + "1) 'entities': the following list of types should be included. SVG output defaults " "to IfcSpace to be included. The entity names are handled case-insensitively.\n" "2) 'layers': the entities that are assigned to presentation layers of which names " "match the given values should be included.\n" diff --git a/src/ifcgeom/IfcGeomFilter.h b/src/ifcgeom/IfcGeomFilter.h index 4ab0af0394..8ed61c293f 100644 --- a/src/ifcgeom/IfcGeomFilter.h +++ b/src/ifcgeom/IfcGeomFilter.h @@ -33,8 +33,13 @@ #include #include +#include + namespace IfcGeom { + /// The filter function (free or member function) or function object (use boost::ref() to reference to it) + /// should return true if the geometry for the product is wanted to be included in the output. + /// http://www.boost.org/doc/libs/1_62_0/doc/html/function/tutorial.html typedef boost::function filter_t; struct filter @@ -92,7 +97,7 @@ namespace IfcGeom static boost::regex wildcard_string_to_regex(std::string str) { // Escape all non-"*?" regex special chars - std::string special_chars = "\\^.$|()[]+/"; + static const std::string special_chars = "\\^.$|()[]+/"; foreach(char c, special_chars) { std::string char_str(1, c); boost::replace_all(str, char_str, "\\" + char_str); @@ -138,9 +143,9 @@ namespace IfcGeom std::string value(IfcSchema::IfcProduct* prod) const { 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()) { + if (prod->is(it->first) && it->second < prod->entity->getArgumentCount()) { + Argument *arg = prod->entity->getArgument(it->second); + if (!arg->isNull()) { return *arg; } } @@ -148,11 +153,15 @@ namespace IfcGeom return ""; } + bool match(IfcSchema::IfcProduct* prod) const { return wildcard_filter::match(value(prod)); } + bool operator()(IfcSchema::IfcProduct* prod) const { - bool is_match = match(value(prod)); - if (is_match != include && traverse) { - is_match = traverse_match(prod, boost::ref(*this)); + bool is_match = match(prod); + if (!is_match && traverse) { + // @note bind1st() and mem_fun() deprecated in C++11, use bind() and mem_fn() when migrating to C++11. + filter_t pred = std::bind1st(std::mem_fun(&string_arg_filter::match), this); + is_match = traverse_match(prod, pred); } return is_match == include; }