使用 Doxygen 记录枚举类值,而不启用EXTRACT_ALL

Document enum class values using Doxygen without enabling EXTRACT_ALL

本文关键字:不启用 EXTRACT ALL Doxygen 记录 枚举 使用      更新时间:2023-10-16

如果不设置EXTRACT_ALL,我无法显示枚举类值的文档。保留、截断和追加的注释不存在。枚举本身是有文档记录的。如果我启用EXTRACT_ALL我会得到一个列表。

我的代码是:

namespace grimoire
{
...
/// @brief Behaviour of function open_for_write for already existing files.
/// @see open_for_write()
enum class OpenMode
{
preserve = std::ofstream::out,   /// Already existing file aren't opened.
truncate = std::ofstream::trunc, /// Discard existing contents.
append   = std::ofstream::app    /// Append to existing contents.
};
...
}

我正在使用CMake来运行Doxygen:

#set(DOXYGEN_EXTRACT_ALL YES)
doxygen_add_docs(
docs
"${CMAKE_CURRENT_SOURCE_DIR}/include/grimoire"
"${CMAKE_CURRENT_SOURCE_DIR}/src")

编辑:

它甚至不适用于经典枚举并且没有显式值。看起来这与我的设置有关。

解决:

我不得不向封闭命名空间添加注释。Doxygen提取了枚举本身和其他东西,如该命名空间内的函数和类,但没有提取枚举条目。

Doxygen 并不总是拾取枚举,这可以通过使用file命令来克服。 此外,您在枚举值定义记录枚举值,这意味着您不应该使用///而是///<

因此,有限的示例如下所示:

/// file

/// @brief Behavior of function open_for_write for already existing files.
/// @see open_for_write()
enum class OpenMode
{
preserve = std::ofstream::out,   ///< Already existing file aren't opened.
truncate = std::ofstream::trunc, ///< Discard existing contents.
append   = std::ofstream::app    ///< Append to existing contents.
};

编辑: 根据OP的答案,给定的解决方案并不完整,因为原始问题嵌入在命名空间中。为了能够在这种情况下显示枚举,仅添加file是不够的,还需要记录命名空间。所以一个更完整的例子:

/// file
/// The namespace documentation
namespace NS
{
/// @brief Behavior of function open_for_write for already existing files.
/// @see open_for_write()
enum class OpenMode
{
preserve = std::ofstream::out,   ///< Already existing file aren't opened.
truncate = std::ofstream::trunc, ///< Discard existing contents.
append   = std::ofstream::app    ///< Append to existing contents.
};
};