From 2144dfc0d165ac48d12bbc3cad43f1c2cd8355c7 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 11 Dec 2012 12:55:28 -0800 Subject: [PATCH] cyclegraph: don't export CycleNode::edges directly, use accessors The CycleNode::edges vector shouldn't be accessed directly; it should be used through accessors, to hide implementation details. (Really, there's a bug in the CycleNode that I need to fix, so I'm fixing this first.) --- cyclegraph.cc | 34 +++++++++++++++++++++------------- cyclegraph.h | 3 ++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cyclegraph.cc b/cyclegraph.cc index ead70ae6..0528029a 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -107,9 +107,8 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) { * (2) the fromnode is the new node and therefore it should not * have any outgoing edges. */ - std::vector * edges=fromnode->getEdges(); - for(unsigned int i=0;isize();i++) { - CycleNode * tonode=(*edges)[i]; + for (unsigned int i = 0; i < fromnode->getNumEdges(); i++) { + CycleNode *tonode = fromnode->getEdge(i); if (tonode!=rmwnode) { if (rmwnode->addEdge(tonode)) rollbackvector.push_back(rmwnode); @@ -134,14 +133,13 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) { void CycleGraph::dumpNodes(FILE *file) { for (unsigned int i=0;i * edges=cn->getEdges(); const ModelAction *action=cn->getAction(); fprintf(file, "N%u [label=\"%u, T%u\"];\n",action->get_seq_number(),action->get_seq_number(), action->get_tid()); if (cn->getRMW()!=NULL) { fprintf(file, "N%u -> N%u[style=dotted];\n", action->get_seq_number(), cn->getRMW()->getAction()->get_seq_number()); } - for (unsigned int j=0;jsize();j++) { - CycleNode *dst=(*edges)[j]; + for (unsigned int j = 0; j < cn->getNumEdges(); j++) { + CycleNode *dst = cn->getEdge(j); const ModelAction *dstaction=dst->getAction(); fprintf(file, "N%u -> N%u;\n", action->get_seq_number(), dstaction->get_seq_number()); } @@ -193,8 +191,8 @@ bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { if (node==to) return true; - for(unsigned int i=0;igetEdges()->size();i++) { - CycleNode *next=(*node->getEdges())[i]; + for (unsigned int i = 0; i < node->getNumEdges(); i++) { + CycleNode *next = node->getEdge(i); if (!discovered->contains(next)) { discovered->put(next,next); queue.push_back(next); @@ -220,8 +218,8 @@ bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) { return true; } - for(unsigned int i=0;igetEdges()->size();i++) { - CycleNode *next=(*node->getEdges())[i]; + for (unsigned int i = 0; i < node->getNumEdges(); i++) { + CycleNode *next = node->getEdge(i); if (!discovered->contains(next)) { discovered->put(next,next); queue.push_back(next); @@ -281,9 +279,19 @@ CycleNode::CycleNode(const ModelAction *modelaction) : { } -/** @returns a vector of the edges from a CycleNode. */ -std::vector * CycleNode::getEdges() { - return &edges; +/** + * @param i The index of the edge to return + * @returns The a CycleNode edge indexed by i + */ +CycleNode * CycleNode::getEdge(unsigned int i) const +{ + return edges[i]; +} + +/** @returns The number of edges leaving this CycleNode */ +unsigned int CycleNode::getNumEdges() const +{ + return edges.size(); } /** diff --git a/cyclegraph.h b/cyclegraph.h index f0f04ffe..829c845f 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -63,7 +63,8 @@ class CycleNode { public: CycleNode(const ModelAction *action); bool addEdge(CycleNode * node); - std::vector * getEdges(); + CycleNode * getEdge(unsigned int i) const; + unsigned int getNumEdges() const; bool setRMW(CycleNode *); CycleNode* getRMW(); const ModelAction * getAction() {return action;}; -- 2.34.1