From: Brian Norris Date: Tue, 5 Feb 2013 00:22:03 +0000 (-0800) Subject: cyclegraph: add overloaded getNode_noCreate() X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=482c7447dd2f63823eb969c37dd6fb4e22991fde;hp=b3ff4f8b32505a6e44b70ddc754af6ecb2321474 cyclegraph: add overloaded getNode_noCreate() Need a generic way to map a ModelAction/Promise to a CycleNode. --- diff --git a/cyclegraph.cc b/cyclegraph.cc index 54b91238..2c3a5936 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -31,14 +31,29 @@ void CycleGraph::putNode(const ModelAction *act, CycleNode *node) #endif } +/** @return The corresponding CycleNode, if exists; otherwise NULL */ +CycleNode * CycleGraph::getNode_noCreate(const ModelAction *act) const +{ + return actionToNode.get(act); +} + +/** @return The corresponding CycleNode, if exists; otherwise NULL */ +CycleNode * CycleGraph::getNode_noCreate(const Promise *promise) const +{ + return readerToPromiseNode.get(promise->get_action()); +} + /** * @brief Returns the CycleNode corresponding to a given ModelAction + * + * Gets (or creates, if none exist) a CycleNode corresponding to a ModelAction + * * @param action The ModelAction to find a node for * @return The CycleNode paired with this action */ CycleNode * CycleGraph::getNode(const ModelAction *action) { - CycleNode *node = actionToNode.get(action); + CycleNode *node = getNode_noCreate(action); if (node == NULL) { node = new CycleNode(action); putNode(action, node); @@ -58,7 +73,7 @@ CycleNode * CycleGraph::getNode(const ModelAction *action) CycleNode * CycleGraph::getNode(const Promise *promise) { const ModelAction *reader = promise->get_action(); - CycleNode *node = readerToPromiseNode.get(reader); + CycleNode *node = getNode_noCreate(promise); if (node == NULL) { node = new CycleNode(promise); readerToPromiseNode.put(reader, node); diff --git a/cyclegraph.h b/cyclegraph.h index c9c575ab..f03c4ecf 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -52,8 +52,10 @@ class CycleGraph { private: void addNodeEdge(CycleNode *fromnode, CycleNode *tonode); void putNode(const ModelAction *act, CycleNode *node); - CycleNode * getNode(const ModelAction *); + CycleNode * getNode(const ModelAction *act); CycleNode * getNode(const Promise *promise); + CycleNode * getNode_noCreate(const ModelAction *act) const; + CycleNode * getNode_noCreate(const Promise *promise) const; bool mergeNodes(CycleNode *node1, CycleNode *node2, promise_list_t *mustMerge);