简体   繁体   English

Linux 中 C++ 的类层次结构/依赖关系图生成器

[英]Class hierarchy/dependency diagram generator for C++ in Linux

Is there some tool to generate class hierarchy/dependency diagrams by inspecting C++ code in Linux?是否有一些工具可以通过检查 Linux 中的 C++ 代码来生成类层次结构/依赖关系图?

I have this big collection of C++ files given to me and such a tool would be invaluable to help me understand the source code.我有一大堆 C++ 文件给我,这样的工具对于帮助我理解源代码非常有用。 I am getting a little tangled up in understanding it.我对它的理解有点纠结。

Try doxygen . 尝试doxygen It may also be shipped with your distribution. 它也可能随您的发行版一起提供。

You may need GraphViz to generate the graphs. 您可能需要GraphViz来生成图形。 There is a simple example and output . 一个简单的例子输出

And this is a more complicated example from the legend file generated by doxygen: 这是doxygen生成的图例文件中一个更复杂的例子:

Code (NOTE: if you only want to generate the graphs, the comments are not required.): 代码(注意:如果您只想生成图表,则不需要注释。):

/*! Invisible class because of truncation */
class Invisible { };

/*! Truncated class, inheritance relation is hidden */
class Truncated : public Invisible { };

/* Class not documented with doxygen comments */
class Undocumented { };

/*! Class that is inherited using public inheritance */
class PublicBase : public Truncated { };

/*! A template class */
template<class T> class Templ { };

/*! Class that is inherited using protected inheritance */
class ProtectedBase { };

/*! Class that is inherited using private inheritance */
class PrivateBase { };

/*! Class that is used by the Inherited class */
class Used { };

/*! Super class that inherits a number of other classes */
class Inherited : public PublicBase,
                  protected ProtectedBase,
                  private PrivateBase,
                  public Undocumented,
                  public Templ<int>
{
  private:
    Used *m_usedClass;
};

Result: 结果:

在此输入图像描述

You do not need to comment your code to generate these graphs. 并不需要注释你的代码来生成这些图表。 The first example has no comments at all. 第一个例子根本没有评论。 The second example has one class without doxygen style comment. 第二个例子有一个没有doxygen风格注释的类。 Just set the appropriate parameter (at least EXTRACT_ALL = YES should be set. I cannot recall whether this is all that is needed). 只需设置适当的参数(至少应设置EXTRACT_ALL = YES 。我不记得是否只需要这一点)。

There's a promising new tool called cpp-depenencies . 有一种很有前景的新工具叫做cpp-depenencies

It can generate component dependency diagrams (like below) as well as class hierarchy diagrams (by passing an option to treat each source file as a component). 它可以生成component依赖关系图(如下所示)以及class层次结构图(通过传递一个选项将每个源文件视为一个组件)。

在此输入图像描述

There's also cpp_dependency_graph , which is able to generate component/include dependency graphs in dot , d3.js or JSON formats. 还有cpp_dependency_graph ,它能够以dotd3.js或JSON格式生成组件/包含依赖关系图。

Below is an example d3.js visualisation. 下面是d3.js可视化示例。

在此输入图像描述

Disclaimer - I am the author of cpp_dependency_graph . 免责声明 - 我是cpp_dependency_graph的作者。

如果将Eclipse用作IDE,则可以使用类型层次结构来查看类层次结构。

如果你使用kdevelop,你可以安装kdevcontrolflowgraphview插件

Source Trail is an easy-to-use tool in my experience with an intuitive GUI that helps you explore the relationship between a language element and others that are related to it.根据我的经验, Source Trail是一个易于使用的工具,它具有直观的 GUI,可帮助您探索语言元素与其他相关元素之间的关系。 It worked very well for me on MacOS.它在 MacOS 上对我来说效果很好。 As of September 2021, it is no longer developed, but the repository remains available.截至 2021 年 9 月,它不再开发,但存储库仍然可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM