summaryrefslogtreecommitdiffstats
path: root/doc/docblocks.doc
blob: 804187a5b50b827918d49ea5a8999cd98ee43ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/******************************************************************************
 *
 * 
 *
 * Copyright (C) 1997-2002 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */
/*! \page docblocks Documenting the code

\subsection specialblock Special documentation blocks

A special documentation block is a C or C++ comment block with some 
additional markings, so doxygen knows it is a piece of documentation that
needs to end up in the generated documentation. 

For each code item there are two types of descriptions, which together
form the documentation: a \e brief description and \e detailed
description, both are optional. 
Having more than one brief or detailed description however, is 
not allowed. 

As the name suggest, a brief description is
a short one-liner, whereas the detailed description provides longer, 
more detailed documentation.

There are several ways to mark a comment block as a detailed description:
<ol>
<li> You can use the JavaDoc style, which consist of a C-style comment
block starting with two *'s, like this:

\verbatim
/**
 * ... text ...
 */
\endverbatim

<li> or you can use the Qt style and add an exclamation mark (!) 
after the opening of a C-style comment block, as shown in this example:

\verbatim
/*!
 * ... text ...
 */
\endverbatim

In both cases the intermediate *'s are optional, so

\verbatim
/*!
 ... text ...
*/
\endverbatim

is also valid.

<li> 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. Here are examples of the two cases:

\verbatim
///
/// ... text ...
///
\endverbatim

or

\verbatim
//!
//!... text ...
//!
\endverbatim

<li>

Some people like to make their comment blocks more visible in the
documentation. For this purpose you can use the following:

\verbatim
/////////////////////////////////////////////////
/// ... text ...
/////////////////////////////////////////////////
\endverbatim

</ol>

For the brief description there are also several posibilities:
<ol>
<li>One could use the \ref cmdbrief "\brief" command with one of the 
above comment blocks. This command ends at the end of a paragraph, 
so the detailed description follows after an empty line.

Here is an example:

\verbatim
/*! \brief Brief description.
 *         Brief description continued.
 *
 *  Detailed description starts here.
 */
\endverbatim

<li>If \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" is set to \c YES 
    in the configuration file, 
    then using JavaDoc style comment
    blocks will automatically start a brief description which ends at the
    first dot followed by a space or new line. Here is an example:

\verbatim
/** Brief description which ends at this dot. Details follow
 *  here.
 */
\endverbatim
The option has the same effect for multi-line special C++ comments:
\verbatim
/// Brief description which ends at this dot. Details follow
/// here.
\endverbatim

<li>A third option is to use a special C++ style comment which does not 
    span more than one line. Here are two examples:
\verbatim
/// Brief description.
/** Detailed description. */
\endverbatim

or

\verbatim
//! Brief descripion.

//! Detailed description 
//! starts here.
\endverbatim

Note the blank line in the last example, which is required to separate the 
brief description from the block containing the detailed description. The
\ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" should also be set to \c NO
for this case.

</ol>

As you can see doxygen is quite flexible. The following however is
not legal

\verbatim
//! Brief description, which is
//! really a detailed description since it spans multiple lines.
/*! Oops, another detailed description!
 */
\endverbatim

because doxygen only allows one brief and one detailed description. 

Furthermore, if there is one brief description before a declaration 
and one before a definition of a code item, only the one before 
the \e declaration will be used. If the same situation occurs for a 
detailed description, the one before the \e definition is preferred 
and the one before the declaration will be ignored.

Here is an example of a documented piece of C++ code using the Qt style:
\verbinclude qtstyle.cpp
 \htmlonly
 Click <a href="$(DOXYGEN_DOCDIR)/examples/qtstyle/html/class_test.html">here</a>
 for the corresponding HTML documentation that is generated by doxygen.
 \endhtmlonly

The one-line comments contain a brief description, 
whereas the multi-line comment blocks contain a more detailed description.

The brief descriptions are included in the member overview of a 
class, namespace or file and are printed using a small italic font 
(this description can be hidden by setting 
\ref cfg_brief_member_desc "BRIEF_MEMBER_DESC" to \c NO in 
the config file). By default the brief descriptions become the first 
sentence of the detailed descriptions 
(but this can be changed by setting the \ref cfg_repeat_brief "REPEAT_BRIEF" 
tag to \c NO). Both the brief and the detailed descriptions 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
however, where the first sentence of the documentation block is automatically
treated as a brief description. To enable this behaviour you should set
\ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" to YES in the configuration
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:
\verbatim
  /** Brief description (e.g.\ using only a few words). Details follow. */
\endverbatim

Here is the same piece of code as shown above, this time documented using the 
JavaDoc style and \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" set to YES:
\verbinclude jdstyle.cpp
 \htmlonly
 Click <a href="$(DOXYGEN_DOCDIR)/examples/jdstyle/html/class_test.html">here</a>
 for the corresponding HTML documentation that is generated by doxygen.
 \endhtmlonly

