如何使用 doxygen 从 C++ 创建 UML 类图来源

发布于 2024-10-13 03:46:26 字数 183 浏览 15 评论 0原文

我一直在寻找一些描述如何使用 doxygen 生成简单类图的材料,但找不到。

我需要从一组 C++ 文件创建如下所示的 UML 类图:

alt text

任何人都可以帮我调整 doxygen 到生成这样的图?

I have been searching for some material that describes how to generate simple class diagrams with doxygen, but couldn't find one.

I need to create UML class diagrams as shown below from a set of C++ files:

alt text

Can anybody help me tweak doxygen to generate such graphs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

↙厌世 2024-10-20 03:46:27

得票最高的 2 个答案是正确的。截至今天,我唯一需要更改的(默认设置)是使用点而不是内置生成器启用生成。

一些重要注意事项:

  • Doxygen 不会生成项目中所有类的实际完整图表。它将为每个层次结构生成一个单独的图像。如果您有多个不相关的类层次结构,您将获得多个图像。
  • 所有这些图表都可以在 html/inherits.html 或(从网站导航)classes => 中找到。类层次结构 => “转到文本类层次结构”。
  • 这是一个C++问题,所以我们来谈谈模板。特别是如果您继承自 T
    • 每个模板实例都会被 Doxygen 正确地视为不同的类型。从不同实例继承的类型在图中将具有不同的父类。
    • 如果类模板 foo 继承自 T 并且 T 模板类型参数具有默认值,则将采用该默认值。如果有一个继承自 foo 的类型 bar,其中 U 与默认值不同,则 bar将有一个 foo 父级。 foo<>bar 将没有共同的父级。
    • 如果有多个类模板至少从其中一个模板参数继承,只要模板类型参数在代码中具有完全相同的名称,Doxygen 就会为这些类模板假定一个共同的父级。这会激励命名的一致性。
    • CRTP 和反向 CRTP 正常工作。
    • 递归模板继承树不会扩展。任何 variant 实例化都将显示为继承自 variant
    • 正在绘制没有实例化的类模板。它们的名称中将包含一个 <...> 字符串,表示没有默认值的类型和非类型参数。
    • 类模板的完整和部分特化也正在绘制中。如果特化继承自不同类型,Doxygen 会生成正确的图。

The 2 highest upvoted answers are correct. As of today, the only thing I needed to change (from default settings) was to enable generation using dot instead of the built-in generator.

Some important notes:

  • Doxygen will not generate an actual full diagram of all classes in the project. It will generate a separate image for each hierarchy. If you have multiple, unrelated class hierarchies you will get multiple images.
  • All these diagrams can be found in html/inherits.html or (from the website navigation) classes => class hierarchy => "Go to the textual class hierarchy".
  • This is a C++ question, so let's talk about templates. Especially if you inherit from T.
    • Each template instantiation will be correctly considered a different type by Doxygen. Types which inherit from different instantations will have different parent classes on the diagram.
    • If a class template foo inherits from T and the T template type parameter has a default, such default will be assumed. If there is a type bar which inherits from foo<U> where U is different than the default, bar will have a foo<U> parent. foo<> and bar<U> will not have a common parent.
    • If there are multiple class templates which inherit from at least one of their template parameters, Doxygen will assume a common parent for these class templates as long as the template type parameters have exactly the same names in the code. This incentivizes for consistency in naming.
    • CRTP and reverse CRTP just work.
    • Recursive template inheritance trees are not expanded. Any variant instantiation will be displayed to inherit from variant<Ts...>.
    • Class templates with no instantiations are being drawn. They will have a <...> string in their name representing type and non-type parameters which did not have defaults.
    • Class template full and partial specializations are also being drawn. Doxygen generates correct graphs if specializations inherit from different types.
玉环 2024-10-20 03:46:27

我认为您需要编辑 doxys 文件并将 GENERATE_UML (类似的东西)设置为 true。并且您需要安装 dot/graphviz。

I think you will need to edit the doxys file and set GENERATE_UML (something like that) to true. And you need to have dot/graphviz installed.

黄昏下泛黄的笔记 2024-10-20 03:46:26

嗯,这似乎是一个老问题了,但是由于我最近几天一直在摆弄 Doxygen 配置,而我的脑子里仍然充满了当前的信息,让我们来尝试一下 -

我认为之前的答案几乎已经it:

缺少的选项是在 Doxyfile 中添加 COLLABORATION_GRAPH = YES。我假设你可以在 doxywizard GUI 中的某个地方做同样的事情(我不使用 doxywizard)。

因此,作为一个更完整的示例,我倾向于使用的与 UML 输出相关的典型“Doxyfile”选项是:

