在Doxygen中引用参数的正确方法是什么?

Ric*_*ard 56 doxygen

我有一个功能的以下Doxygen文档:

/**
  @brief Does interesting things

  @param[in]  pfirst The first parameter: a barrel full of monkeys

  @pre
    "pfirst" must have been previously passed through BarrelFiller()
*/
Run Code Online (Sandbox Code Playgroud)

请注意,这pfirst是一个参数,并在前提条件中引用它.

我在这里用引号包围它,因为我想从文本的其余部分中脱颖而出.但是这样做会很好,Doxygen会强调命令,最好将它链接到参数定义.有没有办法做到这一点?

如果只使用默认配置(或其微小的改动)就会发生这种情况会特别好.

DRH*_*DRH 63

Doxygen提供\p指示下一个字是函数参数的命令.你会像这样使用它:

... the \p x and \p y coordinates are used to ...
Run Code Online (Sandbox Code Playgroud)

我相信默认情况下会使用打字机字体来表示.我不认为这目前提供任何自动链接功能,但可能在未来.

有一个相关的命令,\a用于标记成员参数.默认情况下,它在文本中强调显示(<em>arg</em>)

您可以找到有关各种Doxygen 特殊命令参考的更多信息.

  • 对于那些在Doxygen文档中没有注意到这个条款的人来说,最清楚的是:你可以用`@`替换任何命令的前导`\`并得到相同的结果.所以,`@ p`也适用于此. (7认同)
  • 我认为这并不是OP正在询问的问题(尽管我并不认为我对他自己的问题比我更了解).主要是他要问的是如何以一种方式标记一些文本,使得输出将被_semanticically_标记为参数(例如,在HTML输出中,一个元素是`paramname`类的成员),不仅仅是_rendered similar_作为默认样式表中的参数.如果你正在为Doxygen的输出换肤,这显然很重要,但目前还没有经济实惠的方法. (6认同)

Gab*_*les 7

我知道你问的是@parameters,但谷歌搜索也在这里搜索@return类型,所以这里是答案:

#在返回值前使用Doxygen来创建指向其定义的超链接:

使用#符号。

完整示例(请参阅@return下面的类型#,每个类型前面都有一个):

#include <stdarg.h> // for va_list, va_start, va_end
#include <stdio.h>  // for vsnprintf

// Function prototype:

int debug_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));

// Function definition:

/// @brief      Function to print out data through serial UART for debugging.
/// @details    Feel free to add more details here,
///             perhaps
///             even
///             a
///             whole
///             paragraph.
/// @note       Optionally add a note too.
/// @param[in]  format  `printf`-like format string
/// @param[in]  ...     `printf`-like variadic list of arguments corresponding to the format string
/// @return     Number of characters printed if OK, or < 0 if error:
///             - #DEBUG_ERR_ENCODING
///             - #DEBUG_ERR_OVERFLOW
///             - #DEBUG_ERR_UART
int debug_printf(const char *format, ...)
{
    int num_chars_printed;

    va_list args;
    va_start(args, format);

    // Use `vsnprintf()` now here to format everything into a single string buffer, then send 
    // out over the UART
    // - num_chars_printed could be set to one of the error codes listed above here

    va_end(args);

    return num_chars_printed;
}
Run Code Online (Sandbox Code Playgroud)

Doxygen 输出现在将错误返回类型显示为行下的子项目符号列表Number of characters printed if OK, or < 0 if error:并且由于#前面的字符,每个错误类型都转换为各自定义的 URL

Doxygen 参考资料:

  1. 请参阅@Jeremy Sarao 的回答,以及在我脑海中盘旋的部落知识。
  2. 部落知识。我不知道如何或在哪里找到这些信息。在 Doxygen 文档中。
  3. 查看所有的Doxygen的特殊命令的列表,在这里:http://www.doxygen.nl/manual/commands.html(例如:\brief@brief\note或者@note\details或者@details\example等)。
  4. 需要注意的是可能的param值是param[in]param[in,out]param[out]。有关更多详细信息和官方文档,请参阅这些参考资料:
    1. 那是输入参数还是输入/输出参数?Doxygen,C++
    2. param特殊命令的官方 Doxygen 文档:http : //www.doxygen.nl/manual/commands.html#cmdparam
  5. 其他演示 Doxygen 用法的代码示例:
    1. STM32如何获得上次复位状态
    2. C 代码中的错误处理

其他参考资料:

  1. GCC 超级有用的 printf 格式属性的文档:
    1. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html - 请参阅“格式”部分
    2. 如何在用户定义的函数中使用格式化字符串?
    3. 我应该如何在 C++ 的类方法中正确使用 __attribute__ ((format (printf, x, y)))?
  2. 基本printf包装器实现:https : //github.com/adafruit/ArduinoCore-samd/blob/master/cores/arduino/Print.cpp#L189

其他 Doxygen 示例:

(复制自我的 eRCaGuy_dotfiles 项目在这里

完整的 Doxygen 函数头示例:

/// \brief          A brief one or two line description of the function.
/// \note           An important note the user should be aware of--perhaps many lines.
/// \details        Extra details.
///                 Perhaps
///                 even
///                 a long
///                 paragraph.
/// \param[in]      var1            Description of variable one, an input
/// \param[in]      var2            Description of variable two, an input
/// \param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// \param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// \return         Description of return types. It may be an enum, with these
///                 possible values:
///                 - #ENUM_VALUE_1
///                 - #ENUM_VALUE_2
///                 - #ENUM_VALUE_3
my_enum_t myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here

    my_enum_t error = ENUM_VALUE_1;

    // Check for NULL pointers
    if (!var3 || !var4)
    {
        // var3 or var4 are NULL pointers, which means they can't be dereferenced
        error = ENUM_VALUE_2;
        goto done;
    }

    if (something_else)
    {
        error = ENUM_VALUE_3;
        goto done;
    }

done:
    return error;
}
Run Code Online (Sandbox Code Playgroud)

您也可以使用@代替\

/// @brief          A brief one or two line description of the function.
/// @param[in]      var1            Description of variable one, an input
/// @param[in]      var2            Description of variable two, an input
/// @param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// @param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// @return         None
void myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here
}
Run Code Online (Sandbox Code Playgroud)

现在\又是这个较短的版本,而不是@

/// \brief          A brief one or two line description of the function.
/// \param[in]      var1            Description of variable one, an input
/// \param[in]      var2            Description of variable two, an input
/// \param[out]     var3            Description of variable three, an output (usu. via a pointer
///                                 to a variable)
/// \param[in,out]  var4            Description of variable four, an input/output (usu. via a
///                                 pointer) since its initial value is read and used, but then 
///                                 it is also updated by the function at some point
/// \return         None
void myFunc(int var1, int var2, int* var3, int* var4)
{
    // function implementation here
}
Run Code Online (Sandbox Code Playgroud)