Doxygen
Loading...
Searching...
No Matches
DotGfxHierarchyTable Class Referencefinal

Represents a graphical class hierarchy. More...

#include <src/dotgfxhierarchytable.h>

Inheritance diagram for DotGfxHierarchyTable:
Collaboration diagram for DotGfxHierarchyTable:

Public Member Functions

 DotGfxHierarchyTable (const DString &prefix="", ClassDef::CompoundType ct=ClassDef::Class)
 ~DotGfxHierarchyTable () override=default
void createGraph (DotNode *rootNode, TextStream &t, const DString &path, const DString &fileName, int id)
void writeGraph (TextStream &t, const DString &path, const DString &fileName)
const std::vector< DotNode * > subGraphs () const
Public Member Functions inherited from DotGraph
 DotGraph ()
virtual ~DotGraph ()=default

Protected Member Functions

DString getBaseName () const override
DString getMapLabel () const override
void computeTheGraph () override
Protected Member Functions inherited from DotGraph
int getNextNodeNumber ()
 returns the node number.
int getNextEdgeNumber ()
 returns the edge number.
DString writeGraph (TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
virtual DString absMapName () const
virtual DString getImgAltText () const
DString absBaseName () const
DString absDotName () const
DString imgName () const
DString absImgName () const
DString relImgName () const

Private Types

using DotNodeMap = std::unordered_multimap< std::string, std::unique_ptr<DotNode> >

Private Member Functions

void addHierarchy (DotNode *n, const ClassDef *cd, ClassDefSet &visited)
void addClassList (const ClassLinkedMap &cl, ClassDefSet &visited)

Private Attributes

int m_graphId
DString m_prefix
ClassDef::CompoundType m_classType
std::vector< DotNode * > m_rootNodes
DotNodeMap m_usedNodes
std::vector< DotNode * > m_rootSubgraphs
DotNodem_rootSubgraphNode

Additional Inherited Members

Static Protected Member Functions inherited from DotGraph
static void writeGraphHeader (TextStream &t, const DString &title=DString())
static void writeGraphFooter (TextStream &t)
static void computeGraph (DotNode *root, GraphType gt, GraphOutputFormat format, const DString &rank, bool renderParents, bool backArrows, const DString &title, DString &graphStr)
Protected Attributes inherited from DotGraph
GraphOutputFormat m_graphFormat = GraphOutputFormat::BITMAP
EmbeddedOutputFormat m_textFormat = EmbeddedOutputFormat::Html
Dir m_dir
DString m_fileName
DString m_relPath
bool m_generateImageMap = false
int m_graphId = 0
DString m_absPath
DString m_baseName
DString m_theGraph
bool m_regenerate = false
bool m_doNotAddImageToIndex = false
bool m_noDivTag = false
bool m_zoomable = true
bool m_urlOnly = false

Detailed Description

Represents a graphical class hierarchy.

Definition at line 31 of file dotgfxhierarchytable.h.

Member Typedef Documentation

◆ DotNodeMap

using DotGfxHierarchyTable::DotNodeMap = std::unordered_multimap< std::string, std::unique_ptr<DotNode> >
private

Definition at line 52 of file dotgfxhierarchytable.h.

Constructor & Destructor Documentation

◆ DotGfxHierarchyTable()

DotGfxHierarchyTable::DotGfxHierarchyTable ( const DString & prefix = "",
ClassDef::CompoundType ct = ClassDef::Class )

Definition at line 226 of file dotgfxhierarchytable.cpp.

228 , m_classType(ct)
229{
230 // build a graph with each class as a node and the inheritance relations
231 // as edges
232 ClassDefSet visitedClasses;
233 addClassList(*Doxygen::classLinkedMap,visitedClasses);
235 // m_usedNodes now contains all nodes in the graph
236
237 // color the graph into a set of independent subgraphs
238 bool done=false;
239 int curColor=0;
240 while (!done) // there are still nodes to color
241 {
242 done=true; // we are done unless there are still uncolored nodes
243 for (auto n : m_rootNodes)
244 {
245 if (n->subgraphId()==-1) // not yet colored
246 {
247 //printf("Starting at node %s (%p): %d\n",qPrint(n->label()),n,curColor);
248 done=false; // still uncolored nodes
249 n->setSubgraphId(curColor);
250 n->markAsVisible();
251 n->colorConnectedNodes(curColor);
252 curColor++;
253 m_rootSubgraphs.push_back(n);
254 }
255 }
256 }
257
258 //printf("Number of independent subgraphs: %d\n",curColor);
259 for (auto n : m_rootSubgraphs)
260 {
261 //printf("Node %s color=%d (c=%d,p=%d)\n",
262 // qPrint(n->label()),n->m_subgraphId,
263 // n->children()?n->children()->count():0,
264 // n->parents()?n->parents()->count():0);
265 int number=0;
266 n->renumberNodes(number);
267 }
268}
constexpr auto prefix
Definition anchor.cpp:44
std::vector< DotNode * > m_rootSubgraphs
void addClassList(const ClassLinkedMap &cl, ClassDefSet &visited)
ClassDef::CompoundType m_classType
std::vector< DotNode * > m_rootNodes
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:95
static ClassLinkedMap * hiddenClassLinkedMap
Definition doxygen.h:96
std::unordered_set< const ClassDef * > ClassDefSet
Definition classdef.h:95

References addClassList(), Doxygen::classLinkedMap, Doxygen::hiddenClassLinkedMap, m_classType, m_prefix, m_rootNodes, m_rootSubgraphs, and prefix.

Referenced by ~DotGfxHierarchyTable().

◆ ~DotGfxHierarchyTable()

DotGfxHierarchyTable::~DotGfxHierarchyTable ( )
overridedefault

Member Function Documentation

◆ addClassList()

void DotGfxHierarchyTable::addClassList ( const ClassLinkedMap & cl,
ClassDefSet & visited )
private

Definition at line 179 of file dotgfxhierarchytable.cpp.

180{
181 for (const auto &cd : cl)
182 {
183 //printf("Trying %s subClasses=%d\n",qPrint(cd->name()),cd->subClasses()->count());
184 if (cd->getLanguage()==SrcLangExt::VHDL &&
186 )
187 {
188 continue;
189 }
190 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE) && cd->compoundType() != m_classType)
191 {
192 continue;
193 }
194 if (!classHasVisibleRoot(cd->baseClasses()) &&
195 cd->isVisibleInHierarchy()
196 ) // root node in the forest
197 {
198 DString tmp_url="";
199 if (cd->isLinkable() && !cd->isHidden())
200 {
201 tmp_url=cd->getReference()+"$"+cd->getOutputFileBase();
202 if (!cd->anchor().empty())
203 {
204 tmp_url+="#"+cd->anchor();
205 }
206 }
207 //printf("Inserting root class %s\n",qPrint(cd->name()));
208 DString tooltip = cd->briefDescriptionAsTooltip();
209 auto n = std::make_unique<DotNode>(this,
210 cd->displayName(),
211 tooltip,
212 tmp_url);
213 DotNode *root = n.get();
214
215 m_usedNodes.emplace(cd->name().str(),std::move(n));
216 m_rootNodes.push_back(root);
217 if (visitedClasses.find(cd.get())==visitedClasses.end() && !cd->subClasses().empty())
218 {
219 addHierarchy(root,cd.get(),visitedClasses);
220 visitedClasses.insert(cd.get());
221 }
222 }
223 }
224}
void addHierarchy(DotNode *n, const ClassDef *cd, ClassDefSet &visited)
friend class DotNode
Definition dotgraph.h:36
static VhdlClasses convert(Protection prot)
Definition vhdldocgen.h:80
bool classHasVisibleRoot(const BaseClassList &bcl)
#define Config_getBool(name)
Definition config.h:33

