Skip to main content

The DotClassGraph Class Reference

Representation of a class inheritance or dependency graph. More...

Declaration

class DotClassGraph { ... }

Included Headers

Base class

classDotGraph

A dot graph. More...

Public Constructors Index

DotClassGraph (const ClassDef *cd, GraphType t)

Public Destructor Index

~DotClassGraph () override

Public Member Functions Index

boolisTrivial () const
boolisTooBig () const
intnumNodes () const
QCStringwriteGraph (TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool TBRank=TRUE, bool imageMap=TRUE, int graphId=-1)
voidwriteXML (TextStream &t)
voidwriteDocbook (TextStream &t)
voidwriteDEF (TextStream &t)

Protected Member Functions Index

QCStringgetBaseName () const override
QCStringgetMapLabel () const override
voidcomputeTheGraph () override
QCStringgetImgAltText () const override

Private Member Functions Index

voidbuildGraph (const ClassDef *cd, DotNode *n, bool base, int distance)
booldetermineVisibleNodes (DotNode *rootNode, int maxNodes, bool includeParents)
voiddetermineTruncatedNodes (DotNodeDeque &queue, bool includeParents)
voidaddClass (const ClassDef *cd, DotNode *n, EdgeInfo::Colors color, const QCString &label, const QCString &usedName, const QCString &templSpec, bool base, int distance)

Private Member Attributes Index

DotNode *m_startNode
DotNodeMapm_usedNodes
GraphTypem_graphType
QCStringm_collabFileName
QCStringm_inheritFileName
boolm_lrRank

Description

Representation of a class inheritance or dependency graph.

Definition at line 28 of file dotclassgraph.h.

Public Constructors

DotClassGraph()

DotClassGraph::DotClassGraph (const ClassDef * cd, GraphType t)

Declaration at line 31 of file dotclassgraph.h, definition at line 316 of file dotclassgraph.cpp.

317{
318 //printf("--------------- DotClassGraph::DotClassGraph '%s'\n",qPrint(cd->displayName()));
319 m_graphType = t;
320 QCString tmp_url="";
321 if (cd->isLinkable() && !cd->isHidden())
322 {
323 tmp_url=cd->getReference()+"$"+cd->getOutputFileBase();
324 if (!cd->anchor().isEmpty())
325 {
326 tmp_url+="#"+cd->anchor();
327 }
328 }
329 QCString className = cd->displayName();
330 QCString tooltip = cd->briefDescriptionAsTooltip();
331 m_startNode = new DotNode(this,
332 className,
333 tooltip,
334 tmp_url,
335 TRUE, // is a root node
336 cd
337 );
338 m_startNode->setDistance(0);
339 m_usedNodes.emplace(className.str(),m_startNode);
340
343
345 DotNodeDeque openNodeQueue;
346 openNodeQueue.push_back(m_startNode);
348
351}

References Definition::anchor, Definition::briefDescriptionAsTooltip, buildGraph, ClassDef::collaborationGraphFileName, Config_getInt, determineTruncatedNodes, determineVisibleNodes, Definition::displayName, DotGraph::DotNode, FALSE, Definition::getOutputFileBase, Definition::getReference, Inheritance, ClassDef::inheritanceGraphFileName, QCString::isEmpty, Definition::isHidden, Definition::isLinkable, m_collabFileName, m_graphType, m_inheritFileName, m_lrRank, m_startNode, m_usedNodes, QCString::str and TRUE.

Public Destructor

~DotClassGraph()

DotClassGraph::~DotClassGraph ()

Declaration at line 32 of file dotclassgraph.h, definition at line 377 of file dotclassgraph.cpp.

References DotNode::deleteNodes and m_startNode.

Public Member Functions

isTooBig()

bool DotClassGraph::isTooBig ()

Declaration at line 36 of file dotclassgraph.h, definition at line 361 of file dotclassgraph.cpp.

362{
363 return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
364}

References Config_getInt and numNodes.

Referenced by ClassDefImpl::writeCollaborationGraph and ClassDefImpl::writeInheritanceGraph.

isTrivial()

bool DotClassGraph::isTrivial ()

Declaration at line 35 of file dotclassgraph.h, definition at line 353 of file dotclassgraph.cpp.

354{
356 return m_startNode->children().empty() && m_startNode->parents().empty();
357 else
358 return !Config_getBool(UML_LOOK) && m_startNode->children().empty();
359}

References Config_getBool, Inheritance, m_graphType and m_startNode.

