【问题标题】:How to add non-commented code blocks to numbered documentation sections如何将未注释的代码块添加到编号的文档部分
【发布时间】:2015-02-18 23:48:28
【问题描述】:

我需要生成包含引用块编号列表的文档,其中包含标记、递增数字和实际代码块(最好带有链接)。我至少可以处理一个标签、唯一编号和一个真正的代码块。

所以拿这个:

C++ 代码

    int a = 5;
    int b = 10;
    int c, d;
    /**
     * @method{} Multiply
     */
    c = a*b;
    /** @endmethod */
    /**
     * @method{} Divide
     */
    d = a/b;
    /** @endmethod */

并将其转换为“相关页面”下名为“方法”的 Doxygen 页面,其中列出了这两种方法以及标题,类似于:

Doxygen 输出 - 相关页面 - 方法

Function foobar

Method 1: Multiply      <-- {} First argument turns to a number?
c = a*b;                <-- More important: This gets pulled from the code?

Method 2: Divide
d = a/b;

也许有更好的工具来解决这个问题?

到目前为止,我已经通过将此别名添加到 Doxyfile 中,使用我的 cmets 在“相关页面”下生成“方法”页面:

Doxyfile

ALIASES += "method=\xrefitem method \"Method \" \"Methods\" "

但我无法找到一种方法来获取实际代码以插入到文档中...或者如何自动或手动对其编号(我可以预处理)...我得到的最接近的是 @code groups 是 hacky 并且不起作用?

【问题讨论】:

    标签: c++ documentation comments doxygen


    【解决方案1】:

    自动编号似乎不可用,最接近抓取代码的东西似乎是 @sn-p 命令,但这不适合我的架构,因为我不需要使用任何 @ref 或 @anchors或自定义@pages,只需将代码吸入@xrefitem 块的文档中。

    所以我想出的答案是最好的结果(除非其他人用更好的东西做出回应!)是以我只能假设不受支持的方式破解 @code 块,但恰好适合我的工作需要(标签号需要预处理,所以我将它们保留为 {} 直到文档或使用预提交挂钩):

    Doxyfile:

    ALIASES += "mynotes=\verbatim My Notes:\n"
    ALIASES += "endmynotes=\endverbatim"
    ALIASES += "model=\xrefitem model \"Model\" \"Models\" "
    ALIASES += "model{1}=\xrefitem mathmodel \"Model\" \"Models\" #\1:  "
    

    代码:

    /// @model{10} Do this thing with a preprocessed tag number
    /// @mynotes
    /// Place my notes here verbatim
    /// @endmynotes
    /// @code{.cpp}
        m_serr << "Bad contents!" << std::endl;
    /// @endcode
    

    输出 HTML 文档:

    模型((模型页面的链接)):
    #10:使用预处理的标签号来做这件事

    My Notes:
       Place my notes here verbatim
    

    {.cpp} m_serr << "Bad contents!" << std::endl;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      相关资源
      最近更新 更多