cyclegraph: add overloaded getNode_noCreate()
authorBrian Norris <banorris@uci.edu>
Tue, 5 Feb 2013 00:22:03 +0000 (16:22 -0800)
committerBrian Norris <banorris@uci.edu>
Wed, 6 Feb 2013 21:44:39 +0000 (13:44 -0800)
Need a generic way to map a ModelAction/Promise to a CycleNode.

cyclegraph.cc
cyclegraph.h

index 54b91238d98b2d22155a45a838da9a3b655d376c..2c3a5936a89d8ac7dbb7e5b43e32b7a1cfd5ec6a 100644 (file)
@@ -31,14 +31,29 @@ void CycleGraph::putNode(const ModelAction *act, CycleNode *node)
 #endif
 }
 
 #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
 /**
  * @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)
 {
  * @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);
        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 * 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);
        if (node == NULL) {
                node = new CycleNode(promise);
                readerToPromiseNode.put(reader, node);
index c9c575ab36cdce5c8e9bc8445b0bce21837d8f99..f03c4ecf33496314387d99c28f19dc80f3839e27 100644 (file)
@@ -52,8 +52,10 @@ class CycleGraph {
  private:
        void addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
        void putNode(const ModelAction *act, CycleNode *node);
  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(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);
 
        bool mergeNodes(CycleNode *node1, CycleNode *node2,
                        promise_list_t *mustMerge);