24

I need a way to get doxygen to show the real value of the enum member in the doxygen output. For instance I have:

///MyEnum
typedef enum My_Enum
{
MY_ENUM_0,///<MY_ENUM_0
MY_ENUM_1,///<MY_ENUM_1
MY_ENUM_2 ///<MY_ENUM_2
} My_Enum;

The output is:

MyEnum.
Enumerator:
MY_ENUM_0
      MY_ENUM_0.
MY_ENUM_1
      MY_ENUM_1.
MY_ENUM_2
      MY_ENUM_2.

What I want is:

Enumerator:
MY_ENUM_0
          0 MY_ENUM_0.
MY_ENUM_1
          1 MY_ENUM_1.
MY_ENUM_2
          2 MY_ENUM_2.

Or something similar.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
noti
  • 887
  • 7
  • 25
  • Recently I saw this question again, my advise was to open an issue in the doxygen issue tracker (https://github.com/doxygen/doxygen/issues/new) – albert Sep 19 '18 at 17:27
  • see https://stackoverflow.com/questions/52387561/doxygen-enum-with-explicit-hard-value – albert Sep 19 '18 at 17:54

2 Answers2

2

There isn't a way to do this directly from doxygen that I can think of. Doxygen is not a C compiler. So it will not derive the value of an enum which is a compile-time constant.

The closest thing doxygen can do is selectively expand your macros since it does have a C preprocesor. So if you have some value assigned to a constant that is derived by preprocessor expansion, doxygen can expand the macros and show you what will be assigned.

Building on TheCodeArtist's answer, you might consider writing script that runs prior to doxygen, makes copies of your files, searches for this pattern:

enum *** {
    ***, ///< %VAL%:

and replaces each occurrence of %VAL% with what the value should be so you aren't manually keeping up with the numbers. After doxygen runs the original files which contain the %VAL% tokens would need to be replaced. That's not a particularly elegant or robust solution.

albert
  • 8,285
  • 3
  • 19
  • 32
Nick
  • 1,361
  • 1
  • 14
  • 42
  • 1
    See my comment with the question. – albert Sep 20 '18 at 15:51
  • @albert Thanks for that suggestion, also thank you for linking the other question on this topic. I think this is a good idea for a new feature. I have found myself in a situation where I had to semi manually calculate an enumerated value more than a few times. – Nick Sep 20 '18 at 19:34
0

Using doxygen, we can document:

  • The enum
  • Its values
  • A description of each value

The following code snippet describes an example for all 3 above.

/*! \enum My_Enum
* Documentation of the enum type.
*/

typedef enum My_Enum {
    MY_ENUM_0, /*!< Document the value 0 */
    MY_ENUM_1, /*!< Document the value 1 */
} My_Enum;

/*! \var My_Enum MY_ENUM_0
 * The description of the MY_ENUM_0. Can contain its enumerated name */

/*! \var My_Enum MY_ENUM_1
 * The description of the MY_ENUM_1. Can contain its enumerated name*/

Also note that since macro/enum expansion does NOT happen within doxygen comments. If any are used within a doxygen comment then they need to be expanded using INPUT_FILTER. For example:

INPUT_FILTER = sed /MY_ENUM_0/0

is required for the following code snippet

typedef enum My_Enum {
    MY_ENUM_0, /*!< MY_ENUM_0 */
    ...

Also Checkout this answer for details on the multiple doxygen commenting styles:

  • ///< <comment>
  • /*!< <comment> */
Community
  • 1
  • 1
TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
  • 5
    This does not answer the question. The value of MY_ENUM_0 is 0, but it will not be visible in the doxygen doc generated by the code in your answer. – Étienne Apr 09 '14 at 12:09
  • The doxygen comnent `/*! – TheCodeArtist Apr 09 '14 at 12:20
  • 7
    Because you wrote "0" yourself, the OP is asking how to have Doxygen generates the "0". – Étienne Apr 09 '14 at 12:21
  • Yes, you are right. Involves manual effort. This is the closest that i DO know that works. – TheCodeArtist Apr 09 '14 at 12:23
  • 7
    Sure, I didn't mean to be rude, the problem is that enum values can be defined using macros or other enum values, and then it can get quite complicated to know which value the enum has and to document/update it by hand. – Étienne Apr 09 '14 at 12:26