5

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
spamy
  • 93
  • 1
  • 5
  • See this answer: http://stackoverflow.com/a/1510919/623518 Essentially, *comments are replaced with a single space in the "translation phase", which happens prior to the Preprocessing directive parsing*. So preprocessing **cannot** be used to replace directives within comments. The only way to do this is to use the input filter, as I suggest in my answer. Alternatively, just reference your define (see my update). – Chris Apr 14 '12 at 14:56
  • Possible duplicate: http://stackoverflow.com/questions/9299608/expand-non-function-macros-in-doxygen-documentation-for-c – Chris Apr 14 '12 at 14:56

1 Answers1

0

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.

albert
  • 8,285
  • 3
  • 19
  • 32
Chris
  • 44,602
  • 16
  • 137
  • 156
  • My 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 – spamy Apr 13 '12 at 09:37
  • Ok, it seems that macro expansion within comment blocks is only possible by using `INPUT_FILTER`, see my update. – Chris Apr 13 '12 at 10:03