Referenced by generateDEFForClass, PerlModGenerator::generatePerlModForClass, generateXMLForClass, ClassDefImpl::writeCollaborationGraph and ClassDefImpl::writeInheritanceGraph.

numNodes()

int DotClassGraph::numNodes ()

Declaration at line 37 of file dotclassgraph.h, definition at line 366 of file dotclassgraph.cpp.

367{
368 size_t numNodes = 0;
369 numNodes+= m_startNode->children().size();
371 {
372 numNodes+= m_startNode->parents().size();
373 }
374 return static_cast<int>(numNodes);
375}

References Inheritance, m_graphType, m_startNode and numNodes.

Referenced by isTooBig, numNodes, ClassDefImpl::writeCollaborationGraph and ClassDefImpl::writeInheritanceGraph.

writeDEF()

void DotClassGraph::writeDEF (TextStream & t)

Declaration at line 44 of file dotclassgraph.h, definition at line 480 of file dotclassgraph.cpp.

481{
482 for (const auto &[name,node] : m_usedNodes)
483 {
484 node->writeDEF(t);
485 }
486}

Reference m_usedNodes.

Referenced by generateDEFForClass.

writeDocbook()

void DotClassGraph::writeDocbook (TextStream & t)

Declaration at line 43 of file dotclassgraph.h, definition at line 472 of file dotclassgraph.cpp.

473{
474 for (const auto &[name,node] : m_usedNodes)
475 {
476 node->writeDocbook(t,TRUE);
477 }
478}

References m_usedNodes and TRUE.

writeGraph()

QCString DotClassGraph::writeGraph (TextStream & t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString & path, const QCString & fileName, const QCString & relPath, bool TBRank=TRUE, bool imageMap=TRUE, int graphId=-1)

Declaration at line 38 of file dotclassgraph.h, definition at line 449 of file dotclassgraph.cpp.

450 GraphOutputFormat graphFormat,
451 EmbeddedOutputFormat textFormat,
452 const QCString &path,
453 const QCString &fileName,
454 const QCString &relPath,
455 bool /*isTBRank*/,
456 bool generateImageMap,
457 int graphId)
458{
459 return DotGraph::writeGraph(out, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
460}

Reference DotGraph::writeGraph.

Referenced by DocbookGenerator::endDotGraph, HtmlGenerator::endDotGraph, LatexGenerator::endDotGraph and RTFGenerator::endDotGraph.

writeXML()

void DotClassGraph::writeXML (TextStream & t)

Declaration at line 42 of file dotclassgraph.h, definition at line 464 of file dotclassgraph.cpp.

465{
466 for (const auto &[name,node] : m_usedNodes)
467 {
468 node->writeXML(t,TRUE);
469 }
470}

References m_usedNodes and TRUE.

Referenced by generateXMLForClass.

Protected Member Functions

computeTheGraph()

void DotClassGraph::computeTheGraph ()
protected virtual

Declaration at line 49 of file dotclassgraph.h, definition at line 399 of file dotclassgraph.cpp.

400{
405 m_lrRank ? "LR" : "",
407 TRUE,
408 m_startNode->label(),
410 );
411}

References DotGraph::computeGraph, Inheritance, DotGraph::m_graphFormat, m_graphType, m_lrRank, m_startNode, DotGraph::m_theGraph and TRUE.

getBaseName()

QCString DotClassGraph::getBaseName ()
protected virtual

Declaration at line 47 of file dotclassgraph.h, definition at line 382 of file dotclassgraph.cpp.

383{
384 switch (m_graphType)
385 {
387 return m_collabFileName;
388 break;
390 return m_inheritFileName;
391 break;
392 default:
393 ASSERT(0);
394 break;
395 }
396 return "";
397}

References ASSERT, Collaboration, Inheritance, m_collabFileName, m_graphType and m_inheritFileName.

getImgAltText()

QCString DotClassGraph::getImgAltText ()
protected virtual

Declaration at line 50 of file dotclassgraph.h, definition at line 432 of file dotclassgraph.cpp.

433{
434 switch (m_graphType)
435 {
437 return "Collaboration graph";
438 break;
440 return "Inheritance graph";
441 break;
442 default:
443 ASSERT(0);
444 break;
445 }
446 return "";
447}

References ASSERT, Collaboration, Inheritance and m_graphType.

getMapLabel()

QCString DotClassGraph::getMapLabel ()
protected virtual

Declaration at line 48 of file dotclassgraph.h, definition at line 413 of file dotclassgraph.cpp.