References addHierarchy(), classHasVisibleRoot(), Config_getBool, VhdlDocGen::convert(), DotGraph::DotNode, VhdlDocGen::ENTITYCLASS, m_classType, m_rootNodes, and m_usedNodes.

Referenced by DotGfxHierarchyTable().

◆ addHierarchy()

void DotGfxHierarchyTable::addHierarchy ( DotNode * n,
const ClassDef * cd,
ClassDefSet & visited )
private

Definition at line 105 of file dotgfxhierarchytable.cpp.

106{
107 //printf("addHierarchy '%s' baseClasses=%d\n",qPrint(cd->name()),cd->baseClasses()->count());
108 for (const auto &bcd : cd->subClasses())
109 {
110 ClassDef *bClass=bcd.classDef;
111 //printf(" Trying sub class='%s' usedNodes=%d\n",qPrint(bClass->name()),m_usedNodes->count());
112 if (bClass && bClass->isVisibleInHierarchy() && classHasVisibleRoot(bClass->baseClasses()))
113 {
114 auto it = m_usedNodes.find(bClass->name().str());
115 //printf(" Node '%s' Found visible class='%s'\n",qPrint(n->label()),
116 // qPrint(bClass->name()));
117 DotNode *root = nullptr;
118 if (it!=m_usedNodes.end()) // node already present
119 {
120 const auto &bn = it->second;
121 root = bn.get();
122 const auto &children = n->children();
123 auto child_it = std::find(children.begin(),children.end(),bn.get());
124 if (child_it==children.end()) // no arrow yet
125 {
126 n->addChild(bn.get(),EdgeInfo::protectionToColor(bcd.prot));
127 bn->addParent(n);
128 //printf(" Adding node %s to existing base node %s (c=%d,p=%d)\n",
129 // qPrint(n->label()),
130 // qPrint(bn->label()),
131 // bn->children() ? bn->children()->count() : 0,
132 // bn->parents() ? bn->parents()->count() : 0
133 // );
134 }
135 //else
136 //{
137 // printf(" Class already has an arrow!\n");
138 //}
139 }
140 else
141 {
142 DString tmp_url="";
143 if (bClass->isLinkable() && !bClass->isHidden())
144 {
145 tmp_url=bClass->getReference()+"$"+bClass->getOutputFileBase();
146 if (!bClass->anchor().empty())
147 {
148 tmp_url+="#"+bClass->anchor();
149 }
150 }
151 DString tooltip = bClass->briefDescriptionAsTooltip();
152 auto bn = std::make_unique<DotNode>(this,
153 bClass->displayName(),
154 tooltip,
155 tmp_url
156 );
157 n->addChild(bn.get(),EdgeInfo::protectionToColor(bcd.prot));
158 bn->addParent(n);
159 root = bn.get();
160 //printf(" Adding node %s to new base node %s (c=%d,p=%d)\n",
161 // qPrint(n->label()),
162 // qPrint(bn->label()),
163 // bn->children() ? bn->children()->count() : 0,
164 // bn->parents() ? bn->parents()->count() : 0
165 // );
166 //printf(" inserting %s (%p)\n",qPrint(bClass->name()),bn);
167 m_usedNodes.emplace(bClass->name().str(),std::move(bn)); // add node to the used list
168 }
169 if (visitedClasses.find(bClass)==visitedClasses.end() && !bClass->subClasses().empty())
170 {
171 visitedClasses.insert(bClass);
172 addHierarchy(root,bClass,visitedClasses);
173 }
174 }
175 }
176 //printf("end addHierarchy\n");
177}
virtual bool isVisibleInHierarchy() const =0
the class is visible in a class diagram, or class hierarchy
virtual const BaseClassList & baseClasses() const =0
Returns the list of base classes from which this class directly inherits.
virtual const BaseClassList & subClasses() const =0
Returns the list of sub classes that directly derive from this class.
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:153
const std::string & str() const
Definition dstring.h:634
virtual bool isLinkable() const =0
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual DString displayName(bool includeScope=true) const =0
virtual bool isHidden() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual DString getOutputFileBase() const =0
void addChild(DotNode *n, EdgeInfo::Colors edgeColor=EdgeInfo::Purple, EdgeInfo::Styles edgeStyle=EdgeInfo::Solid, const DString &edgeLab=DString(), const DString &edgeURL=DString(), int edgeLabColor=-1)
Definition dotnode.cpp:338
const DotNodeRefVector & children() const
Definition dotnode.h:123
static constexpr Colors protectionToColor(Protection prot)
Definition dotnode.h:44

