How to display a defined value

一曲冷凌霜 提交于 2019-12-12 11:38:44

问题


In some doxygen documentation I'd like to display the content of a #define, not the tag itself. For instance, in a C file I have

#define REPEAT_N_TIMES 10

Now in my documentation I want to display:

The action is done 10 times.

If I use \ref REPEAT_N_TIMES, it displays:

The action is done REPEAT_N_TIMES times

Is there a way to display the content of a link, not the link itself, for example like \ValueOf(\ref REPEAT_N_TIMES) or \contentOf(\ref REPEAT_N_TIMES)?

Update: My Doxygen's config is:

// Configuration options related to the preprocessor

ENABLE_PREPROCESSING   = YES
MACRO_EXPANSION        = YES
EXPAND_ONLY_PREDEF     = YES
SEARCH_INCLUDES        = YES
INCLUDE_PATH           =
INCLUDE_FILE_PATTERNS  =
PREDEFINED             = WXUNUSED()=
EXPAND_AS_DEFINED      =
SKIP_FUNCTION_MACROS   = YES

The MACRO_EXPANSION setting seems to change the "details" of the macros. But I don't see a way to select either the name of the macro, or its content. Using the command \ref doesn't seems to be the right way: it refers to "something" not the content of "something"

Is there an operator or function I could use, possibly similar to C, where I can use something like \ref *something instead of \ref something?


回答1:


The doxygen manual page on preprocessing seems to have all the information you need. As a first step try setting the MACRO_EXPANSION flag in the doxygen configuration file to YES, then in your documentation include

The action is done REPEAT_N_TIMES times.

As noted in the doxygen manual, this will expand all macro definitions (recursively if needed), which is often too much. Therefore you can specify exactly which macros to expand using the EXPAND_ONLY_PREDEF and EXPAND_AS_DEFINED settings in the configuration file. For example, try setting

EXPAND_ONLY_PREDEF = YES
EXPAND_AS_DEFINED = REPEAT_N_TIMES

in the configuration file.

UPDATE: Following @spamy's comment I looked into this a bit more and it seems that the methods I have mentioned above does not work for macros within comment blocks, i.e. only macros within the source code are expanded. See, for example, this post on the doxygen sourceforge page. According to this post the only way to achieve macro expansion within comment blocks is to use the INPUT_FILTER configuration file setting. Use something like

INPUT_FILTER = sed /REPEAT_N_TIMES/10

Warning: The above INPUT_FILTER has not been tested.

If you don't want to use the INPUT_FILTER then this answer to another thread is probably your best bet. Essentially it says you can document the macro, so readers of the documentation would be able to find the real value easily. So add documentation to your #define and just \ref it elsewhere in your documentation.



来源:https://stackoverflow.com/questions/10137566/how-to-display-a-defined-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!