414{
415 QCString mapName;
416 switch (m_graphType)
417 {
419 mapName="coll_map";
420 break;
422 mapName="inherit_map";
423 break;
424 default:
425 ASSERT(0);
426 break;
427 }
428
430}

References ASSERT, Collaboration, escapeCharsInString, FALSE, Inheritance, m_graphType and m_startNode.

Private Member Functions

addClass()

void DotClassGraph::addClass (const ClassDef * cd, DotNode * n, EdgeInfo::Colors color, const QCString & label, const QCString & usedName, const QCString & templSpec, bool base, int distance)

Declaration at line 56 of file dotclassgraph.h, definition at line 26 of file dotclassgraph.cpp.

27 const QCString &label,const QCString &usedName,const QCString &templSpec,bool base,int distance)
28{
29 if (Config_getBool(HIDE_UNDOC_CLASSES) && !cd->isLinkable()) return;
30
32 QCString className;
33 QCString fullName;
34 if (cd->isAnonymous())
35 {
36 className="anonymous:";
37 className+=label;
38 fullName = className;
39 }
40 else if (!usedName.isEmpty()) // name is a typedef
41 {
42 className=usedName;
43 fullName = className;
44 }
45 else if (!templSpec.isEmpty()) // name has a template part
46 {
47 className=insertTemplateSpecifierInScope(cd->displayName(),templSpec);
48 fullName =insertTemplateSpecifierInScope(cd->name(),templSpec);
49 }
50 else // just a normal name
51 {
52 className=cd->displayName();
53 fullName = cd->name();
54 }
55 //printf("DotClassGraph::addClass(class='%s',parent=%s,prot=%d,label=%s,dist=%d,usedName=%s,templSpec=%s,base=%d)\n",
56 // qPrint(className),qPrint(n->label()),prot,label,distance,usedName,templSpec,base);
57 auto it = m_usedNodes.find(fullName.str());
58 if (it!=m_usedNodes.end()) // class already inserted
59 {
60 DotNode *bn = it->second;
61 if (base)
62 {
63 n->addChild(bn,color,edgeStyle,label);
64 bn->addParent(n);
65 }
66 else
67 {
68 bn->addChild(n,color,edgeStyle,label);
69 n->addParent(bn);
70 }
71 bn->setDistance(distance);
72 //printf(" add exiting node %s of %s\n",qPrint(bn->label()),qPrint(n->label()));
73 }
74 else // new class
75 {
76 QCString displayName=className;
77 if (Config_getBool(HIDE_SCOPE_NAMES)) displayName=stripScope(displayName);
78 QCString tmp_url;
79 if (cd->isLinkable() && !cd->isHidden())
80 {
81 tmp_url=cd->getReference()+"$"+cd->getOutputFileBase();
82 if (!cd->anchor().isEmpty())
83 {
84 tmp_url+="#"+cd->anchor();
85 }
86 }
88 DotNode *bn = new DotNode(this,
89 displayName,
90 tooltip,
91 tmp_url,
92 FALSE, // rootNode
93 cd
94 );
95 if (base)
96 {
97 n->addChild(bn,color,edgeStyle,label);
98 bn->addParent(n);
99 }
100 else
101 {
102 bn->addChild(n,color,edgeStyle,label);
103 n->addParent(bn);
104 }
105 bn->setDistance(distance);
106 m_usedNodes.emplace(fullName.str(),bn);
107 //printf(" add new child node '%s' to %s hidden=%d url=%s\n",
108 // qPrint(className),qPrint(n->label()),cd->isHidden(),qPrint(tmp_url));
109
110 buildGraph(cd,bn,base,distance+1);
111 }
112}

References DotNode::addChild, DotNode::addParent, Definition::anchor, Definition::briefDescriptionAsTooltip, buildGraph, Config_getBool, EdgeInfo::Dashed, Definition::displayName, DotGraph::DotNode, FALSE, Definition::getOutputFileBase, Definition::getReference, insertTemplateSpecifierInScope, Definition::isAnonymous, QCString::isEmpty, Definition::isHidden, Definition::isLinkable, m_usedNodes, Definition::name, EdgeInfo::Orange, EdgeInfo::Orange2, DotNode::setDistance, EdgeInfo::Solid, QCString::str and stripScope.

Referenced by buildGraph.

buildGraph()

void DotClassGraph::buildGraph (const ClassDef * cd, DotNode * n, bool base, int distance)

Declaration at line 53 of file dotclassgraph.h, definition at line 252 of file dotclassgraph.cpp.