EXTRACT_ALL          = YES
CLASS_DIAGRAMS      = YES
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT             = YES
CLASS_GRAPH          = YES
COLLABORATION_GRAPH  = YES
UML_LOOK             = YES
UML_LIMIT_NUM_FIELDS = 50
TEMPLATE_RELATIONS   = YES
DOT_GRAPH_MAX_NODES  = 100
MAX_DOT_GRAPH_DEPTH  = 0
DOT_TRANSPARENT      = YES

这些设置将生成“继承”(CLASS_GRAPH=YES) 和“协作”(<代码>COLLABORATION_GRAPH=YES)图表。

根据 doxygen 输出“部署”的目标,设置 DOT_IMAGE_FORMAT = svg 也可能有用。使用 svg 输出,图表是“可缩放的”,而不是像 .png 这样的位图格式的固定分辨率。显然,如果在 IE 以外的浏览器中查看输出,还有 INTERACTIVE_SVG = YES ,这将允许生成的 svg 图表“交互式缩放和平移”。我前段时间确实尝试过,svg 输出在视觉上非常有吸引力,但当时浏览器对 svg 的支持仍然有点不一致,所以希望这种情况最近可能有所改善。

正如其他评论所提到的,其中一些设置(特别是 DOT_GRAPH_MAX_NODES)确实具有潜在的性能影响,所以 YMMV。

我倾向于讨厌“RTFM”风格的答案,所以对这句话表示歉意,但在这种情况下,Doxygen 文档确实是你的朋友,所以请查看有关上述设置的 Doxygen 文档 - 上次我查看时,你可以在以下位置找到详细信息: http://www.doxygen.nl/manual/config.html

Hmm, this seems to be a bit of an old question, but since I've been messing about with Doxygen configuration last few days, while my head's still full of current info let's have a stab at it -

I think the previous answers almost have it:

The missing option is to add COLLABORATION_GRAPH = YES in the Doxyfile. I assume you can do the equivalent thing somewhere in the doxywizard GUI (I don't use doxywizard).

So, as a more complete example, typical "Doxyfile" options related to UML output that I tend to use are:

EXTRACT_ALL          = YES
CLASS_DIAGRAMS      = YES
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT             = YES
CLASS_GRAPH          = YES
COLLABORATION_GRAPH  = YES
UML_LOOK             = YES
UML_LIMIT_NUM_FIELDS = 50
TEMPLATE_RELATIONS   = YES
DOT_GRAPH_MAX_NODES  = 100
MAX_DOT_GRAPH_DEPTH  = 0
DOT_TRANSPARENT      = YES

These settings will generate both "inheritance" (CLASS_GRAPH=YES) and "collaboration" (COLLABORATION_GRAPH=YES) diagrams.

Depending on your target for "deployment" of the doxygen output, setting DOT_IMAGE_FORMAT = svg may also be of use. With svg output the diagrams are "scalable" instead of the fixed resolution of bitmap formats such as .png. Apparently, if viewing the output in browsers other than IE, there is also INTERACTIVE_SVG = YES which will allow "interactive zooming and panning" of the generated svg diagrams. I did try this some time ago, and the svg output was very visually attractive, but at the time, browser support for svg was still a bit inconsistent, so hopefully that situation may have improved lately.

As other comments have mentioned, some of these settings (DOT_GRAPH_MAX_NODES in particular) do have potential performance impacts, so YMMV.

I tend to hate "RTFM" style answers, so apologies for this sentence, but in this case the Doxygen documentation really is your friend, so check out the Doxygen docs on the above mentioned settings- last time I looked you can find the details at http://www.doxygen.nl/manual/config.html.

孤千羽 2024-10-20 03:46:26

Doxygen 创建继承图,但我认为它不会创建整个类层次结构。它确实允许您使用 GraphViz 工具。如果您使用 Doxygen GUI 前端工具,您将在 Step2: -> 中找到相关选项。向导选项卡 ->图表。 DOT 关系选项位于“专家”选项卡下。

Doxygen creates inheritance diagrams but I dont think it will create an entire class hierachy. It does allow you to use the GraphViz tool. If you use the Doxygen GUI frontend tool you will find the relevant options in Step2: -> Wizard tab -> Diagrams. The DOT relation options are under the Expert Tab.

耳钉梦 2024-10-20 03:46:26

引用这篇文章(由doxygen作者本人撰写):

run doxygen -g and change the following options of the generated Doxyfile:

    EXTRACT_ALL            = YES
    HAVE_DOT               = YES
    UML_LOOK               = YES

run doxygen again

Quote from this post (it's written by the author of doxygen himself) :

run doxygen -g and change the following options of the generated Doxyfile:

    EXTRACT_ALL            = YES
    HAVE_DOT               = YES
    UML_LOOK               = YES

run doxygen again
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文