References DotNode::addChild(), addHierarchy(), Definition::anchor(), ClassDef::baseClasses(), Definition::briefDescriptionAsTooltip(), DotNode::children(), classHasVisibleRoot(), Definition::displayName(), DotGraph::DotNode, DString::empty(), Definition::getOutputFileBase(), Definition::getReference(), Definition::isHidden(), Definition::isLinkable(), ClassDef::isVisibleInHierarchy(), m_usedNodes, Definition::name(), EdgeInfo::protectionToColor(), DString::str(), and ClassDef::subClasses().

Referenced by addClassList(), and addHierarchy().

◆ computeTheGraph()

void DotGfxHierarchyTable::computeTheGraph ( )
overrideprotectedvirtual

Implements DotGraph.

Definition at line 37 of file dotgfxhierarchytable.cpp.

38{
39 TextStream md5stream;
41 md5stream << " rankdir=\"LR\";\n";
42 for (auto node : m_rootNodes)
43 {
44 if (node->subgraphId()==m_rootSubgraphNode->subgraphId())
45 {
46 node->clearWriteFlag();
47 }
48 }
49 for (auto node : m_rootNodes)
50 {
51 if (node->subgraphId()==m_rootSubgraphNode->subgraphId())
52 {
53 node->write(md5stream,GraphType::Hierarchy,GraphOutputFormat::BITMAP,false,true,true);
54 }
55 }
56 writeGraphFooter(md5stream);
57 m_theGraph = md5stream.str();
58}
DString m_theGraph
Definition dotgraph.h:95
static void writeGraphFooter(TextStream &t)
Definition dotgraph.cpp:293
static void writeGraphHeader(TextStream &t, const DString &title=DString())
Definition dotgraph.cpp:268
int subgraphId() const
Definition dotnode.h:108
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
virtual DString trGraphicalHierarchy()=0
@ Hierarchy
Definition dotgraph.h:31
Translator * theTranslator
Definition language.cpp:71

References BITMAP, Hierarchy, m_rootNodes, m_rootSubgraphNode, DotGraph::m_theGraph, TextStream::str(), DotNode::subgraphId(), theTranslator, Translator::trGraphicalHierarchy(), DotGraph::writeGraphFooter(), and DotGraph::writeGraphHeader().

◆ createGraph()

void DotGfxHierarchyTable::createGraph ( DotNode * rootNode,
TextStream & t,
const DString & path,
const DString & fileName,
int id )

Definition at line 65 of file dotgfxhierarchytable.cpp.

67{
69 m_graphId = id;
70 m_noDivTag = true;
71 m_zoomable = false;
73}
bool m_noDivTag
Definition dotgraph.h:98
bool m_zoomable
Definition dotgraph.h:99
DString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
Definition dotgraph.cpp:113

References BITMAP, DotGraph::DotNode, Html, m_graphId, DotGraph::m_noDivTag, m_rootSubgraphNode, DotGraph::m_zoomable, and DotGraph::writeGraph().

Referenced by writeGraph(), and ~DotGfxHierarchyTable().

◆ getBaseName()

DString DotGfxHierarchyTable::getBaseName ( ) const
overrideprotectedvirtual

Implements DotGraph.

Definition at line 27 of file dotgfxhierarchytable.cpp.

28{
29 DString baseName;
30 if (m_prefix.empty())
31 baseName.sprintf("inherit_graph_%d", m_graphId);
32 else
33 baseName.sprintf("%sinherit_graph_%d",qPrint(m_prefix), m_graphId);
34 return baseName;
35}
DString & sprintf(const char *format,...)
Definition dstring.cpp:29
const char * qPrint(const char *s)
Definition dstring.h:772

