From b70b63f09aebea3543fc077e7cb206c4a6e58d01 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Tue, 5 Jan 2021 12:01:24 +0100 Subject: Refactoring: modernize DotNode --- src/dotcallgraph.cpp | 28 +-- src/dotclassgraph.cpp | 47 ++--- src/dotgfxhierarchytable.cpp | 4 +- src/dotgraph.cpp | 11 +- src/dotincldepgraph.cpp | 32 ++-- src/dotnode.cpp | 448 +++++++++++++++++-------------------------- src/dotnode.h | 35 ++-- 7 files changed, 230 insertions(+), 375 deletions(-) diff --git a/src/dotcallgraph.cpp b/src/dotcallgraph.cpp index cbd62ef..9525d52 100644 --- a/src/dotcallgraph.cpp +++ b/src/dotcallgraph.cpp @@ -84,14 +84,9 @@ void DotCallGraph::determineVisibleNodes(QList &queue, int &maxNodes) n->markAsVisible(); maxNodes--; // add direct children - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - queue.append(dn); - } + queue.append(dn); } } } @@ -105,17 +100,12 @@ void DotCallGraph::determineTruncatedNodes(QList &queue) if (n->isVisible() && n->isTruncated()==DotNode::Unknown) { bool truncated = FALSE; - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - if (!dn->isVisible()) - truncated = TRUE; - else - queue.append(dn); - } + if (!dn->isVisible()) + truncated = TRUE; + else + queue.append(dn); } n->markAsTruncated(truncated); } @@ -201,7 +191,7 @@ QCString DotCallGraph::writeGraph( bool DotCallGraph::isTrivial() const { - return m_startNode->children()==0; + return m_startNode->children().empty(); } bool DotCallGraph::isTooBig() const @@ -211,6 +201,6 @@ bool DotCallGraph::isTooBig() const int DotCallGraph::numNodes() const { - return m_startNode->children() ? m_startNode->children()->count() : 0; + return (int)m_startNode->children().size(); } diff --git a/src/dotclassgraph.cpp b/src/dotclassgraph.cpp index e719d79..98a82d4 100644 --- a/src/dotclassgraph.cpp +++ b/src/dotclassgraph.cpp @@ -115,23 +115,16 @@ void DotClassGraph::determineTruncatedNodes(QList &queue,bool includePa if (n->isVisible() && n->isTruncated()==DotNode::Unknown) { bool truncated = FALSE; - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - if (!dn->isVisible()) - truncated = TRUE; - else - queue.append(dn); - } + if (!dn->isVisible()) + truncated = TRUE; + else + queue.append(dn); } - if (n->parents() && includeParents) + if (includeParents) { - QListIterator li(*n->parents()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) + for (const auto &dn : n->parents()) { if (!dn->isVisible()) truncated = TRUE; @@ -176,14 +169,9 @@ bool DotClassGraph::determineVisibleNodes(DotNode *rootNode, n->markAsVisible(); maxNodes--; // add direct children - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - childQueue.append(dn); - } + childQueue.append(dn); } } } @@ -207,14 +195,9 @@ bool DotClassGraph::determineVisibleNodes(DotNode *rootNode, n->markAsVisible(); maxNodes--; // add direct parents - if (n->parents()) + for (const auto &dn : n->parents()) { - QListIterator li(*n->parents()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - parentQueue.append(dn); - } + parentQueue.append(dn); } } } @@ -387,9 +370,9 @@ DotClassGraph::DotClassGraph(const ClassDef *cd,GraphType t) bool DotClassGraph::isTrivial() const { if (m_graphType==Inheritance) - return m_startNode->children()==0 && m_startNode->parents()==0; + return m_startNode->children().empty() && m_startNode->parents().empty(); else - return !Config_getBool(UML_LOOK) && m_startNode->children()==0; + return !Config_getBool(UML_LOOK) && m_startNode->children().empty(); } bool DotClassGraph::isTooBig() const @@ -400,10 +383,10 @@ bool DotClassGraph::isTooBig() const int DotClassGraph::numNodes() const { int numNodes = 0; - numNodes+= m_startNode->children() ? m_startNode->children()->count() : 0; + numNodes+= (int)m_startNode->children().size(); if (m_graphType==Inheritance) { - numNodes+= m_startNode->parents() ? m_startNode->parents()->count() : 0; + numNodes+= (int)m_startNode->parents().size(); } return numNodes; } diff --git a/src/dotgfxhierarchytable.cpp b/src/dotgfxhierarchytable.cpp index c535acf..9f81e22 100644 --- a/src/dotgfxhierarchytable.cpp +++ b/src/dotgfxhierarchytable.cpp @@ -116,7 +116,9 @@ void DotGfxHierarchyTable::addHierarchy(DotNode *n,const ClassDef *cd,ClassDefSe { const auto &bn = it->second; root = bn.get(); - if (n->children()==0 || n->children()->findRef(bn.get())==-1) // no arrow yet + const auto &children = n->children(); + auto child_it = std::find(children.begin(),children.end(),bn.get()); + if (child_it==children.end()) // no arrow yet { n->addChild(bn.get(),bcd.prot); bn->addParent(n); diff --git a/src/dotgraph.cpp b/src/dotgraph.cpp index 287793e..0da1db9 100644 --- a/src/dotgraph.cpp +++ b/src/dotgraph.cpp @@ -316,19 +316,20 @@ void DotGraph::computeGraph(DotNode *root, } root->clearWriteFlag(); root->write(md5stream, gt, format, gt!=CallGraph && gt!=Dependency, TRUE, backArrows); - if (renderParents && root->parents()) + if (renderParents) { - QListIterator dnli(*root->parents()); - const DotNode *pn; - for (dnli.toFirst();(pn=dnli.current());++dnli) + for (const auto &pn : root->parents()) { if (pn->isVisible()) { + const auto &children = pn->children(); + auto child_it = std::find(children.begin(),children.end(),root); + int index = child_it - children.begin(); root->writeArrow(md5stream, // stream gt, // graph type format, // output format pn, // child node - pn->edgeInfo()->at(pn->children()->findRef(root)), // edge info + &pn->edgeInfo()[index], // edge info FALSE, // topDown? backArrows // point back? ); diff --git a/src/dotincldepgraph.cpp b/src/dotincldepgraph.cpp index 05a96d9..85f7a51 100644 --- a/src/dotincldepgraph.cpp +++ b/src/dotincldepgraph.cpp @@ -89,14 +89,9 @@ void DotInclDepGraph::determineVisibleNodes(QList &queue, int &maxNodes n->markAsVisible(); maxNodes--; // add direct children - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) - { - queue.append(dn); - } + queue.append(dn); } } } @@ -110,20 +105,15 @@ void DotInclDepGraph::determineTruncatedNodes(QList &queue) if (n->isVisible() && n->isTruncated()==DotNode::Unknown) { bool truncated = FALSE; - if (n->children()) + for (const auto &dn : n->children()) { - QListIterator li(*n->children()); - const DotNode *dn; - for (li.toFirst();(dn=li.current());++li) + if (!dn->isVisible()) { - if (!dn->isVisible()) - { - truncated = TRUE; - } - else - { - queue.append(dn); - } + truncated = TRUE; + } + else + { + queue.append(dn); } } n->markAsTruncated(truncated); @@ -208,7 +198,7 @@ QCString DotInclDepGraph::writeGraph(FTextStream &out, bool DotInclDepGraph::isTrivial() const { - return m_startNode->children()==0; + return m_startNode->children().empty(); } bool DotInclDepGraph::isTooBig() const @@ -218,7 +208,7 @@ bool DotInclDepGraph::isTooBig() const int DotInclDepGraph::numNodes() const { - return m_startNode->children() ? m_startNode->children()->count() : 0; + return (int)m_startNode->children().size(); } void DotInclDepGraph::writeXML(FTextStream &t) diff --git a/src/dotnode.cpp b/src/dotnode.cpp index 06de5f4..a6703b3 100644 --- a/src/dotnode.cpp +++ b/src/dotnode.cpp @@ -302,9 +302,6 @@ DotNode::DotNode(int n,const char *lab,const char *tip, const char *url, DotNode::~DotNode() { - delete m_children; - delete m_parents; - delete m_edgeInfo; } void DotNode::addChild(DotNode *n, @@ -315,72 +312,48 @@ void DotNode::addChild(DotNode *n, int edgeLabCol ) { - if (m_children==0) - { - m_children = new QList; - m_edgeInfo = new QList; - m_edgeInfo->setAutoDelete(TRUE); - } - m_children->append(n); - EdgeInfo *ei = new EdgeInfo( + m_children.push_back(n); + m_edgeInfo.emplace_back( edgeColor, edgeStyle, edgeLab, edgeURL, edgeLabCol==-1 ? edgeColor : edgeLabCol); - m_edgeInfo->append(ei); } void DotNode::addParent(DotNode *n) { - if (m_parents==0) - { - m_parents = new QList; - } - m_parents->append(n); + m_parents.push_back(n); } void DotNode::removeChild(DotNode *n) { - if (m_children) m_children->remove(n); + auto it = std::find(m_children.begin(),m_children.end(),n); + if (it!=m_children.end()) m_children.erase(it); } void DotNode::removeParent(DotNode *n) { - if (m_parents) m_parents->remove(n); + auto it = std::find(m_parents.begin(),m_parents.end(),n); + if (it!=m_parents.end()) m_parents.erase(it); } -void DotNode::deleteNode(DotNodeList &deletedList,SDict *skipNodes) +void DotNode::deleteNode(DotNodeRefVector &deletedList) { if (m_deleted) return; // avoid recursive loops in case the graph has cycles m_deleted=TRUE; - if (m_parents!=0) // delete all parent nodes of this node + // delete all parent nodes of this node + for (const auto &pn : m_parents) { - QListIterator dnlip(*m_parents); - DotNode *pn; - for (dnlip.toFirst();(pn=dnlip.current());++dnlip) - { - //pn->removeChild(this); - pn->deleteNode(deletedList,skipNodes); - } + pn->deleteNode(deletedList); } - if (m_children!=0) // delete all child nodes of this node + // delete all child nodes of this node + for (const auto &cn : m_children) { - QListIterator dnlic(*m_children); - DotNode *cn; - for (dnlic.toFirst();(cn=dnlic.current());++dnlic) - { - //cn->removeParent(this); - cn->deleteNode(deletedList,skipNodes); - } + cn->deleteNode(deletedList); } // add this node to the list of deleted nodes. - //printf("skipNodes=%p find(%p)=%p\n",skipNodes,this,skipNodes ? skipNodes->find((int)this) : 0); - if (skipNodes==0 || skipNodes->find((char*)this)==0) - { - //printf("deleting\n"); - deletedList.append(this); - } + deletedList.push_back(this); } void DotNode::setDistance(int distance) @@ -390,20 +363,21 @@ void DotNode::setDistance(int distance) inline int DotNode::findParent( DotNode *n ) { - if ( !m_parents ) return -1; - return m_parents->find(n); + auto it = std::find(m_parents.begin(),m_parents.end(),n); + return it!=m_parents.end() ? it-m_parents.begin() : -1; } /*! helper function that deletes all nodes in a connected graph, given * one of the graph's nodes */ -void DotNode::deleteNodes(DotNode *node,SDict *skipNodes) +void DotNode::deleteNodes(DotNode *node) { - //printf("deleteNodes skipNodes=%p\n",skipNodes); - static DotNodeList deletedNodes; - deletedNodes.setAutoDelete(TRUE); - node->deleteNode(deletedNodes,skipNodes); // collect nodes to be deleted. - deletedNodes.clear(); // actually remove the nodes. + DotNodeRefVector deletedNodes; + node->deleteNode(deletedNodes); // collect nodes to be deleted. + for (const auto &dotNode : deletedNodes) + { + delete dotNode; + } } void DotNode::writeBox(FTextStream &t, @@ -421,27 +395,22 @@ void DotNode::writeBox(FTextStream &t, // add names shown as relations to a set, so we don't show // them as attributes as well StringUnorderedSet arrowNames; - if (m_edgeInfo) + // for each edge + for (const auto &ei : m_edgeInfo) { - // for each edge - QListIterator li(*m_edgeInfo); - EdgeInfo *ei; - for (li.toFirst();(ei=li.current());++li) + if (!ei.label().isEmpty()) // labels joined by \n { - if (!ei->label().isEmpty()) // labels joined by \n + int i=ei.label().find('\n'); + int p=0; + QCString lab; + while ((i=ei.label().find('\n',p))!=-1) { - int i=ei->label().find('\n'); - int p=0; - QCString lab; - while ((i=ei->label().find('\n',p))!=-1) - { - lab = stripProtectionPrefix(ei->label().mid(p,i-p)); - arrowNames.insert(lab.str()); - p=i+1; - } - lab = stripProtectionPrefix(ei->label().right(ei->label().length()-p)); + lab = stripProtectionPrefix(ei.label().mid(p,i-p)); arrowNames.insert(lab.str()); + p=i+1; } + lab = stripProtectionPrefix(ei.label().right(ei.label().length()-p)); + arrowNames.insert(lab.str()); } } @@ -597,44 +566,40 @@ void DotNode::write(FTextStream &t, if (!m_visible) return; // node is not visible writeBox(t,gt,format,m_truncated==Truncated); m_written=TRUE; - QList *nl = toChildren ? m_children : m_parents; - if (nl) + if (toChildren) { - if (toChildren) + auto it = m_edgeInfo.begin(); + for (const auto &cn : m_children) { - QListIterator dnli1(*nl); - QListIterator dnli2(*m_edgeInfo); - const DotNode *cn; - for (dnli1.toFirst();(cn=dnli1.current());++dnli1,++dnli2) + if (cn->isVisible()) { - if (cn->isVisible()) - { - //printf("write arrow %s%s%s\n",label().data(),backArrows?"<-":"->",cn->label().data()); - writeArrow(t,gt,format,cn,dnli2.current(),topDown,backArrows); - } - cn->write(t,gt,format,topDown,toChildren,backArrows); + //printf("write arrow %s%s%s\n",label().data(),backArrows?"<-":"->",cn->label().data()); + writeArrow(t,gt,format,cn,&(*it),topDown,backArrows); } + cn->write(t,gt,format,topDown,toChildren,backArrows); + ++it; } - else // render parents + } + else // render parents + { + for (const auto &pn : m_parents) { - QListIterator dnli(*nl); - DotNode *pn; - for (dnli.toFirst();(pn=dnli.current());++dnli) + if (pn->isVisible()) { - if (pn->isVisible()) - { - //printf("write arrow %s%s%s\n",label().data(),backArrows?"<-":"->",pn->label().data()); - writeArrow(t, - gt, - format, - pn, - pn->edgeInfo()->at(pn->children()->findRef(this)), - FALSE, - backArrows - ); - } - pn->write(t,gt,format,TRUE,FALSE,backArrows); + const auto &children = pn->children(); + auto child_it = std::find(children.begin(),children.end(),this); + int index = child_it - children.begin(); + //printf("write arrow %s%s%s\n",label().data(),backArrows?"<-":"->",pn->label().data()); + writeArrow(t, + gt, + format, + pn, + &pn->edgeInfo()[index], + FALSE, + backArrows + ); } + pn->write(t,gt,format,TRUE,FALSE,backArrows); } } //printf("end DotNode::write(%d) name=%s\n",distance,m_label.data()); @@ -660,51 +625,46 @@ void DotNode::writeXML(FTextStream &t,bool isClassGraph) const t << "/>" << endl; } } - if (m_children) + auto it = m_edgeInfo.begin(); + for (const auto &childNode : m_children) { - QListIterator nli(*m_children); - QListIterator eli(*m_edgeInfo); - DotNode *childNode; - EdgeInfo *edgeInfo; - for (;(childNode=nli.current());++nli,++eli) - { - edgeInfo=eli.current(); - t << " number() << "\" relation=\""; - if (isClassGraph) - { - switch(edgeInfo->color()) - { - case EdgeInfo::Blue: t << "public-inheritance"; break; - case EdgeInfo::Green: t << "protected-inheritance"; break; - case EdgeInfo::Red: t << "private-inheritance"; break; - case EdgeInfo::Purple: t << "usage"; break; - case EdgeInfo::Orange: t << "template-instance"; break; - case EdgeInfo::Orange2: t << "type-constraint"; break; - case EdgeInfo::Grey: ASSERT(0); break; - } - } - else // include graph + const EdgeInfo &edgeInfo = *it; + t << " number() << "\" relation=\""; + if (isClassGraph) + { + switch(edgeInfo.color()) { - t << "include"; + case EdgeInfo::Blue: t << "public-inheritance"; break; + case EdgeInfo::Green: t << "protected-inheritance"; break; + case EdgeInfo::Red: t << "private-inheritance"; break; + case EdgeInfo::Purple: t << "usage"; break; + case EdgeInfo::Orange: t << "template-instance"; break; + case EdgeInfo::Orange2: t << "type-constraint"; break; + case EdgeInfo::Grey: ASSERT(0); break; } - t << "\">" << endl; - if (!edgeInfo->label().isEmpty()) + } + else // include graph + { + t << "include"; + } + t << "\">" << endl; + if (!edgeInfo.label().isEmpty()) + { + int p=0; + int ni; + while ((ni=edgeInfo.label().find('\n',p))!=-1) { - int p=0; - int ni; - while ((ni=edgeInfo->label().find('\n',p))!=-1) - { - t << " " - << convertToXML(edgeInfo->label().mid(p,ni-p)) - << "" << endl; - p=ni+1; - } t << " " - << convertToXML(edgeInfo->label().right(edgeInfo->label().length()-p)) + << convertToXML(edgeInfo.label().mid(p,ni-p)) << "" << endl; + p=ni+1; } - t << " " << endl; + t << " " + << convertToXML(edgeInfo.label().right(edgeInfo.label().length()-p)) + << "" << endl; } + t << " " << endl; + ++it; } t << " " << endl; } @@ -729,51 +689,46 @@ void DotNode::writeDocbook(FTextStream &t,bool isClassGraph) const t << "/>" << endl; } } - if (m_children) + auto it = m_edgeInfo.begin(); + for (const auto &childNode : m_children) { - QListIterator nli(*m_children); - QListIterator eli(*m_edgeInfo); - DotNode *childNode; - EdgeInfo *edgeInfo; - for (;(childNode=nli.current());++nli,++eli) - { - edgeInfo=eli.current(); - t << " number() << "\" relation=\""; - if (isClassGraph) - { - switch(edgeInfo->color()) - { - case EdgeInfo::Blue: t << "public-inheritance"; break; - case EdgeInfo::Green: t << "protected-inheritance"; break; - case EdgeInfo::Red: t << "private-inheritance"; break; - case EdgeInfo::Purple: t << "usage"; break; - case EdgeInfo::Orange: t << "template-instance"; break; - case EdgeInfo::Orange2: t << "type-constraint"; break; - case EdgeInfo::Grey: ASSERT(0); break; - } - } - else // include graph + const EdgeInfo &edgeInfo = *it; + t << " number() << "\" relation=\""; + if (isClassGraph) + { + switch(edgeInfo.color()) { - t << "include"; + case EdgeInfo::Blue: t << "public-inheritance"; break; + case EdgeInfo::Green: t << "protected-inheritance"; break; + case EdgeInfo::Red: t << "private-inheritance"; break; + case EdgeInfo::Purple: t << "usage"; break; + case EdgeInfo::Orange: t << "template-instance"; break; + case EdgeInfo::Orange2: t << "type-constraint"; break; + case EdgeInfo::Grey: ASSERT(0); break; } - t << "\">" << endl; - if (!edgeInfo->label().isEmpty()) + } + else // include graph + { + t << "include"; + } + t << "\">" << endl; + if (!edgeInfo.label().isEmpty()) + { + int p=0; + int ni; + while ((ni=edgeInfo.label().find('\n',p))!=-1) { - int p=0; - int ni; - while ((ni=edgeInfo->label().find('\n',p))!=-1) - { - t << " " - << convertToXML(edgeInfo->label().mid(p,ni-p)) - << "" << endl; - p=ni+1; - } t << " " - << convertToXML(edgeInfo->label().right(edgeInfo->label().length()-p)) + << convertToXML(edgeInfo.label().mid(p,ni-p)) << "" << endl; + p=ni+1; } - t << " " << endl; + t << " " + << convertToXML(edgeInfo.label().right(edgeInfo.label().length()-p)) + << "" << endl; } + t << " " << endl; + ++it; } t << " " << endl; } @@ -806,21 +761,16 @@ void DotNode::writeDEF(FTextStream &t) const t << " };" << endl; } } - if (m_children) + auto it = m_edgeInfo.begin(); + for (const auto &childNode : m_children) { - QListIterator nli(*m_children); - QListIterator eli(*m_edgeInfo); - DotNode *childNode; - EdgeInfo *edgeInfo; - for (;(childNode=nli.current());++nli,++eli) - { - edgeInfo=eli.current(); - t << " node-child = {" << endl; - t << " child-id = '" << childNode->number() << "';" << endl; - t << " relation = "; - - switch(edgeInfo->color()) - { + const EdgeInfo &edgeInfo = *it; + t << " node-child = {" << endl; + t << " child-id = '" << childNode->number() << "';" << endl; + t << " relation = "; + + switch (edgeInfo.color()) + { case EdgeInfo::Blue: t << "public-inheritance"; break; case EdgeInfo::Green: t << "protected-inheritance"; break; case EdgeInfo::Red: t << "private-inheritance"; break; @@ -828,17 +778,17 @@ void DotNode::writeDEF(FTextStream &t) const case EdgeInfo::Orange: t << "template-instance"; break; case EdgeInfo::Orange2: t << "type-constraint"; break; case EdgeInfo::Grey: ASSERT(0); break; - } - t << ';' << endl; + } + t << ';' << endl; - if (!edgeInfo->label().isEmpty()) - { - t << " edgelabel = <<_EnD_oF_dEf_TeXt_" << endl - << edgeInfo->label() << endl - << "_EnD_oF_dEf_TeXt_;" << endl; - } - t << " }; /* node-child */" << endl; - } /* for (;childNode...) */ + if (!edgeInfo.label().isEmpty()) + { + t << " edgelabel = <<_EnD_oF_dEf_TeXt_" << endl + << edgeInfo.label() << endl + << "_EnD_oF_dEf_TeXt_;" << endl; + } + t << " }; /* node-child */" << endl; + ++it; } t << " }; /* node */" << endl; } @@ -847,63 +797,31 @@ void DotNode::writeDEF(FTextStream &t) const void DotNode::clearWriteFlag() { m_written=FALSE; - if (m_parents!=0) - { - QListIterator dnlip(*m_parents); - DotNode *pn; - for (dnlip.toFirst();(pn=dnlip.current());++dnlip) - { - if (pn->isWritten()) - { - pn->clearWriteFlag(); - } - } - } - if (m_children!=0) - { - QListIterator dnlic(*m_children); - DotNode *cn; - for (dnlic.toFirst();(cn=dnlic.current());++dnlic) - { - if (cn->isWritten()) - { - cn->clearWriteFlag(); - } - } - } + for (const auto &pn : m_parents) if (pn->isWritten()) pn->clearWriteFlag(); + for (const auto &cn : m_children) if (cn->isWritten()) cn->clearWriteFlag(); } void DotNode::colorConnectedNodes(int curColor) { - if (m_children) + for (const auto &cn : m_children) { - QListIterator dnlic(*m_children); - DotNode *cn; - for (dnlic.toFirst();(cn=dnlic.current());++dnlic) + if (cn->subgraphId()==-1) // uncolored child node { - if (cn->subgraphId()==-1) // uncolored child node - { - cn->setSubgraphId(curColor); - cn->markAsVisible(); - cn->colorConnectedNodes(curColor); - //printf("coloring node %s (%p): %d\n",cn->label().data(),cn,cn->subgraphId()); - } + cn->setSubgraphId(curColor); + cn->markAsVisible(); + cn->colorConnectedNodes(curColor); + //printf("coloring node %s (%p): %d\n",cn->label().data(),cn,cn->subgraphId()); } } - if (m_parents) + for (const auto &pn : m_parents) { - QListIterator dnlip(*m_parents); - DotNode *pn; - for (dnlip.toFirst();(pn=dnlip.current());++dnlip) + if (pn->subgraphId()==-1) // uncolored parent node { - if (pn->subgraphId()==-1) // uncolored parent node - { - pn->setSubgraphId(curColor); - pn->markAsVisible(); - pn->colorConnectedNodes(curColor); - //printf("coloring node %s (%p): %d\n",pn->label().data(),pn,pn->subgraphId()); - } + pn->setSubgraphId(curColor); + pn->markAsVisible(); + pn->colorConnectedNodes(curColor); + //printf("coloring node %s (%p): %d\n",pn->label().data(),pn,pn->subgraphId()); } } } @@ -911,17 +829,12 @@ void DotNode::colorConnectedNodes(int curColor) void DotNode::renumberNodes(int &number) { m_number = number++; - if (m_children) + for (const auto &cn : m_children) { - QListIterator dnlic(*m_children); - DotNode *cn; - for (dnlic.toFirst();(cn=dnlic.current());++dnlic) + if (!cn->isRenumbered()) { - if (!cn->isRenumbered()) - { - cn->markRenumbered(); - cn->renumberNodes(number); - } + cn->markRenumbered(); + cn->renumberNodes(number); } } } @@ -930,43 +843,26 @@ const DotNode *DotNode::findDocNode() const { if (!m_url.isEmpty()) return this; //printf("findDocNode(): '%s'\n",m_label.data()); - if (m_parents) + for (const auto &pn : m_parents) { - QListIterator dnli(*m_parents); - DotNode *pn; - for (dnli.toFirst();(pn=dnli.current());++dnli) + if (!pn->hasDocumentation()) { - if (!pn->hasDocumentation()) - { - pn->markHasDocumentation(); - const DotNode *dn = pn->findDocNode(); - if (dn) return dn; - } + pn->markHasDocumentation(); + const DotNode *dn = pn->findDocNode(); + if (dn) return dn; } } - if (m_children) + for (const auto &cn : m_children) { - QListIterator dnli(*m_children); - DotNode *cn; - for (dnli.toFirst();(cn=dnli.current());++dnli) + if (!cn->hasDocumentation()) { - if (!cn->hasDocumentation()) - { - cn->markHasDocumentation(); - const DotNode *dn = cn->findDocNode(); - if (dn) return dn; - } + cn->markHasDocumentation(); + const DotNode *dn = cn->findDocNode(); + if (dn) return dn; } } return 0; } -//-------------------------------------------------------------- - -int DotNodeList::compareValues(const DotNode *n1,const DotNode *n2) const -{ - return qstricmp(n1->label(),n2->label()); -} - diff --git a/src/dotnode.h b/src/dotnode.h index 92f268e..dd42637 100644 --- a/src/dotnode.h +++ b/src/dotnode.h @@ -16,12 +16,12 @@ #ifndef DOTNODE_H #define DOTNODE_H -#include "sortdict.h" +#include #include "dotgraph.h" class ClassDef; -class DotNodeList; +class DotNode; class FTextStream; /** Attributes of an edge of a dot graph */ @@ -30,7 +30,7 @@ class EdgeInfo public: enum Colors { Blue=0, Green=1, Red=2, Purple=3, Grey=4, Orange=5, Orange2=6 }; enum Styles { Solid=0, Dashed=1 }; - EdgeInfo(int color,int style,const QCString &lab,const QCString &url,int labColor) + EdgeInfo(int color,int style,const QCString &lab,const QCString &url,int labColor) : m_color(color), m_style(style), m_label(lab), m_url(url), m_labColor(labColor) {} ~EdgeInfo() {} int color() const { return m_color; } @@ -46,11 +46,14 @@ class EdgeInfo int m_labColor; }; +using DotNodeRefVector = std::vector; +using EdgeInfoVector = std::vector; + /** A node in a dot graph */ class DotNode { public: - static void deleteNodes(DotNode* node, SDict* skipNodes = 0); + static void deleteNodes(DotNode* node); static QCString convertLabel(const QCString& l); DotNode(int n,const char *lab,const char *tip,const char *url, bool rootNode=FALSE,const ClassDef *cd=0); @@ -65,7 +68,7 @@ class DotNode const char *edgeURL=0, int edgeLabCol=-1); void addParent(DotNode *n); - void deleteNode(DotNodeList &deletedList,SDict *skipNodes=0); + void deleteNode(DotNodeRefVector &deletedList); void removeChild(DotNode *n); void removeParent(DotNode *n); int findParent( DotNode *n ); @@ -101,18 +104,18 @@ class DotNode const DotNode *findDocNode() const; // only works for acyclic graphs! void markAsVisible(bool b=TRUE) { m_visible=b; } void markAsTruncated(bool b=TRUE) { m_truncated=b ? Truncated : Untruncated; } - const QList *children() const { return m_children; } - const QList *parents() const { return m_parents; } - const QList *edgeInfo() const { return m_edgeInfo; } + const DotNodeRefVector &children() const { return m_children; } + const DotNodeRefVector &parents() const { return m_parents; } + const EdgeInfoVector &edgeInfo() const { return m_edgeInfo; } private: int m_number; QCString m_label; //!< label text QCString m_tooltip; //!< node's tooltip QCString m_url; //!< url of the node (format: remote$local) - QList *m_parents = 0; //!< list of parent nodes (incoming arrows) - QList *m_children = 0; //!< list of child nodes (outgoing arrows) - QList *m_edgeInfo = 0; //!< edge info for each child + DotNodeRefVector m_parents; //!< list of parent nodes (incoming arrows) + DotNodeRefVector m_children; //!< list of child nodes (outgoing arrows) + EdgeInfoVector m_edgeInfo; //!< edge info for each child bool m_deleted = false; //!< used to mark a node as deleted mutable bool m_written = false; //!< used to mark a node as written bool m_hasDoc = false; //!< used to mark a node as documented @@ -125,14 +128,4 @@ class DotNode int m_subgraphId = -1; }; -/** Class representing a list of DotNode objects. */ -class DotNodeList : public QList -{ - public: - DotNodeList() : QList() {} - ~DotNodeList() {} - private: - int compareValues(const DotNode *n1,const DotNode *n2) const; -}; - #endif -- cgit v0.12