如何Doxygen注释生成的代码
我正在使用 C 预处理器生成枚举中的元素。有没有办法为生成的元素编写 doxygen 注释?我不能在 doxygen 之前通过预处理器运行它,因为这会删除 doxygen 注释。
示例:
#define ATTRIBUTES \
X(TITLE, "title") \
X(FILENAME, "filename") \
X(GENRE_ID, "genre_id")
enum ATTRIBUTES_ENUM {
#define X(a, b) a##_ATTRIBUTE,
ATTRIBUTES
#undef X
ATTRIBUTES_COUNT
};
添加类似以下内容:
/**
* \def TITLE_ATTRIBUTE
* The media's title.
*/
不起作用。
编辑 感谢 Thomas Matthews,这是我使用的解决方案:
#define ATTRIBUTES \
X(TITLE, "title") /*!< title attribute */ \
X(FILENAME, "filename") /*!< filename attribute */ \
X(GENRE_ID, "genre_id") /*!< genre id attribute */
#define X(a, b) a##_ATTRIBUTE,
enum ATTRIBUTES_ENUM {
ATTRIBUTES
ATTRIBUTES_COUNT
};
#undef X
并告诉 Doxygen 扩展宏。唯一的缺点是最后一个元素的注释也用作 ATTRIBUTES
定义的注释。但这对我来说只是一个小问题。
I'm using the C preprocessor to generate elements in an enum. Is there a way to write doxygen comments for the generated elements? I can't just run it through the preprocessor before doxygen since that will strip the doxygen comments.
Example:
#define ATTRIBUTES \
X(TITLE, "title") \
X(FILENAME, "filename") \
X(GENRE_ID, "genre_id")
enum ATTRIBUTES_ENUM {
#define X(a, b) a##_ATTRIBUTE,
ATTRIBUTES
#undef X
ATTRIBUTES_COUNT
};
And adding something like:
/**
* \def TITLE_ATTRIBUTE
* The media's title.
*/
doesn't work.
EDIT
Thanks to Thomas Matthews, here's the solution I used:
#define ATTRIBUTES \
X(TITLE, "title") /*!< title attribute */ \
X(FILENAME, "filename") /*!< filename attribute */ \
X(GENRE_ID, "genre_id") /*!< genre id attribute */
#define X(a, b) a##_ATTRIBUTE,
enum ATTRIBUTES_ENUM {
ATTRIBUTES
ATTRIBUTES_COUNT
};
#undef X
And tell Doxygen to expand macros. The only downside is that the comment for the last element is also used as the comment for the ATTRIBUTES
define. But that's a minor issue in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作
在宏定义中,在每个成员后面添加 Doxygen 注释:
<前><代码>#定义属性 \
X(TITLE, "标题") /**!<标题元素 */ \
X(FILENAME, "文件名") /**!<文件名元素 */ \
X(GENRE_ID, "genre_id") /**!<标题元素*/
由于代码格式问题,每一行的注释应该是 C sytle 注释。
我的理解是 Doxygen应该处理宏(进行替换),然后将修改后的文本输入到其注释引擎中。
不过只是猜测。
我强烈建议使用不同的模式将枚举转换为文本。使用数组、向量或地图。如:
现在只需在表中搜索枚举并读出文本即可。将枚举值和文本放在一个结构中的好处是,这允许更改枚举值,但其余代码不必更改。
Try the following
In the macro definition, add the Doxygen comments after each member:
Due to code formmatting issues, the comments on each line should be C sytle comments.
My understanding is that Doxygen should process the macro (making the substitutions), then feed the modified text into it's comment engine.
Just a guess though.
I highly suggest a different schema for converting enums to text. Use either an array, vector or map. Such as:
Now just search the table for an enum and read the text out. The nice thing about putting the enum value and the text together in a structure is that this allows the enum values to change, but the rest of the code doesn't have to change.