References DString::empty(), m_graphId, m_prefix, qPrint(), and DString::sprintf().

◆ getMapLabel()

DString DotGfxHierarchyTable::getMapLabel ( ) const
overrideprotectedvirtual

Implements DotGraph.

Definition at line 60 of file dotgfxhierarchytable.cpp.

61{
63}
DString label() const
Definition dotnode.h:103
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2755

References escapeCharsInString(), DotNode::label(), and m_rootSubgraphNode.

◆ subGraphs()

const std::vector< DotNode * > DotGfxHierarchyTable::subGraphs ( ) const
inline

Definition at line 41 of file dotgfxhierarchytable.h.

41{ return m_rootSubgraphs; }

References m_rootSubgraphs.

◆ writeGraph()

void DotGfxHierarchyTable::writeGraph ( TextStream & t,
const DString & path,
const DString & fileName )

Definition at line 75 of file dotgfxhierarchytable.cpp.

77{
78 //printf("DotGfxHierarchyTable::writeGraph(%s)\n",name);
79 //printf("m_rootNodes=%p count=%d\n",m_rootNodes,m_rootNodes->count());
80
81 if (m_rootSubgraphs.empty()) return;
82
83 Dir d(path.str());
84 // store the original directory
85 if (!d.exists())
86 {
87 term("Output dir {} does not exist!\n",path);
88 }
89
90 // put each connected subgraph of the hierarchy in a row of the HTML output
91 out << "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">\n";
92
93 int count=0;
94 std::stable_sort(m_rootSubgraphs.begin(),m_rootSubgraphs.end(),
95 [](auto n1,auto n2) { return dstricmp_sort(n1->label(),n2->label())<0; });
96 for (auto n : m_rootSubgraphs)
97 {
98 out << "<tr><td>";
99 createGraph(n,out,path,fileName,count++);
100 out << "</td></tr>\n";
101 }
102 out << "</table>\n";
103}
void createGraph(DotNode *rootNode, TextStream &t, const DString &path, const DString &fileName, int id)
#define term(fmt,...)
Definition message.h:137

References createGraph(), Dir::exists(), m_rootSubgraphs, DString::str(), and term.

Referenced by HtmlGenerator::writeGraphicalHierarchy(), and ~DotGfxHierarchyTable().

Member Data Documentation

◆ m_classType

ClassDef::CompoundType DotGfxHierarchyTable::m_classType
private

Definition at line 55 of file dotgfxhierarchytable.h.

Referenced by addClassList(), and DotGfxHierarchyTable().

◆ m_graphId

int DotGfxHierarchyTable::m_graphId
private

Definition at line 53 of file dotgfxhierarchytable.h.

Referenced by createGraph(), and getBaseName().

◆ m_prefix

DString DotGfxHierarchyTable::m_prefix
private

Definition at line 54 of file dotgfxhierarchytable.h.

Referenced by DotGfxHierarchyTable(), and getBaseName().

◆ m_rootNodes

std::vector<DotNode*> DotGfxHierarchyTable::m_rootNodes
private

Definition at line 56 of file dotgfxhierarchytable.h.

Referenced by addClassList(), computeTheGraph(), and DotGfxHierarchyTable().

◆ m_rootSubgraphNode

DotNode* DotGfxHierarchyTable::m_rootSubgraphNode
private

Definition at line 59 of file dotgfxhierarchytable.h.

Referenced by computeTheGraph(), createGraph(), and getMapLabel().

◆ m_rootSubgraphs

std::vector<DotNode*> DotGfxHierarchyTable::m_rootSubgraphs
private

Definition at line 58 of file dotgfxhierarchytable.h.

Referenced by DotGfxHierarchyTable(), subGraphs(), and writeGraph().

◆ m_usedNodes

DotNodeMap DotGfxHierarchyTable::m_usedNodes
private

Definition at line 57 of file dotgfxhierarchytable.h.

Referenced by addClassList(), and addHierarchy().


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