如何将示例与 Doxygen 集成?

发布于 2024-12-28 13:05:26 字数 1435 浏览 1 评论 0原文

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

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

发布评论

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

评论(4

月隐月明月朦胧 2025-01-04 13:05:26

您可以将示例源代码放在 doxygen 配置中定义的特殊路径中的 EXAMPLE_PATH 下,然后使用 @example 标记插入示例。

然后,Doxygen 将生成一个包含示例源代码的额外页面。它还会从包含示例标签的类文档中设置指向它的链接。

或者,如果您想使用小代码片段,可以使用 @code ... @endcode 插入它们

。相关文档位于此处:
doxygen 文档

You can put example source code in a special path defined in the doxygen config under EXAMPLE_PATH, and then insert examples with the @example tag.

Doxygen will then generate an extra page containing the source of the example. It will also set a link to it from the class documentation containing the example tag.

Alternatively if you want to use small code snippets you can insert them with @code ... @endcode

The documentation for this is here:
doxygen documentation?

夜巴黎 2025-01-04 13:05:26

另一种方法是使用 \snippet 命令。

  • 在你的头文件中写入如下内容:
\section ex1 示例
\snippet path_to_test_class/TestClass.cpp TestClass 示例
\section ex2 预期输出
\snippet path_to_test_class/TestClass.cpp TestClass 预期输出
  • 在 TestClass.cpp 文件中,有类似以下内容:

<前> <代码> //! [OptimizeSpeedOnTrackTest 示例]
C类;
const double res = c.do_something();
//! [优化赛道速度测试示例]
//! [OptimizeSpeedOnTrackTest 预期输出]
ASSERT_DOUBLE_EQ(5,res);
//! [OptimizeSpeedOnTrackTest 预期输出]

path_to_test_class 必须位于您的 EXAMPLE_PATH 中。

这为您提供了以下内容:

  • 您的示例不仅仅用于文档:它们还提供测试覆盖范围
  • 您的测试运行程序(和您的编译器)可以确保您的示例实际编译和编译。 run
  • 它非常适合 TDD 工作流程

Another way of doing it is to use the \snippet command.

  • In your header file write something like:
\section ex1 Example
\snippet path_to_test_class/TestClass.cpp TestClass example
\section ex2 Expected output
\snippet path_to_test_class/TestClass.cpp TestClass expected output
  • In the TestClass.cpp file, have something like:
 //! [OptimizeSpeedOnTrackTest example]
 Class c;
 const double res = c.do_something();
 //! [OptimizeSpeedOnTrackTest example]
 //! [OptimizeSpeedOnTrackTest expected output]
 ASSERT_DOUBLE_EQ(5,res);
 //! [OptimizeSpeedOnTrackTest expected output]

path_to_test_class must be in your EXAMPLE_PATH.

This gives you the following:

  • Your examples aren't just there for documentation: they provide test coverage as well
  • Your test runner (& your compiler) give you the insurance that your examples actually compile & run
  • It fits in pretty nicely in a TDD workflow
意犹 2025-01-04 13:05:26

我在使用 @example 将示例文件包含在文档中时遇到了一些错误。这是我使用的解决方法。

examplefile.cs 放置在专门用于示例代码的文件夹/项目中。
将该文件夹放置在 Doxygen EXCLUDE 列表中(Expert->Input->EXCLUDE,在 Doxygen GUI 前端)和 EXAMPLE_PATH 中(Expert->Input->EXAMPLE_PATH在 Doxygen GUI 前端中)

将此代码块放置在文档文件中的某个位置(我将其放在示例所在的文件中。)

/** @example examplefile.cs
 * A description of the example file, causes the example file to show up in 
 * Examples */

这会导致该文件显示在示例中的示例下Doxygen 菜单,但不会在项目中显示为类/文件。

然后记录你的类/函数:

/** @brief MyClass does something
 * @details I have something more long winded to say about it.  See example 
 * in examplefile.cs: @include examplefile.cs */

这会导致示例文件在 MyClass 的文档中完整打印出来。

I had some errors using @example to include the example file in the documentation. This is the workaround I used.

Place examplefile.cs in a folder/project specifically for example code.
Place that folder in the Doxygen EXCLUDE list (Expert->Input->EXCLUDEin Doxygen GUI frontend) and in the EXAMPLE_PATH (Expert->Input->EXAMPLE_PATH in Doxygen GUI frontend)

Place this code block somewhere in a documented file (I put it in the file the example is for.)

/** @example examplefile.cs
 * A description of the example file, causes the example file to show up in 
 * Examples */

This causes the file to show up under Examples in the Doxygen menu, but not show up as a class/file in your project.

Then document your class/function:

/** @brief MyClass does something
 * @details I have something more long winded to say about it.  See example 
 * in examplefile.cs: @include examplefile.cs */

This causes the example file to print out in it's entirety in the documentation of MyClass.

奢欲 2025-01-04 13:05:26
  1. 为doxyfile添加一个方法
    EXAMPLE_PATH = dir_example\

  2. 可以连接同一个文件中的所有示例,例如 example_list.h
    并将其包含在 doxyfile 中
    INPUT = example_list.h \

(语言 - 俄语)
http://www.scale-tech.ru/SimBookmaker/doc/html /examples__list_8h_source.html

http://www.scale-tech.ru/SimBookmaker/doc/html /examples.html

  1. add a way to doxyfile
    EXAMPLE_PATH = dir_example \

  2. can connect all of the examples in the same file such example_list.h
    and include it in doxyfile
    INPUT = example_list.h \

(language - Russian)
http://www.scale-tech.ru/SimBookmaker/doc/html/examples__list_8h_source.html
and
http://www.scale-tech.ru/SimBookmaker/doc/html/examples.html

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