252void DotClassGraph::buildGraph(const ClassDef *cd,DotNode *n,bool base,int distance)
253{
254 //printf("DocClassGraph::buildGraph(%s,distance=%d,base=%d)\n",
255 // qPrint(cd->name()),distance,base);
256 // ---- Add inheritance relations
257
259 {
260 for (const auto &bcd : base ? cd->baseClasses() : cd->subClasses())
261 {
262 //printf("-------- inheritance relation %s->%s templ='%s'\n",
263 // qPrint(cd->name()),qPrint(bcd->classDef->name()),qPrint(bcd->templSpecifiers));
264 addClass(bcd.classDef,n,EdgeInfo::protectionToColor(bcd.prot),QCString(),bcd.usedName,bcd.templSpecifiers,base,distance);
265 }
266 }
268 {
269 // ---- Add usage relations
270
271 const UsesClassList &list = base ? cd->usedImplementationClasses() :
273 for (const auto &ucd : list)
274 {
275 //printf("addClass: %s templSpec=%s\n",qPrint(ucd.classDef->name()),qPrint(ucd.templSpecifiers));
276 addClass(ucd.classDef,n,EdgeInfo::Purple,joinLabels(ucd.accessors),QCString(),
277 ucd.templSpecifiers,base,distance);
278 }
279 }
280 if (Config_getBool(TEMPLATE_RELATIONS) && base)
281 {
282 for (const auto &ccd : cd->templateTypeConstraints())
283 {
284 //printf("addClass: %s\n",qPrint(ccd.classDef->name()));
285 addClass(ccd.classDef,n,EdgeInfo::Orange2,joinLabels(ccd.accessors),QCString(),
286 QCString(),TRUE,distance);
287 }
288 }
289
290 // ---- Add template instantiation relations
291
292 if (Config_getBool(TEMPLATE_RELATIONS))
293 {
294 if (base) // template relations for base classes
295 {
296 const ClassDef *templMaster=cd->templateMaster();
297 if (templMaster)
298 {
299 for (const auto &ti : templMaster->getTemplateInstances())
300 if (ti.classDef==cd)
301 {
302 addClass(templMaster,n,EdgeInfo::Orange,ti.templSpec,QCString(),QCString(),TRUE,distance);
303 }
304 }
305 }
306 else // template relations for super classes
307 {
308 for (const auto &ti : cd->getTemplateInstances())
309 {
310 addClass(ti.classDef,n,EdgeInfo::Orange,ti.templSpec,QCString(),QCString(),FALSE,distance);
311 }
312 }
313 }
314}

References addClass, ClassDef::baseClasses, Collaboration, Config_getBool, DotGraph::DotNode, FALSE, ClassDef::getTemplateInstances, Inheritance, joinLabels, m_graphType, EdgeInfo::Orange, EdgeInfo::Orange2, EdgeInfo::protectionToColor, EdgeInfo::Purple, ClassDef::subClasses, ClassDef::templateMaster, ClassDef::templateTypeConstraints, TRUE, ClassDef::usedByImplementationClasses and ClassDef::usedImplementationClasses.

Referenced by addClass and DotClassGraph.

determineTruncatedNodes()

void DotClassGraph::determineTruncatedNodes (DotNodeDeque & queue, bool includeParents)

Declaration at line 55 of file dotclassgraph.h, definition at line 114 of file dotclassgraph.cpp.

115{
116 while (!queue.empty())
117 {
118 DotNode *n = queue.front();
119 queue.pop_front();
120 if (n->isVisible() && n->isTruncated()==DotNode::Unknown)
121 {
122 bool truncated = FALSE;
123 for (const auto &dn : n->children())
124 {
125 if (!dn->isVisible())
126 truncated = TRUE;
127 else
128 queue.push_back(dn);
129 }
130 if (includeParents)
131 {
132 for (const auto &dn : n->parents())
133 {
134 if (!dn->isVisible())
135 truncated = TRUE;
136 else
137 queue.push_back(dn);
138 }
139 }
140 n->markAsTruncated(truncated);
141 }
142 }
143}

References DotNode::children, DotGraph::DotNode, FALSE, DotNode::isTruncated, DotNode::isVisible, DotNode::markAsTruncated, DotNode::parents, TRUE and DotNode::Unknown.

Referenced by DotClassGraph.

determineVisibleNodes()

bool DotClassGraph::determineVisibleNodes (DotNode * rootNode, int maxNodes, bool includeParents)

Declaration at line 54 of file dotclassgraph.h, definition at line 145 of file dotclassgraph.cpp.

