a173ab76d0aa7c86faf5754c4e560499ba049ecb
[alexxy/gromacs.git] / doxygen / doxygen.md
1 Using Doxygen {#page_doxygen}
2 =============
3
4 This page documents how Doxygen is set up in the \Gromacs source tree,
5 as well as guidelines for adding new Doxygen comments.  Examples are included,
6 as well as tips and tricks for avoiding Doxygen warnings.  The guidelines focus
7 on C++ code and other new code that follows the new module layout.
8 Parts of the guidelines are still applicable to documenting older code (e.g.,
9 within `gmxlib/` or `mdlib/`), in particular the guidelines about formatting
10 the Doxygen comments and the use of \c \\internal.
11 \ref page_codelayout documents the overall structure of the documentation.
12
13 To get started quickly, you only need to read the first two sections to
14 understand the overall structure of the documentation, and take a look at the
15 examples at the end.  The remaining sections provide the details for
16 understanding why the examples are the way they are, and for more complex
17 situations.  They are meant more as a reference to look up solutions for
18 particular problems, rather than single-time reading.  To understand or find
19 individual Doxygen commands, you should first look at Doxygen documentation
20 (http://www.stack.nl/~dimitri/doxygen/manual/index.html).
21
22
23 Documentation flavors
24 =====================
25 The \Gromacs source tree is set up to produce three different levels of Doxygen
26 documentation:
27
28 1. Public API documentation (suffix `-user`), which documents functions and
29    classes exported from the library and intended for use outside the \Gromacs
30    library.
31 2. Library API documentation (suffix `-lib`), which additionally includes
32    functions and classes that are designed to be used from other parts of
33    \Gromacs, as well as some guidelines that are mostly of interest to
34    developers.
35 3. Full documentation (suffix `-full`), which includes (nearly) all (documented)
36    functions and classes in the source tree.
37
38 Each subsequent level of documentation includes all the documentation from the
39 levels above it.  The suffixes above refer to the suffixes of Doxygen input and
40 output files, as well as the name of the output directory.  When all the
41 flavors have been built, the front pages of the documentation contain links to
42 the other flavors, and explain the differences in more detail.
43
44 As a general guideline, the public API documentation should be kept free of
45 anything that a user linking against an unmodified \Gromacs does not see.
46 In other words, the public API documentation should mainly document the
47 contents of installed headers, and provide the necessary overview of using
48 those.  Also, verbosity requirements for the public API documentation are
49 higher: ideally, readers of the documentation could immediately start using the
50 API based on the documentation, without any need to look at the implementation.
51
52 Similarly, the library API documentation should not contain things that other
53 modules in \Gromacs can or should never call.  In particular, anything declared
54 locally in source files should be only available in the full documentation.
55 Also, if something is documented, and is not identified to be in the library
56 API, then it should not be necessary to call that function from outside its
57 module.
58
59
60 Building the documentation
61 ==========================
62
63 If you simply want to see up-to-date documentation, you can go to
64 http://jenkins.gromacs.org/job/Doxygen_Nightly_master/javadoc/html-lib/index.xhtml
65 to see the documentation for the current development version.
66 Jenkins also runs Doxygen for all changes pushed to Gerrit for master, and the
67 resulting documentation can be viewed from the link posted by Jenkins.  The
68 Doxygen build is marked as unstable if it introduces any Doxygen warnings.
69
70 You may need to build the documentation locally if you want to check the
71 results after adding/modifying a significant amount of comments.  This is
72 recommended in particular if you do not have much experience with Doxygen.
73 It is a good idea to build with all the different settings to see that the
74 result is what you want, and that you do not produce any warnings.
75 For local work, it is generally a good idea to set `GMX_COMPACT_DOXYGEN=ON`
76 CMake option, which removes some large generated graphs from the documentation
77 and speeds up the process significantly.
78
79 All files related to Doxygen reside in the `doxygen/` subdirectory in the source
80 and build trees.  In a freshly checked out source tree, this directory contains
81 various `Doxyfile-*.cmakein` files.  When you run CMake, corresponding files
82 `Doxyfile-user`, `Doxyfile-lib`, and `Doxyfile-full` are generated at the
83 corresponding location in the build tree.  There is also a
84 `Doxyfile-common.cmakein`, which is used to produce `Doxyfile-common`.
85 This file contains settings that are shared between all the input files.
86 `Doxyfile-compact` provides the extra settings for `GMX_COMPACT_DOXYGEN=ON`.
87
88 You can run Doxygen directly with one of the generated files (all output will
89 be produced under the current working directory), or build one of the
90 `doc-user`, `doc-lib`, and `doc-full` targets.  The targets run Doxygen in a
91 quieter mode and only show the warnings if there were any, and put the output
92 under `doxygen/` in the build tree.  The `doc-all` target builds all three
93 targets with less typing.
94
95 The generated documentation is put under `html-user/`, `html-lib/`, and/or
96 `html-full/` in the output directory.  Open `index.xhtml` file from one of
97 these subdirectories to start browsing (for \Gromacs developers, the
98 `html-lib/` is a reasonable starting point).  Log files with all Doxygen
99 warnings are also produced as `doxygen-*.log`, so you can inspect them after
100 the run.
101
102 You will need Doxygen 1.8.5 to build the current documentation.  Other versions
103 may work, but likely also produce warnings.  Additionally,
104 [graphviz](http://www.graphviz.org) and
105 [mscgen](http://www.mcternan.me.uk/mscgen/) are required for some graphs in
106 the documentation, and `latex` for formulas.  Working versions are likely
107 available through most package managers.  It is possible to build the
108 documentation without these tools, but you will see some errors and the related
109 figures will be missing from the documentation.
110
111
112 General guidelines for Doxygen markup
113 =====================================
114
115 Doxygen provides quite a few different alternative styles for documenting the
116 source code.  There are subtleties in how Doxygen treats the different types of
117 comments, and this also depends somewhat on the Doxygen configuration.  It is
118 possible to change the meaning of a comment by just changing the style of
119 comment it is enclosed in.  To avoid such issues, and to avoid needing to
120 manage all the alternatives, a single style throughout the source tree is
121 preferable.  When it comes to treatment of styles, \Gromacs uses the default
122 Doxygen configuration with one exception: `JAVADOC_AUTOBRIEF` is set ON to
123 allow more convenient one-line brief descriptions in C code.
124
125 Majority of existing comments in \Gromacs uses Qt-style comments (`/*!` and
126 `//!` instead of `/*``*` and `///`, \c \\brief instead of \c \@brief etc.),
127 so these should be used also for new documentation.  There is a single
128 exception for brief comments in C code; see below.
129
130 Similarly, existing comments use `/*!` for multiline comments in both C and
131 C++ code, instead of using multiple `//!` lines for C++.  The rationale is that
132 since the code will be a mixture of both languages for a long time, it is more
133 uniform to use similar style in both.  Also, since files will likely transition
134 from C to C++ gradually, rewriting the comments because of different style
135 issues should not generally be necessary.  Finally, multi-line `//!` comments
136 can work differently depending on Doxygen configuration, so it is better to
137 avoid that ambiguity.
138
139 When adding comments, ensure that a short brief description is always produced.
140 This is used in various listings, and should briefly explain the purpose of the
141 method without unnecessarily expanding those lists.
142 The basic guideline is to start all comment blocks with \c \\brief (possibly
143 after some other Doxygen commands).
144 If you want to avoid the \c \\brief for one-liners, you can use `//!`, but the
145 description must fit on a single line; otherwise, it is not interpreted as a
146 brief comment.  Note in particular that a simple `/*!` without a \c \\brief
147 does not produce a brief description.
148 Also note that \c \\brief marks the whole following paragraph as a brief
149 description, so you should insert an empty line after the intended brief
150 description.
151
152 In C code, `//` comments must be avoided because some compilers do not like
153 them.  If you want to avoid the \c \\brief for one-liners in C code, use
154 `/*``*` instead of `//!`.  If you do this, the brief description should not
155 contain unescaped periods except at the end.  Because of this, you should
156 prefer `//!` in C++ code.
157
158 Put the documentation comments in the header file that contains the
159 declaration, if such a header exists.
160 Implementation-specific comments that do not influence how a method
161 is used can go into the source file, just before the method definition, with an
162 \c \\internal tag in the beginning of the comment block.  Doxygen-style comments
163 within functions are not generally usable.
164
165 At times, you may need to exclude some part of a header or a source file such
166 that Doxygen does not see it at all.  In general, you should try to avoid this,
167 but it may be necessary to remove some functions that you do not want to appear
168 in the public API documentation, and which would generate warnings if left
169 undocumented, or to avoid Doxygen warnings from code it does not understand.
170 Prefer \c \\cond and \c \\endcond to do this.  If \c \\cond does not work for
171 you, you can also use \c \#ifndef `DOXYGEN`.  If you exclude a class method in
172 a header, you also need to exclude it in the source code to avoid warnings.
173
174
175 \Gromacs specifics
176 =================
177
178 The general guidelines on the style of Doxygen comments were given above.
179 This section introduces \Gromacs specific constructs currently used in Doxygen
180 documentation, as well as how \Gromacs uses Doxygen groups to organize the
181 documentation.
182
183 Controlling documentation visibility
184 ------------------------------------
185
186 To control in which level of documentation a certain function appears, three
187 different mechanisms are used:
188 * Global Doxygen configuration.  This is mainly used to include
189   declarations local to source files only in the full documentation.
190   You can find the details from the `Doxyfile-*.cmakein` files, and some of
191   them are also mentioned below on individual code constructs.
192 * The standard Doxygen command \c \\internal marks the documentation to be only
193   extracted into the full documentation (`INTERNAL_DOCS` is `ON` only for the
194   full documentation).  This should be used as a first command in a comment
195   block to exclude all the documentation.  It is possible to use \c \\internal
196   and \c \\endinternal to exclude individual paragraphs, but \c \\if `internal`
197   is preferred (see below).
198   In addition, \Gromacs-specific custom Doxygen command \c \\libinternal is
199   provided, which should be used the same way to exclude the documentation from
200   the public API documentation.  This command expands to either \c \\internal
201   or to a no-op, depending on the documentation level.
202 * Doxygen commands \c \\if and \c \\cond can be used with section names
203   `libapi` and `internal` to only include the documentation in library API and
204   the full documentation, respectively.  `libapi` is also defined in the full
205   documentation.  These are declared using `ENABLED_SECTIONS` in the Doxygen
206   configuration files.
207
208 Examples of locations where it is necessary to use these explicit commands are
209 given below in the sections on individual code constructs.
210
211 Modules as Doxygen groups
212 -------------------------
213
214 As described in \ref page_codelayout, each subdirectory under `src/gromacs/`
215 represents a _module_, i.e., a somewhat coherent collection of routines.
216 Doxygen cannot automatically generate a list of routines in a module; it only
217 extracts various alphabetical indexes that contain more or less all documented
218 functions and classes.  To help reading the documentation, the routines for a
219 module should be visible in one place.
220
221 \Gromacs uses Doxygen groups to achieve this: for each documented module, there
222 is a \c \\defgroup definition for the module, and all the relevant classes and
223 functions need to be manually added to this group using \c \\ingroup and
224 \c \\addtogroup.
225 The group page also provides a natural place for overview documentation about
226 the module, and can be navigated to directly from the "Modules" tab in the
227 generated documentation.
228
229 Some notes about using \c \\addtogroup are in order:
230 * \c \\addtogroup only adds the elements that it directly contains into the
231   group.  If it contains a namespace declaration, only the namespace is added
232   to the group, but none of the namespace contents are.  For this reason,
233   \c \\addtogroup should go within the innermost scope, around the members that
234   should actually be added.
235 * If the module should not appear in the public API documentation, its
236   definition (\c \\defgroup) should be prefixed with a \c \\libinternal.
237   In this case, also all \c \\addtogroup commands for this module should be
238   similarly prefixed.  Otherwise, they create the group in the public API
239   documentation, but without any of the content from the \c \\defgroup
240   definition.  This may also cause the contents of the \c \\addtogroup section
241   to appear in the public API documentation, even if it otherwise would not.
242
243 Public API and library API groups
244 ---------------------------------
245
246 In addition to the module groups, two fixed groups are provided:
247 `group_publicapi` and `group_libraryapi`.  Classes and files can be added to
248 these groups using \Gromacs specific custom \c \\inpublicapi and
249 \c \\inlibraryapi commands.  The generated group documentation pages are not
250 very useful, but annotated classes and files show the API definition under the
251 name, making this information more easily accessible.  These commands in
252 file-level comments are also used for some automatic intermodule dependency
253 validation (see below).
254
255 Note that functions, enumerations, and other entities that do not have a
256 separate page in the generated documentation can only belong to one group;
257 in such a case, the module group is preferred over the API group.
258
259 Automatic dependency checking
260 -----------------------------
261
262 The build system provides a `doc-check` target that automatically checks some
263 aspects of the documentation, as well as checking that header files are
264 actually used according to their API specifications (i.e., an internal headers
265 are not included from other modules).  The checks depend on correct usage of
266 the commands listed above, in particular the visibility and API definitions in
267 file-level comments.  These checks also provide some level of enforcement for
268 rules about dependencies between the modules, but currently the checks are not
269 run automatically.
270
271 The checker currently checks for a few different types of issues:
272 * For all Doxygen documentation (currently does not apply for members within
273   anonymous namespaces or members that do not appear in the documentation):
274    * If a member has documentation, it should have a brief description.
275    * A note is issued for in-body documentation for functions, since this is
276      ignored by our current settings.
277    * If a class has documentation, it should have public documentation only if
278      it appears in an installed header.
279    * If a class and its containing file has documentation, the class
280      documentation should not be visible if the file documentation is not.
281 * For all files:
282    * Consistent usage of
283
284          #include "..." // This should be used for Gromacs headers
285
286      and
287
288          #include <...> // This should be used for system and external headers
289
290    * Installed headers must not include non-installed headers, and must include
291      all other \Gromacs headers using relative paths so that they resolve
292      correctly also when installed.
293 * For documented files:
294    * Installed headers should have public documentation, and other files should
295      not.
296    * The API level specified for a file should not be higher than where its
297      documentation is visible.  For example, only publicly documented headers
298      should be specified as part of the public API.
299    * If an \c \\ingroup module_foo exists, it should match the subdirectory
300      that the file is actually part of in the file system.
301    * If a \c \\defgroup module_foo exists for the subdirectory where the file is,
302      the file should contain \c \\ingroup module_foo.
303    * Files should not include other files whose documentation visibility is
304      lower (if the included file is not documented, the check is skipped).
305 * For files that are part of documented modules
306   (\c \\defgroup module_foo exists for the subdirectory):
307    * Such files should not be included from outside their module if they are
308      undocumented or are not specified as part of library or public API.
309
310 The checker is based on extracting the Doxygen documentation in XML format.
311 This information is then read using a Python script, and combined with
312 information extracted from the file system and knowledge about the \Gromacs
313 source tree layout.  The Python scripts are in the `doxygen/` folder.
314 In addition to printing the issues, they are also written into
315 `doxygen/doxygen-check.log` for later inspection.
316
317 The script is not currently perfect (either because of unfinished
318 implementation, or because Doxygen bugs or incompleteness of the Doxygen XML
319 output), and the current code also contains issues that the script detects, but
320 the authors have not fixed.  To allow the script to still be used,
321 `doxygen/suppressions.txt` contains a list of issues that are filtered out from
322 the report.  The syntax is simple:
323
324     <file>: <text>
325
326 where `<file>` is a path to the file that reports the message, and `<text>` is
327 the text reported.  Both support `*` as a wildcard.  If `<file>` is empty, the
328 suppression matches only messages that do not have an associated file.
329 `<file>` is matched against the trailing portion of the file name to make it
330 work even though the script reports absolute paths.
331 Empty lines and lines starting with `#` are ignored.
332
333 To add suppression for an issue, the line that reports the issue can be copied
334 into `suppressios.txt`, and the line number (if any) removed.  If the
335 issue does not have a file name (or a pseudo-file) associated, a leading `:`
336 must be added.  To cover many similar issues, parts of the line can then be
337 replaced with wildcards.
338
339 For some false positives from the script, the suppression mechanism is the
340 easiest way to silence the script, but otherwise the goal would be to minimize
341 the number of suppressions.
342
343 As a side effect, the XML extraction makes Doxygen parse all comments in the
344 code, even if they do not appear in the documentation.  This can reveal latent
345 issues in the comments, like invalid Doxygen syntax.  The messages from the XML
346 parsing are stored in `doxygen/doxygen-xml.log` in the build tree, similar to
347 other Doxygen runs.
348
349 The `doc-check` target requires Python 2.7 (other versions may work, but have
350 not been tested).
351
352 Include dependency graphs
353 -------------------------
354
355 The build system also provides an `dep-graphs` target that generates include
356 dependency graphs with some additional annotations.
357 One graph is produced that shows all the modules under `src/gromacs/`, and
358 their include dependencies.  Additionally, a file-level graph is produced for
359 each module, showing the include dependencies within that module.  Currently,
360 these are mostly for eye candy, but they can also be used for analyzing
361 problematic dependencies to clean up the architecture.
362 The output is put in `doxygen/depgraphs/` in the build tree.
363
364 As with `doc-check`, Python 2.7 is required (other versions may work, but have
365 not been tested).  To get `.png` versions of the graphs, `graphviz` is
366 additionally required.
367
368 ### Module graph ###
369
370 The graph is written into `module-deps.dot.png`.
371
372 Node colors:
373 <dl>
374 <dt>gray background</dt>
375 <dd>undocumented module</dd>
376 <dt>orange background</dt>
377 <dd>documented utility modules</dd>
378 <dt>red background</dt>
379 <dd>documented analysis modules</dd>
380 <dt>violet background</dt>
381 <dd>documented MD execution modules</dd>
382 <dt>light blue border</dt>
383 <dd>module contains public API (installed) headers</dd>
384 </dl>
385
386 Edge colors (an edge with a certain color indicates that types above it in the
387 list are not present):
388 <dl>
389 <dt>red</dt>
390 <dd>invalid dependency</dd>
391 <dt>gray</dt>
392 <dd>legacy dependency
393 (dependency on undocumented file, or to undocumented directories)</dd>
394 <dt>solid black</dt>
395 <dd>public header depends on the other module</dd>
396 <dt>solid blue</dt>
397 <dd>library header depends on the other module</dd>
398 <dt>dashed blue</dt>
399 <dd>source file depends on library header in the other module</dd>
400 <dt>dashed black</dt>
401 <dd>source file depends on public header in the other module</dd>
402 <dt>dashed green</dt>
403 <dd>test file depends on the other module</dd>
404 </dl>
405
406 ### File graph ###
407
408 The graphs are written to <em>module_name</em>`-deps.dot.png`.
409
410 Node colors:
411 <dl>
412 <dt>light blue</dt>
413 <dd>public API (installed) headers</dd>
414 <dt>dark blue</dt>
415 <dd>library API headers</dd>
416 <dt>gray</dt>
417 <dd>source files</dd>
418 <dt>light green</dt>
419 <dd>test files</dd>
420 <dt>white</dt>
421 <dd>other files</dd>
422 </dl>
423
424 Each edge signifies an include dependency; there is no additional information
425 currently included.
426
427 Documenting specific code constructs
428 ====================================
429
430 This section describes the techical details and some tips and tricks for
431 documenting specific code constructs such that useful documentation is
432 produced.  If you are wondering where to document a certain piece of
433 information, see the documentation structure section on \ref page_codelayout.
434 The focus of the documentation should be on the overview content: Doxygen pages
435 and the module documentation.  An experienced developer can relatively easily
436 read and understand individual functions, but the documentation should help
437 in getting the big picture.
438
439 Doxygen pages
440 -------------
441
442 The pages that are accessible through navigation from the front page are
443 written using Markdown and are located under `doxygen/`.  Each page should be
444 placed in the page hierarchy by making it a subpage of another page, i.e., it
445 should be referenced once using \c \\subpage.  `mainpage.md` is the root of the
446 hierarchy.
447
448 If you need to exclude a page from the public API docs, you need to add it to
449 an exclude list in `Doxyfile-user.cmakein`, and ensure that there are no
450 references to the page from public API documentation.  \c \\if `libapi` can be
451 used to add references in content that is otherwise public.
452 Generally, the pages should be on a high enough level and provide overview
453 content that is useful enough such that it is not necessary to exclude them
454 from the library API documentation.
455
456 Modules
457 -------
458
459 For each module, decide on a header file that is the most important one for
460 that module (if there is no self-evident header, it may be better to designate,
461 e.g., module-doc.h for this purpose, but this is currently not done for any
462 module).  This header should contain the \c \\defgroup definition for the
463 module.  The name of the group should be `module_`<em>name</em>, where _name_
464 is the name of the subdirectory that hosts the module.
465
466 The module should be added to an appropriate group (see `doxygen/misc.cpp` for
467 definitions) using \c \\ingroup to organize the "Modules" tab in the generated
468 documentation.
469
470 One or more contact persons who know about the contents of the module should be
471 listed using \c \\author commands.  This provides a point of contact if one
472 has questions.
473
474 Classes/structs
475 ---------------
476
477 Classes and structs in header files appear always in Doxygen documentation,
478 even if their enclosing file is not documented.  So start the documentation
479 blocks of classes that are not part of the public API with \c \\internal or
480 \c \\libinternal.  Classes declared locally in source files or in unnamed
481 namespaces only appear in the full documentation.
482
483 If a whole class is not documented, this does not currently generate any
484 warning.  The class is simply exluded from the documentation.  But if a member
485 of a documented class is not documented, a warning is generated.  Guidelines for
486 documenting free functions apply to methods of a class as well.
487
488 For base classes, the API classification (\c \\inpublicapi or
489 \c \\inlibraryapi) should be based on where the class is meant to be
490 subclassed.  The visibility (\c \\internal or \c \\libinternal), in contrast,
491 should reflect the API classification of derived classes such that the base
492 class documentation is always generated together with the derived classes.
493
494 For classes that are meant to be subclassed and have protected members, the
495 protected members should only appear at the documentation level where the class
496 is meant to be subclassed.  For example, if a class is meant to be subclassed
497 only within a module, the protected members should only appear in the
498 full documentation.  This can be accomplished using \c \\cond (note that you
499 will need to add the \c \\cond command also to the source files to hide the
500 same methods from Doxygen, otherwise you will get confusing warnings).
501
502 Methods/functions/enums/macros
503 ------------------------------
504
505 These items do not appear in the documentation unless their enclosing scope is
506 documented.  For class members, the scope is the class; otherwise, it is the
507 namespace if one exists, or the file.  An \c \\addtogroup can also define a
508 scope if the group has higher visibility than the scope outside it.
509 So if a function is not within a namespace (mostly applicable to C code) and
510 has the same visibility as its enclosing file, it is not necessary to add a
511 \c \\internal or \c \\libinternal.
512
513 Static functions are currently extracted for all documentation flavors to allow
514 headers to declare `static inline` functions (used in, for example, math code).
515 Functions in anonymous namespaces are only extracted into the full
516 documentation.  Together with the above rules, this means that you should avoid
517 putting a `static` function within a documented namespace, even within source
518 files, or it may inadvertently appear in the public API documentation.
519
520 If you want to exclude an item from the documentation, you need to put in
521 inside a \c \\cond block such that Doxygen does not see it.
522 Otherwise, a warning for an undocumented function is generated.  You need to
523 enclose both the declaration and the definition with \c \\cond.
524
525 Files
526 -----
527
528 Each documented file should start with a documentation block (right after the
529 copyright notice) that documents the file.  See the examples section for exact
530 formatting.  Things to note:
531 * Please do not specify the file name explicitly after \c \\file.  By default,
532   a file comment applies to the file it is contained in, and an explicit file
533   name only adds one more thing that can get out of date.
534 * \c \\brief cannot appear on the same line as the \c \\file, but should be on
535   the next line.
536 * \c \\internal or \c \\libinternal should indicate where the header is visible.
537   As a general guideline, all installed headers should appear in the public API
538   documentation, i.e., not contain these commands.  If nothing else, then to
539   document that it does not contain any public API functions.  Headers that
540   declare anything in the library API should be marked with \c \\libinternal,
541   and the rest with \c \\internal.
542 * All source files, as well as most test files, should be documented with
543   \c \\internal, since they do not provide anything to public or library API,
544   and this avoids unintentionally extracting things from the file into those
545   documentations.  Shared test files used in tests from other modules should be
546   marked with \c \\libinternal.
547 * \c \\inpublicapi or \c \\inlibraryapi should be used to indicate where the
548   header is meant to be directly included.
549 * As with files, one or more contact persons should be listed with \c \\author.
550   If you make significant modifications or additions to a file, consider adding
551   an \c \\author line for yourself.
552
553 Directories
554 -----------
555
556 Directory documentation does not typically contain useful information beyond a
557 possible brief description, since they correspond very closely to modules, and
558 the modules themselves are documented.  A brief description is still useful to
559 provide a high-level overview of the source tree on the generated "Files" page.
560 A reference to the module is typically sufficient as a brief description for a
561 directory.  All directories are currently documented in
562 `doxygen/directories.cpp`.
563
564
565 Examples
566 ========
567
568 Basic C++
569 ---------
570
571 Here is an example of documenting a C++ class and its containing header file.
572 Comments in the code and the actual documentation explain the used Doxygen
573 constructs.
574
575 \includelineno doxygen-example.cpp
576
577 Basic C
578 -------
579
580 Here is another example of documenting a C header file (so avoiding all
581 C++-style comments), and including free functions.  It also demonstrates the use
582 of \c \\addtogroup to add multiple functions into a module group without repeated
583 \c \\ingroup tags.
584
585 \includelineno doxygen-example.c
586
587 Scoping and visibility rules
588 ----------------------------
589
590 The rules where Doxygen expects something to be documented, and when are
591 commands like \c \\internal needed, can be complex.  The examples below
592 describe some of the pitfalls.
593
594 \includelineno doxygen-example-scoping.cpp
595
596 Module documentation
597 --------------------
598
599 Documenting a new module should place a comment like this in a central header
600 for the module, such that the "Modules" tab in the generated documentation can
601 be used to navigate to the module.
602
603 \includelineno doxygen-example-module.cpp
604
605 Common mistakes
606 ---------------
607
608 The most common mistake, in particular in C code, is to forget to document the
609 file.  This causes Doxygen to ignore most comments in the file, so it
610 does not validate the contents of the comments either, nor is it possible to
611 actually check how the generated documentation looks like.
612
613 The following example shows some other common mistakes (and some less common)
614 that do not produce correct documentation, as well as Doxygen "features"/bugs
615 that can be confusing.
616 The issues are explained in normal comments above each code fragment.
617
618 \includelineno doxygen-example-issues.cpp
619
620 Existing code
621 -------------
622
623 More examples you can find by looking at existing code in the source tree.  In
624 particular new C++ code such as that in the `src/gromacs/analysisdata/` and
625 `src/gromacs/options/` subdirectories contains a large amount of code
626 documented mostly along these guidelines.  Some comments in
627 `src/gromacs/selection/` (in particular, any C-like code) predate the
628 introduction of these guidelines, so those are not the best examples.