DoxyPress
1.7.0
|
Generating source documentation involves adding documentation to your source code or an external file so DoxyPress can incorporate them into the output it generates. The following sections cover the different ways this can be done.
One way to document your code is to add special comment blocks before each class or method. The comment blocks are designated by using C or C++ style comments with additional notations so DoxyPress knows it is text which should be put in the generated output.
For each entity (class, method, function, etc) in the code there are two categories of documentation, brief documentation and detailed documentation. If both are supplied the brief will come first. You can specify either of these or both as needed.
For methods and functions there is also a third category of documentation called in body documentation. This consists of the concatenation of all comment blocks found within the body of the method or function.
Having more than one brief or detailed documentation is allowed but the order in which the output will appear is not specified.
Brief documentation is a short description whereas the detailed documentation is normally longer and more detailed. The "in body" documentation can also act as detailed documentation or can describe a collection of implementation details.
For the HTML output brief documentation is also used to provide tooltips at places where an item is referenced.
There are several ways to mark a comment block as detailed documentation.
The JavaDoc style consists of a C-style comment block starting with two *'s:
/** * ... text ... */
The Qt style uses an exclamation mark (!) after the opening of a C-style comment block:
/*! * ... text ... */
In both cases the intermediate *'s on subsequent lines are optional.
/*! ... text ... */
A third alternative is to use a block of at least two C++ comment lines where each line starts with an additional slash or an exclamation mark. The following are two examples. Note that a blank line ends a documentation block.
/// /// ... text ... ///
or
//! //!... text ... //!
Another alternative is the following, where the comment blocks is made more visible in your code by adding more asterisks. There are 2 slashes at the end of the normal comment block followed by the start of a special comment block.
/********************************************//** * ... text ***********************************************/
or
///////////////////////////////////////////////// /// ... text ... /////////////////////////////////////////////////
For the brief documentation there are also several possibilities.
Use the cmdbrief command with one of the above special comment blocks. This command terminates at a blank line.
/*! \brief Brief documentation. * Brief documentation continued. * * Detailed documentation starts here. */
If javadoc-auto-brief is enabled then using JavaDoc style comment blocks will automatically start a brief documentation which ends at the first period followed by whitespace or a new line.
/** Brief documentation which ends at this period. Detailed documentation starts * here. */
The same setting has the same effect for multi-line special C++ comments.
/// Brief documentation which ends at this dot. Detailed documentation starts /// here.
Use a special C++ style comment which does not span more than one line.
/// Brief documentation. /** Detailed documentation. */
or
//! Brief documentation. //! Detailed documentation //! starts here.
The blank line in the last example is required to separate the brief documentation from the block containing the detailed documentation. The javadoc-auto-brief must be enabled.
If you have multiple detailed documentation blocks they will be joined together. Documentation will also be joined together if the comments are at different places in your source code. In this case the order will depend on the order in which DoxyPress parses the code.
//! Brief documentation, which is //! really a detailed documentation since it spans multiple lines. /*! Another detailed documentation! */
DoxyPress allows you to put the documentation of members (including global functions) in front of the definition. This way the documentation can be placed in the source file instead of the header file. This keeps the header file compact and allows the implementer of the members more direct access to the documentation. As a compromise the brief documentation could be placed before the declaration and the detailed documentation before the member definition.
If you want to document the members of a file, struct, union, class, or enum, it is sometimes helpful to place the documentation block after the member instead of before. For this purpose you have to put an additional < marker in the comment block. This also works for the parameters of a function.
For example:
int var; /*!< Detailed documentation after the member */
This block can be used to put a Qt style detailed documentation block after a member. The following are several other ways to document after the source code.
int var; /**< Detailed documentation after the member */
or
int var; //!< Detailed documentation after the member //!<
or
int var; ///< Detailed documentation after the member ///<
Usually all that is needed is a brief description after a member. The following are two examples.
int var; //!< Brief documentation after the member
or
int var; ///< Brief documentation after the member
For functions you can use the cmdparam command to document the parameters and then use [in]
, [out]
, [in,out]
to document the direction. For inline documentation the direction can be specified at the beginning of the documentation block.
void foo(int v /**< [in] docs for input parameter v. */);
These blocks have the same structure and meaning as the special comment blocks in the previous section. The < indicates the member is located in front of the block instead of after the block. They can only be used to document members and parameters.
They can not be used to document files, classes, unions, structs, groups, namespaces and enums themselves. Furthermore, the structural commands mentioned in the next section (like \class
) are not allowed inside these comment blocks.
Here is an example:
Here is an example of C++ code using the Qt style:
The brief documentation is included in the member overview of a class, namespace, or file and are shown using a small italic font. This documentation can be hidden by setting brief-member-desc to NO
in the project file. By default the brief documentation is the first sentence of the detailed documentation. This can be changed by setting the repeat-brief tag to NO
. Both the brief and the detailed documentation are optional for the Qt style.
By default a JavaDoc style documentation block behaves the same way as a Qt style documentation block. This is not according the JavaDoc specification where the first sentence of the documentation block is automatically treated as brief documentation. To enable this behavior should set javadoc-auto-brief to YES in the project file. If you enable this option and want to put a dot in the middle of a sentence without ending it, you should put a backslash and a space after it.
Here is an example:
/** Brief documentation (e.g.\ using only a few words). Details follow. */
The following source code is documented using the JavaDoc style and javadoc-auto-brief is set to YES.
In the preceding examples the comment blocks were located in front of the declaration or definition of a class or namespace or in front or after one of its members. Sometimes it is not possible or it is not desired to locate the documentation in the source code.
DoxyPress allows you to put your documentation blocks almost anywhere. The exceptions are inside the body of a function or inside a normal C style comment block.
When the documentation is located in a separate location or file structural commands will be required. Structural commands start with a backslash or an at-sign followed by a command name and one or more parameters. For example, to document the class Test
put the following documentation block somewhere in an input file which will be read by DoxyPress.
/*! \class Test \brief A test class. A more detailed class description. */
The structural command \class
is used to indicate the comment block contains documentation for the class Test
.
Other structural commands are as follows:
\struct
to document a C-struct. \union
to document a union. \enum
to document an enumeration type. \fn
to document a function. \var
to document a variable or typedef or enum value. \def
to document a #define. \typedef
to document a type definition. \file
to document a file. \namespace
to document a namespace. \package
to document a Java package. \interface
to document an IDL interface. Refer to section General Commands for detailed information about these commands.
To document a member of a C++ class you must also document the class itself. The same holds true for namespaces. To document a global C function, typedef, enum or preprocessor definition you must first document the file which contains the entity.
/*! \file */or
/** @file */
Here is an example of a C header named structcmd.h
that is documented using structural commands:
Each comment block in the example contains a structural command. This means all the comment blocks can be moved to another location or input file without affecting the generated output.
The disadvantage of this approach is that prototypes are duplicated. When you have comment blocks in a file with an extension of .dox
, .txt
, or .doc
then DoxyPress will hide these files from the file list.
If you have a file DoxyPress can not parse but still would like to document it, you can show it as-is using \verbinclude.
/*! \file myscript.sh * Look at this nice script: * \verbinclude myscript.sh */
Make sure the script is explicitly listed in the input-source or ensure input-patterns includes the .sh
extension and the script can be found in the path set via example-source.
When using DoxyPress for Fortran code set optimize-fortran to YES
in your project file.
The parser tries to guess if the source code is fixed format Fortran or free format Fortran code. This may not always be correct. If not one should use EXTENSION_MAPPING to correct this. By setting EXTENSION_MAPPING = f=FortranFixed f90=FortranFree
files with extension f
are interpreted as fixed format Fortran code and files with extension f90
are interpreted as free format Fortran code.
For Fortran "!>" or "!<" starts a comment and "!!" or "!>" can be used to continue a one line comment into a multi-line comment.
The following is an example of a documented Fortran subroutine:
As an alternative you can also use comments in fixed format code as shown below:
DoxyPress commands are not supported in Python documentation strings. Python has an established way of documenting source code using documentation strings called a docstring. Since a docstring is not stripped form the source programmers can inspect these comments at run time.
DoxyPress will extract the docstrings and use them as the comments in the generated documentation. None of the standard DoxyPress commands are supported.
There is another way to document Python code using comments which start with "##". These comment blocks will be treated the same as comment blocks found in other programming languages which DoxyPress supports.
For Python source code set the language optimization to optimize-python in your project file.
The following listing is the same Python example using DoxyPress style comments.
DoxyPress documentation can be included in normal Tcl comments.
To start a new documentation block start a line with ##
(two hashes). All following comment lines and continuation lines will be added to this block. The block ends with a line not starting with a #
(hash sign).
Brief documentation can be added with ;#< (semicolon, hash and lower then sign). The brief documentation also ends at a line not starting with a
#
(hash sign).
Comment blocks support all DoxyPress commands with the following two exceptions.
If a DoxyPress comment block ends with a line containing only #\code
or #@code
all code until a line only containing #\endcode
or #@endcode
is added to the generated documentation as code block.
If a DoxyPress comment block ends with a line containing only #\verbatim
or #@verbatim
all code until a line only containing #\endverbatim
or #@endverbatim
is added verbatim to the generated documentation.
To detect namespaces, classes, functions and variables the following Tcl commands are recognized. Documentation blocks can be put on the lines before the command.
namespace eval ..
Namespace proc ..
Function variable ..
Variable common ..
Common variable itcl::class ..
Class itcl::body ..
Class method body definition oo::class create ..
Class oo::define ..
OO Class definition method ..
Class method definitions constructor ..
Class constructor destructor ..
Class destructor public ..
Set protection level protected ..
Set protection level private ..
Set protection level The following is an example using DoxyPress style comments:
The previous sections focused on how to designate documentation in your source code, the differences between brief and detailed documentation, and the use of structural commands. In this section we will examine the commands which are supported in special comment blocks to enhance the output.
DoxyPress supports various styles of formatting. The simplest form is to use plain text. This will appear as is in the output and is ideal for a short description.
For longer documentation you may want to add other formatting such as a list, a table, and font styling. DoxyPress supports the syntax of Markdown including the Markdown extra extension.