diff --git a/include/EntityOwner.h b/include/EntityOwner.h index e87f3054e0132702dc2a352be4f0e6cd14878e7b..d2a98c2cf30e441b47c623c62ef2d235b18444a4 100644 --- a/include/EntityOwner.h +++ b/include/EntityOwner.h @@ -63,11 +63,11 @@ namespace ChimeraTK { /** Return a VirtualModule containing the part of the tree structure matching the given tag. The resulting * VirtualModule might have virtual sub-modules, if this EntityOwner contains sub-EntityOwners with - * entities matchting the tag. */ + * entities matchting the tag. "tag" is interpreted as a regular expression (see std::regex_match). */ VirtualModule findTag(const std::string &tag, bool eliminateAllHierarchies=false) const; /** Add the part of the tree structure matching the given tag to a VirtualModule. Users normally will use - * findTag() instead. */ + * findTag() instead. "tag" is interpreted as a regular expression (see std::regex_match). */ void findTagAndAppendToModule(VirtualModule &module, const std::string &tag, bool eliminateAllHierarchies=false, bool eliminateFirstHierarchy=false) const; diff --git a/src/EntityOwner.cc b/src/EntityOwner.cc index c0fb2dcce00a95ee096b6fe97fc0782636b5462e..8445378e824b9e42f1a99fac36d4216ae5ad1c1e 100644 --- a/src/EntityOwner.cc +++ b/src/EntityOwner.cc @@ -6,7 +6,7 @@ */ #include <cassert> - +#include <regex> #include <iostream> #include "EntityOwner.h" @@ -113,10 +113,17 @@ namespace ChimeraTK { } // add nodes to the module if matching the tag + std::regex expr(tag); for(auto node : getAccessorList()) { - if(node.getTags().count(tag) > 0) { - moduleToAddTo->registerAccessor(node); + bool addNode = false; + for(auto &nodeTag : node.getTags()) { + if(std::regex_match(nodeTag, expr)) { + addNode = true; + break; + } } + if(!addNode) if(std::regex_match("", expr)) addNode = true; // check if empty tag matches + if(addNode) moduleToAddTo->registerAccessor(node); } // iterate through submodules