Doxygen 示例命令更改功能注释

问题描述 投票:0回答:1

背景

Doxygen 1.10.0、Visual Studio Community 17.9.4、C++20 代码库。

我已经逐步成功地将文档代码添加到项目中。到目前为止,学习曲线上一切都很好。我刚刚开始将示例引入代码库,这是我的第一次尝试。我有以下函数,其文档输出、示例前插入符合预期:

/*! \brief A function to return the name as a string

The function retrieves the name string from a vector of names.  The index into the vector is the object's data member.
If the input parameter is not provided, the default is the name vector containing the standard names. 
\param [in] Strings is a vector containing name strings.
\return The current name as a string.
\exception out_of_range exception thrown if String's bounds are exceeded.  This indicates that either the vector doesn't have enough elements or the month number is out of range.
*/
std::string WxM::GetCurrentString(const std::vector<string>& Strings) const
{
// code removed for brevity
}

无需任何示例命令,文档就可以正确包含在“类”>“类列表”> WxM > GetStringName() 页面下的 HTML 输出页面上并正确设置格式。

我做了什么

  1. 我已将示例文件目录的路径添加到 Doxygen 的 INPUT > Examples_PATH 字段中。
  2. 我已将相同的路径添加到“输入”>“排除”字段。
  3. 我在 xception 命令行后添加了以下几行:
\example{lineno} GetCurrentString_Example.cpp
This is an example of how to use the GetCurrentString function.
  1. 我已在适当的目录中创建了 GetCurrentString_Example.cpp 文件,其中包含
main()
{
    std::vector<std::string> Names = { "Test", "Test Again", ... };
    WxM WxMInstance;

    // current now contains the name.
    std::string current = WxMInstance.GetCurrentString(Names);
}

Doxygen 没有报告与示例相关的错误或警告。

预期产出

我希望示例代码显示在输出 HTML 中,位于函数文档页面上其自己的标题下,位于函数签名、rief 和主要描述以及 \param 之后, eturn 和 xception 文本,以及定义位置引用和调用者图之前。

实际产量

函数的页面现在仅包含函数签名、带有示例引用的示例标头以及“Definition at..”位置引用和调用者图。剩余的文字已经消失。但是,当我点击示例链接时,所有文本(包括示例代码)都会出现,该链接将我带到新的主菜单示例类别。

如何保留之前的风格(功能描述在自己的页面上)并在该页面上列出示例代码?这是默认行为吗?

Doxygen 示例示例并不是特别有用或丰富,不足以提供见解。我在 Google 上搜索了任何线索,并将问题提交给编码 AIChat,但这是一个非常具体的问题。我发现很少涉及这个主题。

doxygen
1个回答
0
投票

请允许我首先解释一下您的问题,以确保我正确理解它:
您有一个标头,其中包含类/成员函数和 Doxygen 文档,如第一个代码块中所示。
与您的第一个代码块完全相同,即:

/*! \brief A function to return the name as a string

The function retrieves the name string from a vector of names.  The index into the vector is the object's data member.
If the input parameter is not provided, the default is the name vector containing the standard names. 
\param [in] Strings is a vector containing name strings.
\return The current name as a string.
\exception out_of_range exception thrown if String's bounds are exceeded.  This indicates that either the vector doesn't have enough elements or the month number is out of range.
*/
std::string WxM::GetCurrentString(const std::vector<string>& Strings) const
{
// code removed for brevity
}

...您的 Doxygen 输出如您所愿:您有函数描述、参数等。

当您添加

\example
指令时,即:

/*! \brief A function to return the name as a string

The function retrieves the name string from a vector of names.  The index into the vector is the object's data member.
If the input parameter is not provided, the default is the name vector containing the standard names. 
\param [in] Strings is a vector containing name strings.
\return The current name as a string.
\exception out_of_range exception thrown if String's bounds are exceeded.  This indicates that either the vector doesn't have enough elements or the month number is out of range.
\include GetCurrentString_Example.cpp
*/
std::string WxM::GetCurrentString(const std::vector<string>& Strings) const
{
// code removed for brevity
}

...然后你的函数描述消失了,只出现了签名——这是你的问题的正确总结吗?您想要的行为是原始文档

GetCurrentString_Example.cpp
的内容添加到与您的功能描述相同的页面 - 这也是正确的吗?

我能够重现您的问题,并且我认为我可以使用

\include
指令而不是
\example
指令来满足您的需求(我冒昧地在您的代码示例中添加了一个类,只是这样我得到了一个最低限度可编译的示例):

// WxM.h

#include <string>
#include <vector>

/*! \brief The WxM class
 */
class WxM {
public:
  /*! \brief A function to return the name as a string
  The function retrieves the name string from a vector of names.  The index into the vector is the object's data member.
  If the input parameter is not provided, the default is the name vector containing the standard names.
  \param [in] Strings is a vector containing name strings.
  \return The current name as a string.
  \exception out_of_range exception thrown if String's bounds are exceeded.  This indicates that either the vector doesn't have enough elements or the month number is out of range.

  \b Example
  \include GetCurrentString_Example.cpp
  */
  std::string GetCurrentString(const std::vector<string>& Strings) const
  {
    return "Hello, world!";
  }
};

这满足您的需求吗?如果是的话,我可以更详细地描述我发现的内容。

© www.soinside.com 2019 - 2024. All rights reserved.