C++ 记录预处理器在 Doxygen 中的定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2356120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Documenting preprocessor defines in Doxygen
提问by Fire Lancer
Is it possible to document preprocessor defines in Doxygen? I expected to be able to do it just like a variable or function, however the Doxygen output appears to have "lost" the documentation for the define, and does not contain the define itself either.
是否可以记录 Doxygen 中的预处理器定义?我希望能够像变量或函数一样执行它,但是 Doxygen 输出似乎“丢失”了定义的文档,并且也不包含定义本身。
I tried the following
我尝试了以下
/**My Preprocessor Macro.*/
#define TEST_DEFINE(x) (x*x)
and
和
/**@def TEST_DEFINE
My Preprocessor Macro.
*/
#define TEST_DEFINE(x) (x*x)
I also tried putting them within a group (tried defgroup, addtogroup and ingroup) rather than just at the "file scope" however that had no effect either (although other items in the group were documented as intended).
我还尝试将它们放在一个组中(尝试过 defgroup、addtogroup 和 ingroup),而不仅仅是在“文件范围”中,但这也没有任何影响(尽管组中的其他项目已按预期记录)。
I looked through the various Doxygen options, but couldn't see anything that would enable (or prevent) the documentation of defines.
我查看了各种 Doxygen 选项,但看不到任何可以启用(或阻止)定义文档的内容。
回答by ChrisN
Yes, it is possible. The Doxygen documentationsays:
对的,这是可能的。该Doxygen文档说:
To document global objects (functions, typedefs, enum, macros, etc), you must document the file in which they are defined. In other words, there must at least be a
/*! \file */
or a
/** @file */
line in this file.
要记录全局对象(函数、typedef、枚举、宏等),您必须记录定义它们的文件。换句话说,至少必须有一个
/*! \file */
或
/** @file */
此文件中的行。
You can use @defgroup
, @addtogroup
, and @ingroup
to put related items into the same module, even if they appear in separate files (see documentation herefor details). Here's a minimal example that works for me (using Doxygen 1.6.3):
您可以使用@defgroup
、@addtogroup
和@ingroup
将相关项目放入同一个模块中,即使它们出现在单独的文件中(有关详细信息,请参阅此处的文档)。这是一个对我有用的最小示例(使用 Doxygen 1.6.3):
Doxyfile:
文件:
# Empty file.
Test.h:
测试.h:
/** @file */
/**My Preprocessor Macro.*/
#define TEST_DEFINE(x) (x*x)
/**
* @defgroup TEST_GROUP Test Group
*
* @{
*/
/** Test AAA documentation. */
#define TEST_AAA (1)
/** Test BBB documentation. */
#define TEST_BBB (2)
/** Test CCC documentation. */
#define TEST_CCC (3)
/** @} */
Foo.h:
富.h:
/** @file */
/**
* @addtogroup TEST_GROUP
*
* @{
*/
/** @brief My Class. */
class Foo {
public:
void method();
};
/** @} */
Bar.h:
酒吧.h:
/** @file */
/**
* @ingroup TEST_GROUP
* My Function.
*/
void Bar();
In this case, the TEST_DEFINE
documentation appears in the Test.hentry under the Filestab in the HTML output, and the TEST_AAA
etc. definitions appear under Test Groupin the Modulestab together with class Foo
and function Bar
.
在这种情况下,TEST_DEFINE
文档出现在HTML 输出中Files选项卡下的Test.h条目中,等定义出现在Modules选项卡中的Test Group 下,以及 class和 function 。TEST_AAA
Foo
Bar
One thing to note is that if you put the file name after the @file
command, e.g:
需要注意的一件事是,如果您将文件名放在@file
命令之后,例如:
/** @file Test.h */
then this must match the actual name of the file. If it doesn't, documentation for items in the file won't be generated.
那么这必须与文件的实际名称相匹配。如果没有,则不会生成文件中项目的文档。
An alternative solution, if you don't want to add @file
commands, is to set EXTRACT_ALL = YES
in your Doxyfile.
如果您不想添加@file
命令,另一种解决方案是EXTRACT_ALL = YES
在 Doxyfile 中进行设置。
I hope this helps!
我希望这有帮助!
回答by Jim Chargin
In my "C" files, I use a comment format and #define line like this:
在我的“C”文件中,我使用注释格式和 #define 行,如下所示:
/** @brief Number of milli-seconds to wait*/
#define kTimeoutMSec (2)
My html documents do end up containing documentation I specify. (I do have @file at the top of the file and EXTRACT_ALL=YES)
我的 html 文档最终包含我指定的文档。(我确实在文件顶部有@file 并且 EXTRACT_ALL=YES)
回答by Sam Post
Try setting EXTRACT_ALL option, I have that set in my project and it generates documentation for #defines. There might be a more elegant way of doing it without using EXTRACT_ALL so be sure to check the documentation
尝试设置 EXTRACT_ALL 选项,我在我的项目中设置了该选项,并为 #defines 生成文档。在不使用 EXTRACT_ALL 的情况下可能有更优雅的方法,因此请务必查看文档
回答by AmiguelS
Adding to the previous answers, it is also needed to have ENABLE_PREPROCESSING=YES
on the Doxyfile.
除了前面的答案之外,还需要ENABLE_PREPROCESSING=YES
在 Doxyfile 上有。