Skip to content
Snippets Groups Projects
Commit 534f87dd authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

allow using regular expressions when searching for tags

parent cc18905f
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment