This comment block, containing additional marking so Doxygen knows it is part of the documentation, is in either C or C++. It consists of a brief description, or a detailed description. Both of these are optional. What is not optional, however, is the in body description. This then links together all the comment blocks found in the body of the method or function.
While more than one brief or detailed descriptions is allowed, this is not recommended as the order is not specified.
The following will detail the ways in which a comment block can be marked as a detailed description:
C-style comment block, starting with two asterisks (*) in the JavaDoc style.
/**
* ... documentation ...
*/
C-style comment block using the Qt style, consisting of an exclamation mark (!) instead of an extra asterisks.
/*!
* ... documentation ...
*/
The beginning asterisks on the documentation lines can be left out in both cases if that is preferred.
A blank beginning and end line in C++ also acceptable, with either three forward slashes or two forward slashes and an exclamation mark.
///
/// ... documentation
///
or
//!
//! ... documentation ...
//!
Alternatively, in order to make the comment blocks more visible a line of asterisks or forward slashes can be used.
/////////////////////////////////////////////////
/// ... documentation ...
/////////////////////////////////////////////////
or
/********************************************//**
* ... documentation ...
***********************************************/
Note that the two forwards slashes at the end of the normal comment block start a special comment block.
There are three ways to add a brief description to documentation.
To add a brief description use \brief above one of the comment blocks. This brief section ends at the end of the paragraph and any further paragraphs are the detailed descriptions.
/*! \brief brief documentation.
* brief documentation.
*
* detailed documentation.
*/
By setting JAVADOC_AUTOBRIEF to yes, the brief description will only last until the first dot followed by a space or new line. Consequentially limiting the brief description to a single sentence.
/** Brief documentation. Detailed documentation continues * from here.
*/
This can also be used with the above mentioned three-slash comment blocks (///).
The third option is to use a special C++ style comment, ensuring this does not span more than one line.
/// Brief documentation.
/** Detailed documentation. */
or
//! Brief documentation.
//! Detailed documentation //! starts here
The blank line in the above example is required to separate the brief description and the detailed description, and JAVADOC_AUTOBRIEF needs to be set to no.
It is also possible to have the documentation after members of a file, struct, union, class, or enum. To do this add a < marker in the comment block.\
int var; /*!< detailed description after the member */
Or in a Qt style as:
int var; /**< detailed description after the member */
or
int var; //!< detailed description after the member
//!<
or
int var; ///< detailed description after the member
///<
For brief descriptions after a member use:
int var; //!< brief description after the member
or
int var; ///< brief description after the member
While it is preferable to place documentation in front of the code it is documenting, at times it is only possible to put it in a different location, especially if a file is to be documented; after all it is impossible to place the documentation in front of a file. This is best avoided unless it is absolutely necessary as it can lead to some duplication of information.
To do this it is important to have a structural command inside the documentation block. Structural commands start with a backslash (\) or an at-sign (@) for JavaDoc and are followed by one or more parameters.
/*! \class Test
\brief A test class.
A more detailed description of class.
*/
In the above example the command \class is used. This indicates that the comment block contains documentation for the class 'Test'. Others are:
\struct: document a C-struct
\union: document a union
\enum: document an enumeration type
\fn: document a fcuntion
\var: document a variable, typedef, or enum value
\def: document a #define
\typedef: document a type definition
\file: document a file
\namespace: document a namespace
\package: document a Java package
\interface: document an IDL interface