Avidan Borisov
Avidan Borisov

Reputation: 3325

Doxygen - Document a struct variable but not the struct

Let's say I have this struct type:

typedef struct Hidden Hidden;
struct Hidden
{
    int foo;
    int bar;
};

and then I have a global variable

Hidden visible;

Hidden should never be used and visible should be the only declaration of type Hidden. I don't want to generate documentation for Hidden as I don't want it to be used, but instead generate documentation for visible with all the information about it and about its fields.

The closest thing I've found is that when you document a struct with no tag like:

struct
{
    int foo; ///< Number of particals in the universe.
    int bar; ///< Number of socks in the drawer.
} Baz; ///< Nameless struct variable.

Doxygen will generate

struct {
   int foo
       Number of particals in the universe. 
   int bar
       Number of socks in the drawer. 
} Baz
  Nameless struct variable. 

This is the sort of thing I'm trying to achieve, but I can't use nameless structs.

Is such thing possible?

Upvotes: 2

Views: 21983

Answers (2)

Avidan Borisov
Avidan Borisov

Reputation: 3325

I've found a way to do it. Using proprocessor predefines as @RBE suggested lets you create code only for doxygen which won't compile anyway. So just do this (and make DOXYGEN a predefined macro):

typedef struct Hidden Hidden;

#ifdef DOXYGEN

struct
{
    int foo; ///< Number of particals in the universe.
    int bar; ///< Number of socks in the drawer.
} visible; ///< Nameless struct variable!

#endif

struct Hidden
{
    int foo;
    int bar;
};

Hidden visible;

It's hacky, but it works.

Upvotes: 4

RBE
RBE

Reputation: 175

The simplest way to do what you want is to use a macro definition to switch between the code you will compile, and the code you will run doxygen on:

#define DOXYGEN

#ifdef DOXYGEN
/**
 *  @brief Describe your visible structure here.
 */
typedef struct VISIBLE
{
    int foo; //< Number of particles in the universe.
    int bar; //< Number of socks in the drawer.
} VISIBLE;
#else
typedef struct HIDDEN
{
    int foo;
    int bar;
} HIDDEN;

HIDDEN visible;
#endif

Simply comment or uncomment the DOXYGEN definition to switch from one to the other.

Upvotes: 0

Related Questions