Unlike most other documentation systems, doxygen also allows you to put
the documentation of members (including global functions) in front of 
the \e 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 description could be placed before the
declaration and the detailed description before the member definition.

\subsection memberdoc Putting documentation after members 

If you want to document the members of a file, struct, union, class, or enum,
and you want to put the documentation for these members inside the compound,
it is sometimes desired to place the documentation block after the member 
instead of before. For this purpose you should put an additional \< marker
in the comment block.

Here are some examples:
\verbatim
int var; /*!< Detailed description after the member */
\endverbatim
This block can be used to put a Qt style detailed 
documentation block \e after a member. Other ways to do the
same are:
\verbatim
int var; /**< Detailed description after the member */
\endverbatim
or 
\verbatim
int var; //!< Detailed description after the member
         //!< 
\endverbatim
or 
\verbatim
int var; ///< Detailed description after the member
         ///< 
\endverbatim

Most often one only wants to put a brief description after a member.
This is done as follows:
\verbatim
int var; //!< Brief description after the member
\endverbatim
or
\verbatim
int var; ///< Brief description after the member
\endverbatim

Note that these blocks have the same structure and meaning as the 
special comment blocks in the previous section 
only the \< indicates that the member is 
located in front of the block instead of after the block.

Here is an example of the use of these comment blocks:
\verbinclude afterdoc.h
 \htmlonly
 Click <a href="$(DOXYGEN_DOCDIR)/examples/afterdoc/html/class_test.html">here</a>
 for the corresponding HTML documentation that is generated by doxygen.
 \endhtmlonly

\warning These blocks can only be used to document \e members and \e parameters.
         They cannot be used to document files, classes, unions, structs,
         groups, namespaces and enums themselves. Furthermore, the structural 
         commands mentioned in the next section 
         (like <code>\\class</code>) are ignored inside these comment blocks.

\subsection structuralcommands Documentation at other places

So far we have assumed that the documentation blocks are always located in 
front of the declaration or definition of a file, class or namespace or in
front or after one of its members. 
Although this is often comfortable, there may sometimes be reasons to put the 
documentation somewhere else. For documenting a file this is even 
required since there is no such thing as "in front of a file". 
Doxygen allows you to put your documentation blocks practically 
anywhere (the exception is inside the body of a function or inside a 
normal C style comment block). 

The price you pay for not putting the
documentation block before (or after) an item is the need to put a  
structural command inside the documentation block, which leads to some
duplication of information.

Structural commands (like all other commands) start with a backslash 
(<tt>\\</tt>), or an at-sign (<tt>\@</tt>) if you prefer JavaDoc style, 
followed by a command name and one or more parameters.
For instance, if you want to document the class \c Test in the example
above, you could have also put the following documentation block somewhere
in the input that is read by doxygen:
\verbatim
/*! \class Test
    \brief A test class.

    A more detailed class description.
*/
\endverbatim

Here the special command \c \class is used to indicate that the
comment block contains documentation for the class \c Test.
Other structural commands are:
<ul>
<li>\c \struct to document a C-struct.
<li>\c \union to document a union.
<li>\c \enum to document an enumeration type.
<li>\c \fn to document a function.
<li>\c \var to document a variable or typedef or enum value.
<li>\c \def to document a \#define.
<li>\c \file to document a file.
<li>\c \namespace to document a namespace.
<li>\c \package to document a Java package.
<li>\c \interface to document an IDL interface.
</ul>
See section \ref commands for detailed information about these and many other 
commands. 

To document a member of a C++ class, you must also document the class 
itself. The same holds for namespaces. To document a global C function, 
typedef, enum or preprocessor definition you must first document the file 
that contains it (usually this will be a header file, because that file 
contains the information that is exported to other source files).

Let's repeat that, because it is often overlooked:
to document global objects (functions, typedefs, enum, macros, etc), you
<em>must</em> document the file in which they are defined. In other words, 
there <em>must</em> at least be a \verbatim /*! \file */ \endverbatim
or a \verbatim /** @file */ \endverbatim line in this file.

Here is an example of a C header named \c structcmd.h that is documented 
using structural commands:
\verbinclude structcmd.h
 \htmlonly
 Click <a href="$(DOXYGEN_DOCDIR)/examples/structcmd/html/structcmd_8h.html">here</a>
 for the corresponding HTML documentation that is generated by doxygen.
 \endhtmlonly

 Because each comment block in the example above contains a structural command, all
 the comment blocks could be moved to another location or input file 
 (the source file for instance), without affecting the generated 
 documentation. The disadvantage of this approach is that prototypes are
 duplicated, so all changes have to be made twice! Because of this you
 should first consider if this is really needed, and avoid structural
 commands if possible. I often receive examples that contain \\fn command
 in comment blocks which are place in front of a function. This is clearly
 a case where the \\fn command is redundant and will only lead to problems.

\htmlonly
Go to the <a href="lists.html">next</a> section or return to the
 <a href="index.html">index</a>.
\endhtmlonly

*/