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

- added excludeTag() function (negation of findTag())

- removed the no-longer-necessary optional argument of findTag() - use flatten() instead
parent 534f87dd
No related branches found
No related tags found
No related merge requests found
......@@ -60,16 +60,16 @@ namespace ChimeraTK {
/** Obtain the list of submodules associated with this instance and any submodules */
std::list<Module*> getSubmoduleListRecursive();
/** 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. "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. "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;
VirtualModule findTag(const std::string &tag) const;
/** Return a VirtualModule containing the part of the tree structure not matching the given tag. This is
* the negation of findTag(), this function will keep those variables which findTag() would remove from the
* tree. Again, "tag" is interpreted as a regular expression (see std::regex_match). */
VirtualModule excludeTag(const std::string &tag) const;
/** Called inside the constructor of Accessor: adds the accessor to the list */
void registerAccessor(VariableNetworkNode accessor) {
......@@ -125,7 +125,12 @@ namespace ChimeraTK {
virtual ModuleType getModuleType() const = 0;
protected:
/** Add the part of the tree structure matching the given tag to a VirtualModule. Users normally will use
* 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, bool negate=false) const;
/** Create Graphviz dot graph write to stream, excluding the surrounding digraph command */
void dumpGraphInternal(std::ostream &stream) const;
......
......@@ -85,21 +85,33 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
VirtualModule EntityOwner::findTag(const std::string &tag, bool eliminateAllHierarchies) const {
VirtualModule EntityOwner::findTag(const std::string &tag) const {
// create new module to return
VirtualModule module{_name, _description, getModuleType()};
// add everything matching the tag to the virtual module and return it
findTagAndAppendToModule(module, tag, eliminateAllHierarchies, true);
findTagAndAppendToModule(module, tag, false, true);
return module;
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void EntityOwner::findTagAndAppendToModule(VirtualModule &module, const std::string &tag, bool eliminateAllHierarchies,
bool eliminateFirstHierarchy) const {
VirtualModule EntityOwner::excludeTag(const std::string &tag) const {
// create new module to return
VirtualModule module{_name, _description, getModuleType()};
// add everything matching the tag to the virtual module and return it
findTagAndAppendToModule(module, tag, false, true, true);
return module;
}
/*********************************************************************************************************************/
void EntityOwner::findTagAndAppendToModule(VirtualModule &module, const std::string &tag, bool eliminateAllHierarchies,
bool eliminateFirstHierarchy, bool negate) const {
VirtualModule nextmodule{_name, _description, getModuleType()};
VirtualModule *moduleToAddTo;
......@@ -122,13 +134,14 @@ namespace ChimeraTK {
break;
}
}
if(!addNode) if(std::regex_match("", expr)) addNode = true; // check if empty tag matches
if(node.getTags().size() == 0) if(std::regex_match("", expr)) addNode = true; // check if empty tag matches, if no tag applied to node
if(negate) addNode = !addNode;
if(addNode) moduleToAddTo->registerAccessor(node);
}
// iterate through submodules
for(auto submodule : getSubmoduleList()) {
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies);
submodule->findTagAndAppendToModule(*moduleToAddTo, tag, eliminateAllHierarchies, false, negate);
}
if(needToAddSubModule) {
......@@ -139,7 +152,7 @@ namespace ChimeraTK {
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void EntityOwner::dump(const std::string &prefix) const {
......@@ -159,7 +172,7 @@ namespace ChimeraTK {
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void EntityOwner::dumpGraph(const std::string& fileName) const {
std::fstream file(fileName, std::ios_base::out);
......@@ -169,7 +182,7 @@ namespace ChimeraTK {
file.close();
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
std::string EntityOwner::cleanDotNode(std::string fullName) const {
std::replace(fullName.begin(), fullName.end(), '/', '_');
......@@ -177,7 +190,7 @@ namespace ChimeraTK {
return fullName;
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void EntityOwner::dumpGraphInternal(std::ostream &stream) const {
......@@ -220,7 +233,7 @@ namespace ChimeraTK {
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
void EntityOwner::addTag(const std::string &tag) {
for(auto &node : getAccessorList()) node.addTag(tag);
......@@ -228,7 +241,7 @@ namespace ChimeraTK {
_tags.insert(tag);
}
/*********************************************************************************************************************/
/*********************************************************************************************************************/
VirtualModule EntityOwner::flatten() {
VirtualModule nextmodule{_name, _description, getModuleType()};
......
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