【问题标题】:Doxygen - Document a struct variable but not the structDoxygen - 记录结构变量但不记录结构
【发布时间】:2013-03-07 19:35:17
【问题描述】:

假设我有这个结构类型:

typedef struct Hidden Hidden;
struct Hidden
{
    int foo;
    int bar;
};

然后我有一个全局变量

Hidden visible;

Hidden 不应该被使用,visible 应该是Hidden 类型的唯一声明。我不想为Hidden 生成文档,因为我不想使用它,而是为visible 生成文档,其中包含有关它及其字段的所有信息。

我发现最接近的事情是,当您记录一个没有标签的struct 时:

struct
{
    int foo; ///< Number of particals in the universe.
    int bar; ///< Number of socks in the drawer.
} Baz; ///< Nameless struct variable.

Doxygen 会生成

struct {
   int foo
       Number of particals in the universe. 
   int bar
       Number of socks in the drawer. 
} Baz
  Nameless struct variable. 

这是我想要实现的目标,但我不能使用无名结构。

这样的事情可能吗?

【问题讨论】:

    标签: c doxygen


    【解决方案1】:

    我找到了一种方法。使用@RBE 建议的预处理器预定义可以让您仅为 doxygen 创建代码,无论如何都不会编译。因此,只需执行此操作(并将 DOXYGEN 设为预定义宏):

    typedef struct Hidden Hidden;
    
    #ifdef DOXYGEN
    
    struct
    {
        int foo; ///< Number of particals in the universe.
        int bar; ///< Number of socks in the drawer.
    } visible; ///< Nameless struct variable!
    
    #endif
    
    struct Hidden
    {
        int foo;
        int bar;
    };
    
    Hidden visible;
    

    这很hacky,但它可以工作。

    【讨论】:

    • 这里只是一个注释 - 强烈建议不要留下 API 的未记录部分,特别是如果未记录的函数/枚举/结构/等的内容。实际记录在案。
    【解决方案2】:

    做你想做的最简单的方法是使用宏定义在你将编译的代码和你将运行 doxygen 的代码之间切换:

    #define DOXYGEN
    
    #ifdef DOXYGEN
    /**
     *  @brief Describe your visible structure here.
     */
    typedef struct VISIBLE
    {
        int foo; //< Number of particles in the universe.
        int bar; //< Number of socks in the drawer.
    } VISIBLE;
    #else
    typedef struct HIDDEN
    {
        int foo;
        int bar;
    } HIDDEN;
    
    HIDDEN visible;
    #endif
    

    只需注释或取消注释DOXYGEN 定义即可从一个切换到另一个。

    【讨论】:

    • 你误解了我的意思。我不想只是将结构的名称从 HIDDEN 更改为 VISIBLE。我只想为单个结构变量生成文档,而不是为结构类型本身生成文档。
    猜你喜欢
    • 1970-01-01
    • 2013-04-20
    • 2017-10-03
    • 2011-11-04
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    相关资源
    最近更新 更多