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.
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.
To create a Doxygen comment from scratch: Type one of the following symbols: /// , //! , /** or /*! and press Enter .
Once specified, you can generate the comment stub by typing the respective “///” or “/**” above a function, or by using the (Ctrl+/) shortcut.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With