Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a trick to reduce the amount of redundant commenting required for full Doxygen coverage?

Tags:

c++

doxygen

As part of documenting my C++ codebase, I'm trying to get to full Doxygen coverage -- that is, I want all of my (hundreds of) header files to have well-formed Doxygen comments for all of their public API, so that I can run Doxygen on the codebase and not see any "warning: blah is not documented" warnings.

In general this is just a matter of going through and documenting stuff, but I've noticed that I keep entering the same text over and over again for every class. For example, I have many instances of essentially this:

/** The Foo class represents blah blah blah */
class Foo
{
public:
    /** Default constructor */
    Foo();

    /** Copy constructor
      * @param rhs the object to make this object a copy of.
      */
    Foo(const Foo & rhs);

    /** Destructor */
    ~Foo();

    /** Equality operator.
      * @param rhs the object to compare against.
      * @returns true iff this object and (rhs) are equal.
      */
    bool operator == (const Foo & rhs) const;

    /** Inequality operator.
      * @param rhs the object to compare against.
      * @returns true iff this object and (rhs) are not equal.
      */
    bool operator != (const Foo & rhs) const;

    /** Assignment operator
      * @param rhs the object we should copy our state from
      * @returns a reference to *this
      */
    Foo & operator = (const Foo & rhs);

[...]
}

These comments are (usually) more-or-less exactly the same for every class, because these functions/operators almost always work exactly the same way for every class. Indeed, to have operators or copy constructors that behaved in some other manner would be a questionable design pattern, as C++ programmers generally expect operators to work the same way for every class.

My questions is, is there some trick by which I can tell Doxygen to auto-generate reasonable documentation for these things (e.g. via some sort of template or macro) without my having to manually enter this text over and over again? That would greatly cut down on the amount of text I have to enter and maintain, and it would also de-clutter my header files by allowing me to remove comments of the "no duh" variety so that the reader can more easily find the comments that offer real insight.

like image 674
Jeremy Friesner Avatar asked Aug 25 '17 20:08

Jeremy Friesner


People also ask

What is @brief in doxygen?

Putting the command @brief will generate a short description of the function when you generate the doxygen documentation. That short description can be extended if you want.

How do you do doxygen comments?

To create a Doxygen comment from scratch: Type one of the following symbols: /// , //! , /** or /*! and press Enter .

How do I comment out a code in doxygen C++?

Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut.

What is doxygen C++?

Doxygen is the de facto standard tool for generating documentation from annotated C++ sources, but it also supports other popular programming languages such as C, Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, and UNO/OpenOffice flavors), Fortran, and to some extent D.


1 Answers

There are several commands for copying documentation:

\copydoc \copybrief \copydetails

Doxygen help suggests the following syntax:

/*! @copydoc MyClass::myfunction()
 *  More documentation.
 */

This allows you to copy documentation from one class to another. Sometimes I produce a documentation only class that isn't compiled as a standard place to draw documentation from in the rest of the project.

like image 92
Denise Skidmore Avatar answered Oct 12 '22 18:10

Denise Skidmore