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.

2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

See my comment with the question.
@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.
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> */

5 Comments

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.
The doxygen comnent /*!<Document the value 0 */ is displayed alongwith MY_ENUM_0 in the documentation generated as shown in this example answer. Each such comment would have to be value is 0, value is 1, ... etc. for each member of the enum.
Because you wrote "0" yourself, the OP is asking how to have Doxygen generates the "0".
Yes, you are right. Involves manual effort. This is the closest that i DO know that works.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.