Doxygen
dotincldepgraph.cpp
浏览该文件的文档.
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15 
16 #include "dotincldepgraph.h"
17 #include "dotnode.h"
18 #include "util.h"
19 #include "config.h"
20 #include "textstream.h"
21 
22 void DotInclDepGraph::buildGraph(DotNode *n,const FileDef *fd,int distance)
23 {
24  const IncludeInfoList &includeFiles = m_inverse ? fd->includedByFileList() : fd->includeFileList();
25  for (const auto &ii : includeFiles)
26  {
27  const FileDef *bfd = ii.fileDef;
28  QCString in = ii.includeName;
29  //printf(">>>> in='%s' bfd=%p\n",qPrint(ii->includeName),bfd);
30  bool doc=TRUE,src=FALSE;
31  if (bfd)
32  {
33  in = bfd->absFilePath();
34  doc = bfd->isLinkable() && !bfd->isHidden();
35  src = bfd->generateSourceFile();
36  }
37  if (doc || src || !Config_getBool(HIDE_UNDOC_RELATIONS))
38  {
39  QCString url="";
40  if (bfd) url=bfd->getOutputFileBase();
41  if (!doc && src)
42  {
43  url=bfd->getSourceFileBase();
44  }
45  auto it = m_usedNodes.find(in.str());
46  if (it!=m_usedNodes.end()) // file is already a node in the graph
47  {
48  DotNode *bn = it->second;
49  n->addChild(bn,0,0);
50  bn->addParent(n);
51  bn->setDistance(distance);
52  }
53  else
54  {
55  QCString tmp_url;
56  QCString tooltip;
57  if (bfd)
58  {
59  tmp_url=doc || src ? bfd->getReference()+"$"+url : QCString();
60  tooltip = bfd->briefDescriptionAsTooltip();
61  }
62  DotNode *bn = new DotNode(getNextNodeNumber(),// n
63  ii.includeName, // label
64  tooltip, // tip
65  tmp_url, // url
66  FALSE, // rootNode
67  0); // cd
68  n->addChild(bn,0,0);
69  bn->addParent(n);
70  m_usedNodes.insert(std::make_pair(in.str(),bn));
71  bn->setDistance(distance);
72 
73  if (bfd) buildGraph(bn,bfd,distance+1);
74  }
75  }
76  }
77 }
78 
80 {
81  while (!queue.empty() && maxNodes>0)
82  {
83  DotNode *n = queue.front();
84  queue.pop_front();
85  if (!n->isVisible() && n->distance()<=Config_getInt(MAX_DOT_GRAPH_DEPTH)) // not yet processed
86  {
87  n->markAsVisible();
88  maxNodes--;
89  // add direct children
90  for (const auto &dn : n->children())
91  {
92  queue.push_back(dn);
93  }
94  }
95  }
96 }
97 
99 {
100  while (!queue.empty())
101  {
102  DotNode *n = queue.front();
103  queue.pop_front();
104  if (n->isVisible() && n->isTruncated()==DotNode::Unknown)
105  {
106  bool truncated = FALSE;
107  for (const auto &dn : n->children())
108  {
109  if (!dn->isVisible())
110  {
111  truncated = TRUE;
112  }
113  else
114  {
115  queue.push_back(dn);
116  }
117  }
118  n->markAsTruncated(truncated);
119  }
120  }
121 }
122 
124 {
125  m_inverse = inverse;
126  ASSERT(fd!=0);
129  QCString tmp_url=fd->getReference()+"$"+fd->getOutputFileBase();
130  QCString tooltip = fd->briefDescriptionAsTooltip();
132  fd->docName(),
133  tooltip,
134  tmp_url,
135  TRUE); // root node
137  m_usedNodes.insert(std::make_pair(fd->absFilePath().str(),m_startNode));
138  buildGraph(m_startNode,fd,1);
139 
140  int maxNodes = Config_getInt(DOT_GRAPH_MAX_NODES);
141  DotNodeDeque openNodeQueue;
142  openNodeQueue.push_back(m_startNode);
143  determineVisibleNodes(openNodeQueue,maxNodes);
144  openNodeQueue.clear();
145  openNodeQueue.push_back(m_startNode);
146  determineTruncatedNodes(openNodeQueue);
147 }
148 
150 {
152 }
153 
155 {
156  if (m_inverse)
157  {
158  return m_inclByDepFileName;
159  }
160  else
161  {
162  return m_inclDepFileName;
163  }
164 }
165 
167 {
170 }
171 
173 {
174  if (m_inverse)
175  {
176  return escapeCharsInString(m_startNode->label(),FALSE) + "dep";
177  }
178  else
179  {
181  }
182 }
183 
185  GraphOutputFormat graphFormat,
186  EmbeddedOutputFormat textFormat,
187  const QCString &path,
188  const QCString &fileName,
189  const QCString &relPath,
190  bool generateImageMap,
191  int graphId)
192 {
193  return DotGraph::writeGraph(out, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
194 }
195 
197 {
198  return m_startNode->children().empty();
199 }
200 
202 {
203  return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
204 }
205 
207 {
208  return (int)m_startNode->children().size();
209 }
210 
212 {
213  for (const auto &kv : m_usedNodes)
214  {
215  kv.second->writeXML(t,FALSE);
216  }
217 }
218 
220 {
221  for (const auto &kv : m_usedNodes)
222  {
223  kv.second->writeDocbook(t,FALSE);
224  }
225 }
DotGraph::computeGraph
static void computeGraph(DotNode *root, GraphType gt, GraphOutputFormat format, const QCString &rank, bool renderParents, bool backArrows, const QCString &title, QCString &graphStr)
Definition: dotgraph.cpp:305
dotincldepgraph.h
DotNode::addChild
void addChild(DotNode *n, int edgeColor=EdgeInfo::Purple, int edgeStyle=EdgeInfo::Solid, const QCString &edgeLab=QCString(), const QCString &edgeURL=QCString(), int edgeLabCol=-1)
Definition: dotnode.cpp:281
FileDef::getSourceFileBase
virtual QCString getSourceFileBase() const =0
FileDef::generateSourceFile
virtual bool generateSourceFile() const =0
DotGraph::m_theGraph
QCString m_theGraph
Definition: dotgraph.h:89
DotNode::Unknown
@ Unknown
Definition: dotnode.h:65
DotInclDepGraph::writeXML
void writeXML(TextStream &t)
Definition: dotincldepgraph.cpp:211
DotNode::setDistance
void setDistance(int distance)
Definition: dotnode.cpp:333
DotInclDepGraph::m_inclByDepFileName
QCString m_inclByDepFileName
Definition: dotincldepgraph.h:58
dotnode.h
DotNode::markAsTruncated
void markAsTruncated(bool b=TRUE)
Definition: dotnode.h:108
QCString::str
std::string str() const
Definition: qcstring.h:442
DotNode::deleteNodes
static void deleteNodes(DotNode *node)
Definition: dotnode.cpp:347
Definition::isHidden
virtual bool isHidden() const =0
DotNode::addParent
void addParent(DotNode *n)
Definition: dotnode.cpp:298
DotGraph::getNextNodeNumber
int getNextNodeNumber()
returns node numbers.
Definition: dotgraph.h:41
textstream.h
FileDef::includedByFileList
virtual const IncludeInfoList & includedByFileList() const =0
FileDef::isLinkable
virtual bool isLinkable() const =0
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
DotInclDepGraph::writeDocbook
void writeDocbook(TextStream &t)
Definition: dotincldepgraph.cpp:219
FileDef::docName
virtual const QCString & docName() const =0
DotNode::markAsVisible
void markAsVisible(bool b=TRUE)
Definition: dotnode.h:107
DotInclDepGraph::numNodes
int numNodes() const
Definition: dotincldepgraph.cpp:206
DotInclDepGraph::writeGraph
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition: dotincldepgraph.cpp:184
DotNode
A node in a dot graph
Definition: dotnode.h:56
DotInclDepGraph::getBaseName
virtual QCString getBaseName() const
Definition: dotincldepgraph.cpp:154
DotInclDepGraph::determineVisibleNodes
void determineVisibleNodes(DotNodeDeque &queue, int &maxNodes)
Definition: dotincldepgraph.cpp:79
Config_getInt
#define Config_getInt(name)
Definition: config.h:34
DotInclDepGraph::m_startNode
DotNode * m_startNode
Definition: dotincldepgraph.h:55
FileDef::includeDependencyGraphFileName
virtual QCString includeDependencyGraphFileName() const =0
DotInclDepGraph::m_inclDepFileName
QCString m_inclDepFileName
Definition: dotincldepgraph.h:57
DotInclDepGraph::DotInclDepGraph
DotInclDepGraph(const FileDef *fd, bool inverse)
Definition: dotincldepgraph.cpp:123
DotInclDepGraph::buildGraph
void buildGraph(DotNode *n, const FileDef *fd, int distance)
Definition: dotincldepgraph.cpp:22
FileDef::includedByDependencyGraphFileName
virtual QCString includedByDependencyGraphFileName() const =0
DotNode::label
QCString label() const
Definition: dotnode.h:89
Dependency
@ Dependency
Definition: dotgraph.h:29
DotInclDepGraph::m_inverse
bool m_inverse
Definition: dotincldepgraph.h:59
DotGraph::m_graphFormat
GraphOutputFormat m_graphFormat
Definition: dotgraph.h:79
TRUE
#define TRUE
Definition: qcstring.h:36
DotNode::isTruncated
TruncState isTruncated() const
Definition: dotnode.h:92
DotInclDepGraph::computeTheGraph
virtual void computeTheGraph()
Definition: dotincldepgraph.cpp:166
DotInclDepGraph::~DotInclDepGraph
~DotInclDepGraph()
Definition: dotincldepgraph.cpp:149
DotNode::isVisible
bool isVisible() const
Definition: dotnode.h:91
DotInclDepGraph::m_usedNodes
DotNodeMap m_usedNodes
Definition: dotincldepgraph.h:56
DotGraph::writeGraph
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition: dotgraph.cpp:111
Definition::getReference
virtual QCString getReference() const =0
DotNodeDeque
Definition: dotnode.h:137
DotInclDepGraph::isTooBig
bool isTooBig() const
Definition: dotincldepgraph.cpp:201
IncludeInfoList
Definition: filedef.h:59
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
DotNode::distance
int distance() const
Definition: dotnode.h:93
escapeCharsInString
QCString escapeCharsInString(const QCString &name, bool allowDots, bool allowUnderscore)
Definition: util.cpp:3442
FileDef::absFilePath
virtual QCString absFilePath() const =0
config.h
ASSERT
#define ASSERT(x)
Definition: qcstring.h:44
FileDef
A model of a file symbol.
Definition: filedef.h:73
EmbeddedOutputFormat
EmbeddedOutputFormat
Definition: dotgraph.h:28
GraphOutputFormat
GraphOutputFormat
Definition: dotgraph.h:27
DotInclDepGraph::isTrivial
bool isTrivial() const
Definition: dotincldepgraph.cpp:196
Definition::briefDescriptionAsTooltip
virtual QCString briefDescriptionAsTooltip() const =0
DotInclDepGraph::determineTruncatedNodes
void determineTruncatedNodes(DotNodeDeque &queue)
Definition: dotincldepgraph.cpp:98
FileDef::getOutputFileBase
virtual QCString getOutputFileBase() const =0
util.h
A bunch of utility functions.
DotInclDepGraph::getMapLabel
virtual QCString getMapLabel() const
Definition: dotincldepgraph.cpp:172
DotNode::children
const DotNodeRefVector & children() const
Definition: dotnode.h:109
FALSE
#define FALSE
Definition: qcstring.h:33
FileDef::includeFileList
virtual const IncludeInfoList & includeFileList() const =0
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108