diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 605f90a50b..4c61b8e329 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -596,7 +596,7 @@ int main(int argc, char** argv) } Logger::Status(msg.str()); - return successful ? 0 : 1; + return successful ? EXIT_SUCCESS : EXIT_FAILURE; } void write_log() { diff --git a/src/ifcgeom/IfcGeomFilter.h b/src/ifcgeom/IfcGeomFilter.h index 8ed61c293f..e64914717b 100644 --- a/src/ifcgeom/IfcGeomFilter.h +++ b/src/ifcgeom/IfcGeomFilter.h @@ -52,10 +52,19 @@ namespace IfcGeom /// children of a storey named "Level 20", or children of entities that have no representation, e.g. IfcCurtainWall. bool traverse; + bool match(IfcSchema::IfcProduct* prod, const filter_t& pred) const + { + bool is_match = pred(prod); + if (!is_match && traverse) { + is_match = traverse_match(prod, pred); + } + return is_match == include; + } + static bool traverse_match(IfcSchema::IfcProduct* prod, const filter_t& pred) { IfcSchema::IfcProduct* parent, *current = prod; - while ((parent = static_cast(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) { + while ((parent = dynamic_cast(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) { if (pred(parent)) { return true; } @@ -84,7 +93,9 @@ namespace IfcGeom } } - bool match(const std::string &str) const + bool match(const std::string &str) const { return match_values(values, str); } + + static bool match_values(const std::set& values, const std::string &str) { foreach(const boost::regex& r, values) { if (boost::regex_match(str, r)) { @@ -157,13 +168,8 @@ namespace IfcGeom bool operator()(IfcSchema::IfcProduct* prod) const { - 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; + // @note bind1st() and mem_fun() deprecated in C++11, use bind() and mem_fn() when migrating to C++11. + return filter::match(prod, std::bind1st(std::mem_fun(&string_arg_filter::match), this)); } }; @@ -185,11 +191,7 @@ namespace IfcGeom bool operator()(IfcSchema::IfcProduct* prod) const { - bool is_match = match(prod); - if (is_match != include && traverse) { - is_match = traverse_match(prod, boost::ref(*this)); - } - return is_match == include; + return filter::match(prod, std::bind1st(std::mem_fun(&layer_filter::match), this)); } struct wildcards_match @@ -197,12 +199,7 @@ namespace IfcGeom wildcards_match(const std::set& patterns) : patterns(patterns) {} bool operator()(const layer_map_t::value_type& layer_map_value) const { - foreach(const boost::regex& r, patterns) { - if (boost::regex_match(layer_map_value.first, r)) { - return true; - } - } - return false; + return wildcard_filter::match_values(patterns, layer_map_value.first); } std::set patterns; @@ -231,7 +228,7 @@ namespace IfcGeom throw IfcParse::IfcException("'" + type + "' does not name a valid IFC entity"); } values.insert(ty); - // TODO: Add child classes so that containment in set can be in O(log n) + /// @todo Add child classes so that containment in set can be in O(log n) } } @@ -248,11 +245,7 @@ namespace IfcGeom bool operator()(IfcSchema::IfcProduct* prod) const { - bool is_match = match(prod); - if (is_match != include && traverse) { - is_match = traverse_match(prod, boost::ref(*this)); - } - return is_match == include; + return filter::match(prod, std::bind1st(std::mem_fun(&entity_filter::match), this)); } }; }