146 int maxNodes,bool includeParents)
147{
148 DotNodeDeque childQueue;
149 DotNodeDeque parentQueue;
150 std::vector<size_t> childTreeWidth;
151 std::vector<size_t> parentTreeWidth;
152 childQueue.push_back(rootNode);
153 if (includeParents) parentQueue.push_back(rootNode);
154 bool firstNode=TRUE; // flag to force reprocessing rootNode in the parent loop
155 // despite being marked visible in the child loop
156 while ((!childQueue.empty() || !parentQueue.empty()) && maxNodes>0)
157 {
158 if (!childQueue.empty())
159 {
160 DotNode *n = childQueue.front();
161 childQueue.pop_front();
162 size_t distance = n->distance();
163 if (!n->isVisible() && distance<=static_cast<size_t>(Config_getInt(MAX_DOT_GRAPH_DEPTH))) // not yet processed
164 {
165 if (distance>0)
166 {
167 size_t oldSize=childTreeWidth.size();
168 if (distance>oldSize)
169 {
170 childTreeWidth.resize(std::max(childTreeWidth.size(),distance));
171 for (size_t i=oldSize;i<distance;i++) childTreeWidth[i]=0;
172 }
173 childTreeWidth[distance-1]+=n->label().length();
174 }
175 n->markAsVisible();
176 maxNodes--;
177 // add direct children
178 for (const auto &dn : n->children())
179 {
180 childQueue.push_back(dn);
181 }
182 }
183 }
184 if (includeParents && !parentQueue.empty())
185 {
186 DotNode *n = parentQueue.front();
187 parentQueue.pop_front();
188 if ((!n->isVisible() || firstNode) && n->distance()<=Config_getInt(MAX_DOT_GRAPH_DEPTH)) // not yet processed
189 {
190 firstNode=FALSE;
191 size_t distance = n->distance();
192 if (distance>0)
193 {
194 size_t oldSize = parentTreeWidth.size();
195 if (distance>oldSize)
196 {
197 parentTreeWidth.resize(std::max(parentTreeWidth.size(),distance));
198 for (size_t i=oldSize;i<distance;i++) parentTreeWidth[i]=0;
199 }
200 parentTreeWidth[distance-1]+=n->label().length();
201 }
202 n->markAsVisible();
203 maxNodes--;
204 // add direct parents
205 for (const auto &dn : n->parents())
206 {
207 parentQueue.push_back(dn);
208 }
209 }
210 }
211 }
212 if (Config_getBool(UML_LOOK)) return FALSE; // UML graph are always top to bottom
213 size_t maxWidth=0;
214 size_t maxHeight=std::max(childTreeWidth.size(),parentTreeWidth.size());
215 for (size_t i=0;i<childTreeWidth.size();i++)
216 {
217 if (childTreeWidth.at(i)>maxWidth) maxWidth=childTreeWidth.at(i);
218 }
219 for (size_t i=0;i<parentTreeWidth.size();i++)
220 {
221 if (parentTreeWidth.at(i)>maxWidth) maxWidth=parentTreeWidth.at(i);
222 }
223 //printf("max tree width=%d, max tree height=%d\n",maxWidth,maxHeight);
224 return maxWidth>80 && maxHeight<12; // used metric to decide to render the tree
225 // from left to right instead of top to bottom,
226 // with the idea to render very wide trees in
227 // left to right order.
228}

References DotNode::children, Config_getBool, Config_getInt, DotNode::distance, DotGraph::DotNode, FALSE, DotNode::isVisible, DotNode::label, QCString::length, DotNode::markAsVisible, DotNode::parents and TRUE.

Referenced by DotClassGraph.

Private Member Attributes

m_collabFileName

QCString DotClassGraph::m_collabFileName

Definition at line 63 of file dotclassgraph.h.

Referenced by DotClassGraph and getBaseName.

m_graphType

GraphType DotClassGraph::m_graphType

m_inheritFileName

QCString DotClassGraph::m_inheritFileName

Definition at line 64 of file dotclassgraph.h.

Referenced by DotClassGraph and getBaseName.

m_lrRank

bool DotClassGraph::m_lrRank

Definition at line 65 of file dotclassgraph.h.

65 bool m_lrRank;

Referenced by computeTheGraph and DotClassGraph.

m_startNode

DotNode* DotClassGraph::m_startNode

m_usedNodes

DotNodeMap DotClassGraph::m_usedNodes

Definition at line 61 of file dotclassgraph.h.

Referenced by addClass, DotClassGraph, writeDEF, writeDocbook and writeXML.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.