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

When attaching a trigger to a node, the resulting triggered node is stored and...

When attaching a trigger to a node, the resulting triggered node is stored and later returned when the same trigger is attached again to the same node. This fixes crashes when joining two networks sharing the same node triggered by the same trigger, if the triggering node was technically different.
parent fa6c14f5
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#define CHIMERATK_VARIABLE_NETWORK_NODE_H
#include <unordered_set>
#include <unordered_map>
#include <assert.h>
......@@ -90,6 +91,7 @@ namespace ChimeraTK {
/** Compare two nodes */
bool operator==(const VariableNetworkNode& other) const;
bool operator!=(const VariableNetworkNode& other) const;
bool operator<(const VariableNetworkNode& other) const;
/** Connect two nodes */
// VariableNetworkNode& operator<<(const VariableNetworkNode &other);
......@@ -211,6 +213,10 @@ namespace ChimeraTK {
/** Set of tags if type == Application */
std::unordered_set<std::string> tags;
/** Map to store triggered versions of this node. The map key is the trigger node and the value is the node
* with the respective trigger added. */
std::map<VariableNetworkNode, VariableNetworkNode> nodeWithTrigger;
};
......
......@@ -222,6 +222,13 @@ namespace ChimeraTK {
}
/*********************************************************************************************************************/
bool VariableNetworkNode::operator<(const VariableNetworkNode& other) const {
if(pdata->type == NodeType::invalid && other.pdata->type == NodeType::invalid) return false;
return (other.pdata < pdata);
}
/*********************************************************************************************************************/
/*
VariableNetworkNode& VariableNetworkNode::operator<<(const VariableNetworkNode &other) {
if(pdata->direction == VariableDirection::invalid) pdata->direction = VariableDirection::consuming;
......@@ -256,22 +263,26 @@ namespace ChimeraTK {
// force direction of the triggering node to be feeding
if(trigger.pdata->direction == VariableDirection::invalid) trigger.pdata->direction = VariableDirection::feeding;
assert(trigger.pdata->direction == VariableDirection::feeding);
// check if already existing in map
if(pdata->nodeWithTrigger.count(trigger) > 0) {
return pdata->nodeWithTrigger[trigger];
}
// create copy of the node
VariableNetworkNode nodeWithTrigger;
nodeWithTrigger.pdata.reset(new VariableNetworkNode_data(*pdata));
pdata->nodeWithTrigger[trigger].pdata.reset(new VariableNetworkNode_data(*pdata));
// add ourselves as a trigger receiver to the other network
if(!trigger.hasOwner()) {
Application::getInstance().createNetwork().addNode(trigger);
}
trigger.getOwner().addTriggerReceiver(nodeWithTrigger);
trigger.getOwner().addTriggerReceiver(pdata->nodeWithTrigger[trigger]);
// set flag and store pointer to other network
nodeWithTrigger.pdata->externalTrigger = trigger;
pdata->nodeWithTrigger[trigger].pdata->externalTrigger = trigger;
// return the new node
return nodeWithTrigger;
return pdata->nodeWithTrigger[trigger];
}
/*********************************************************************************************************************/
......
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