b71f41b0557fd43dcff596950f93637ba95f6685
[alexxy/gromacs.git] / docs / dev-manual / doxygen.rst
1 Using 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 ``\internal``.
11 See `Doxygen documentation on code layout`__ for
12 the overall structure of the documentation.
13
14 __ doxygen-page-codelayout_
15
16 To get started quickly, you only need to read the first two sections to
17 understand the overall structure of the documentation, and take a look at the
18 examples at the end.  The remaining sections provide the details for
19 understanding why the examples are the way they are, and for more complex
20 situations.  They are meant more as a reference to look up solutions for
21 particular problems, rather than single-time reading.  To understand or find
22 individual Doxygen commands, you should first look at Doxygen documentation
23 (http://www.stack.nl/~dimitri/doxygen/manual/index.html).
24
25
26 Documentation flavors
27 ---------------------
28
29 The |Gromacs| source tree is set up to produce three different levels of Doxygen
30 documentation:
31
32 1. Public API documentation (suffix ``-user``), which documents functions and
33    classes exported from the library and intended for use outside the |Gromacs|
34    library.
35 2. Library API documentation (suffix ``-lib``), which additionally includes
36    functions and classes that are designed to be used from other parts of
37    |Gromacs|, as well as some guidelines that are mostly of interest to
38    developers.
39 3. Full documentation (suffix ``-full``), which includes (nearly) all (documented)
40    functions and classes in the source tree.
41
42 Each subsequent level of documentation includes all the documentation from the
43 levels above it.  The suffixes above refer to the suffixes of Doxygen input and
44 output files, as well as the name of the output directory.  When all the
45 flavors have been built, the front pages of the documentation contain links to
46 the other flavors, and explain the differences in more detail.
47
48 As a general guideline, the public API documentation should be kept free of
49 anything that a user linking against an unmodified |Gromacs| does not see.
50 In other words, the public API documentation should mainly document the
51 contents of installed headers, and provide the necessary overview of using
52 those.  Also, verbosity requirements for the public API documentation are
53 higher: ideally, readers of the documentation could immediately start using the
54 API based on the documentation, without any need to look at the implementation.
55
56 Similarly, the library API documentation should not contain things that other
57 modules in |Gromacs| can or should never call.  In particular, anything declared
58 locally in source files should be only available in the full documentation.
59 Also, if something is documented, and is not identified to be in the library
60 API, then it should not be necessary to call that function from outside its
61 module.
62
63
64 Building the documentation
65 --------------------------
66
67 If you simply want to see up-to-date documentation, you can go to
68 http://jenkins.gromacs.org/job/Documentation_Nightly_master/javadoc/html-lib/index.xhtml
69 to see the documentation for the current development version.
70 Jenkins also runs Doxygen for all changes pushed to Gerrit for
71 release-5-0 and master branches, and the
72 resulting documentation can be viewed from the link posted by Jenkins.  The
73 Doxygen build is marked as unstable if it introduces any Doxygen warnings.
74
75 You may need to build the documentation locally if you want to check the
76 results after adding/modifying a significant amount of comments.  This is
77 recommended in particular if you do not have much experience with Doxygen.
78 It is a good idea to build with all the different settings to see that the
79 result is what you want, and that you do not produce any warnings.
80 For local work, it is generally a good idea to set ``GMX_COMPACT_DOXYGEN=ON``
81 CMake option, which removes some large generated graphs from the documentation
82 and speeds up the process significantly.
83
84 All files related to Doxygen reside in the ``docs/doxygen/`` subdirectory in the source
85 and build trees.  In a freshly checked out source tree, this directory contains
86 various ``Doxyfile-*.cmakein`` files.  When you run CMake, corresponding files
87 ``Doxyfile-user``, ``Doxyfile-lib``, and ``Doxyfile-full`` are generated at the
88 corresponding location in the build tree.  There is also a
89 ``Doxyfile-common.cmakein``, which is used to produce ``Doxyfile-common``.
90 This file contains settings that are shared between all the input files.
91 ``Doxyfile-compact`` provides the extra settings for ``GMX_COMPACT_DOXYGEN=ON``.
92
93 You can run Doxygen directly with one of the generated files (all output will
94 be produced under the current working directory), or build one of the
95 ``doxygen-user``, ``doxygen-lib``, and ``doxygen-full`` targets.  The targets run
96 Doxygen in a quieter mode and only show the warnings if there were any, and put
97 the output under ``docs/html/doxygen/`` in the build tree, so that the Doxygen
98 build cooperates with the broader ``webpage`` target.
99 The ``doxygen-all`` target builds all three targets with less typing.
100
101 The generated documentation is put under ``html-user/``, ``html-lib/``, and/or
102 ``html-full/``.  Open ``index.xhtml`` file from one of
103 these subdirectories to start browsing (for |Gromacs| developers, the
104 ``html-lib/`` is a reasonable starting point).  Log files with all Doxygen
105 warnings are also produced as ``docs/doxygen/doxygen-*.log``, so you can inspect them after
106 the run.
107
108 You will need Doxygen 1.8.5 to build the current documentation.  Other versions
109 may work, but likely also produce warnings.  Additionally,
110 `graphviz <http://www.graphviz.org>`_ and
111 `mscgen <http://www.mcternan.me.uk/mscgen/>`_ are required for some graphs in
112 the documentation, and ``latex`` for formulas.  Working versions are likely
113 available through most package managers.  It is possible to build the
114 documentation without these tools, but you will see some errors and the related
115 figures will be missing from the documentation.
116
117 .. _dev-doxygen-guidelines:
118
119 General guidelines for Doxygen markup
120 -------------------------------------
121
122 Doxygen provides quite a few different alternative styles for documenting the
123 source code.  There are subtleties in how Doxygen treats the different types of
124 comments, and this also depends somewhat on the Doxygen configuration.  It is
125 possible to change the meaning of a comment by just changing the style of
126 comment it is enclosed in.  To avoid such issues, and to avoid needing to
127 manage all the alternatives, a single style throughout the source tree is
128 preferable.  When it comes to treatment of styles, |Gromacs| uses the default
129 Doxygen configuration with one exception: ``JAVADOC_AUTOBRIEF`` is set ``ON`` to
130 allow more convenient one-line brief descriptions in C code.
131
132 Majority of existing comments in |Gromacs| uses Qt-style comments (``/*!`` and
133 ``//!`` instead of ``/**`` and ``///``, ``\brief`` instead of ``@brief`` etc.),
134 so these should be used also for new documentation.  There is a single
135 exception for brief comments in C code; see below.
136
137 Similarly, existing comments use ``/*!`` for multiline comments in both C and
138 C++ code, instead of using multiple ``//!`` lines for C++.  The rationale is that
139 since the code will be a mixture of both languages for a long time, it is more
140 uniform to use similar style in both.  Also, since files will likely transition
141 from C to C++ gradually, rewriting the comments because of different style
142 issues should not generally be necessary.  Finally, multi-line ``//!`` comments
143 can work differently depending on Doxygen configuration, so it is better to
144 avoid that ambiguity.
145
146 When adding comments, ensure that a short brief description is always produced.
147 This is used in various listings, and should briefly explain the purpose of the
148 method without unnecessarily expanding those lists.
149 The basic guideline is to start all comment blocks with ``\brief`` (possibly
150 after some other Doxygen commands).
151 If you want to avoid the ``\brief`` for one-liners, you can use ``//!``, but the
152 description must fit on a single line; otherwise, it is not interpreted as a
153 brief comment.  Note in particular that a simple ``/*!`` without a ``\brief``
154 does not produce a brief description.
155 Also note that ``\brief`` marks the whole following paragraph as a brief
156 description, so you should insert an empty line after the intended brief
157 description.
158
159 In C code, ``//`` comments must be avoided because some compilers do not like
160 them.  If you want to avoid the ``\brief`` for one-liners in C code, use
161 ``/**`` instead of ``//!``.  If you do this, the brief description should not
162 contain unescaped periods except at the end.  Because of this, you should
163 prefer ``//!`` in C++ code.
164
165 Put the documentation comments in the header file that contains the
166 declaration, if such a header exists.
167 Implementation-specific comments that do not influence how a method
168 is used can go into the source file, just before the method definition, with an
169 ``\internal`` tag in the beginning of the comment block.  Doxygen-style comments
170 within functions are not generally usable.
171
172 At times, you may need to exclude some part of a header or a source file such
173 that Doxygen does not see it at all.  In general, you should try to avoid this,
174 but it may be necessary to remove some functions that you do not want to appear
175 in the public API documentation, and which would generate warnings if left
176 undocumented, or to avoid Doxygen warnings from code it does not understand.
177 Prefer ``\cond`` and ``\endcond`` to do this.  If ``\cond`` does not work for
178 you, you can also use ``#ifndef DOXYGEN``.  If you exclude a class method in
179 a header, you also need to exclude it in the source code to avoid warnings.
180
181
182 |Gromacs| specifics
183 -------------------
184
185 The general guidelines on the style of Doxygen comments were given above.
186 This section introduces |Gromacs| specific constructs currently used in Doxygen
187 documentation, as well as how |Gromacs| uses Doxygen groups to organize the
188 documentation.
189
190 Some consistency checks are done automatically using custom scripts.
191 See :doc:`gmxtree` for details.
192
193 Controlling documentation visibility
194 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195
196 To control in which level of documentation a certain function appears, three
197 different mechanisms are used:
198
199 * Global Doxygen configuration.  This is mainly used to include
200   declarations local to source files only in the full documentation.
201   You can find the details from the ``Doxyfile-*.cmakein`` files, and some of
202   them are also mentioned below on individual code constructs.
203 * The standard Doxygen command ``\internal`` marks the documentation to be only
204   extracted into the full documentation (``INTERNAL_DOCS`` is ``ON`` only for the
205   full documentation).  This should be used as a first command in a comment
206   block to exclude all the documentation.  It is possible to use ``\internal``
207   and ``\endinternal`` to exclude individual paragraphs, but ``\if internal``
208   is preferred (see below).
209   In addition, |Gromacs|-specific custom Doxygen command ``\libinternal`` is
210   provided, which should be used the same way to exclude the documentation from
211   the public API documentation.  This command expands to either ``\internal``
212   or to a no-op, depending on the documentation level.
213 * Doxygen commands ``\if`` and ``\cond`` can be used with section names
214   ``libapi`` and ``internal`` to only include the documentation in library API and
215   the full documentation, respectively.  ``libapi`` is also defined in the full
216   documentation.  These are declared using ``ENABLED_SECTIONS`` in the Doxygen
217   configuration files.
218
219 Examples of locations where it is necessary to use these explicit commands are
220 given below in the sections on individual code constructs.
221
222 Modules as Doxygen groups
223 ^^^^^^^^^^^^^^^^^^^^^^^^^
224
225 As described in `Doxygen documentation for code layout`__
226 each subdirectory under ``src/gromacs/``
227 represents a *module*, i.e., a somewhat coherent collection of routines.
228 Doxygen cannot automatically generate a list of routines in a module; it only
229 extracts various alphabetical indexes that contain more or less all documented
230 functions and classes.  To help reading the documentation, the routines for a
231 module should be visible in one place.
232
233 __ doxygen-page-codelayout_
234
235 |Gromacs| uses Doxygen groups to achieve this: for each documented module, there
236 is a ``\defgroup`` definition for the module, and all the relevant classes and
237 functions need to be manually added to this group using ``\ingroup`` and
238 ``\addtogroup``.
239 The group page also provides a natural place for overview documentation about
240 the module, and can be navigated to directly from the "Modules" tab in the
241 generated documentation.
242
243 Some notes about using ``\addtogroup`` are in order:
244
245 * ``\addtogroup`` only adds the elements that it directly contains into the
246   group.  If it contains a namespace declaration, only the namespace is added
247   to the group, but none of the namespace contents are.  For this reason,
248   ``\addtogroup`` should go within the innermost scope, around the members that
249   should actually be added.
250 * If the module should not appear in the public API documentation, its
251   definition (``\defgroup``) should be prefixed with a ``\libinternal``.
252   In this case, also all ``\addtogroup`` commands for this module should be
253   similarly prefixed.  Otherwise, they create the group in the public API
254   documentation, but without any of the content from the ``\defgroup``
255   definition.  This may also cause the contents of the ``\addtogroup`` section
256   to appear in the public API documentation, even if it otherwise would not.
257
258 Public API and library API groups
259 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260
261 In addition to the module groups, two fixed groups are provided:
262 ``group_publicapi`` and ``group_libraryapi``.  Classes and files can be added to
263 these groups using |Gromacs| specific custom ``\inpublicapi`` and
264 ``\inlibraryapi`` commands.  The generated group documentation pages are not
265 very useful, but annotated classes and files show the API definition under the
266 name, making this information more easily accessible.  These commands in
267 file-level comments are also used for some automatic intermodule dependency
268 validation (see below).
269
270 Note that functions, enumerations, and other entities that do not have a
271 separate page in the generated documentation can only belong to one group;
272 in such a case, the module group is preferred over the API group.
273
274
275 Documenting specific code constructs
276 ------------------------------------
277
278 This section describes the techical details and some tips and tricks for
279 documenting specific code constructs such that useful documentation is
280 produced.  If you are wondering where to document a certain piece of
281 information, see the documentation structure section in
282 `Doxygen documentation for code layout`__.
283 The focus of the documentation should be on the overview content: Doxygen pages
284 and the module documentation.  An experienced developer can relatively easily
285 read and understand individual functions, but the documentation should help
286 in getting the big picture.
287
288 __ doxygen-page-codelayout_
289
290 Doxygen pages
291 ^^^^^^^^^^^^^
292
293 The pages that are accessible through navigation from the front page are
294 written using Markdown and are located under ``docs/doxygen/``.  Each page should be
295 placed in the page hierarchy by making it a subpage of another page, i.e., it
296 should be referenced once using ``\subpage``.  ``mainpage.md`` is the root of the
297 hierarchy.
298
299 There are two subdirectories, ``user/`` and ``lib/``, determining the highest
300 documentation level where the page appears.  If you add pages to ``lib/``, ensure
301 that there are no references to the page from public API documentation.
302 ``\if libapi`` can be used to add references in content that is otherwise
303 public.
304 Generally, the pages should be on a high enough level and provide overview
305 content that is useful enough such that it is not necessary to exclude them
306 from the library API documentation.
307
308 Modules
309 ^^^^^^^
310
311 For each module, decide on a header file that is the most important one for
312 that module (if there is no self-evident header, it may be better to designate,
313 e.g., ``module-doc.h`` for this purpose, but this is currently not done for any
314 module).  This header should contain the ``\defgroup`` definition for the
315 module.  The name of the group should be :file:`module_{name}`, where *name*
316 is the name of the subdirectory that hosts the module.
317
318 The module should be added to an appropriate group (see ``docs/doxygen/misc.cpp`` for
319 definitions) using ``\ingroup`` to organize the "Modules" tab in the generated
320 documentation.
321
322 One or more contact persons who know about the contents of the module should be
323 listed using ``\author`` commands.  This provides a point of contact if one
324 has questions.
325
326 Classes/structs
327 ^^^^^^^^^^^^^^^
328
329 Classes and structs in header files appear always in Doxygen documentation,
330 even if their enclosing file is not documented.  So start the documentation
331 blocks of classes that are not part of the public API with ``\internal`` or
332 ``\libinternal``.  Classes declared locally in source files or in unnamed
333 namespaces only appear in the full documentation.
334
335 If a whole class is not documented, this does not currently generate any
336 warning.  The class is simply exluded from the documentation.  But if a member
337 of a documented class is not documented, a warning is generated.  Guidelines for
338 documenting free functions apply to methods of a class as well.
339
340 For base classes, the API classification (``\inpublicapi`` or
341 ``\inlibraryapi``) should be based on where the class is meant to be
342 subclassed.  The visibility (``\internal`` or ``\libinternal``), in contrast,
343 should reflect the API classification of derived classes such that the base
344 class documentation is always generated together with the derived classes.
345
346 For classes that are meant to be subclassed and have protected members, the
347 protected members should only appear at the documentation level where the class
348 is meant to be subclassed.  For example, if a class is meant to be subclassed
349 only within a module, the protected members should only appear in the
350 full documentation.  This can be accomplished using ``\cond`` (note that you
351 will need to add the ``\cond`` command also to the source files to hide the
352 same methods from Doxygen, otherwise you will get confusing warnings).
353
354 Methods/functions/enums/macros
355 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
356
357 These items do not appear in the documentation unless their enclosing scope is
358 documented.  For class members, the scope is the class; otherwise, it is the
359 namespace if one exists, or the file.  An ``\addtogroup`` can also define a
360 scope if the group has higher visibility than the scope outside it.
361 So if a function is not within a namespace (mostly applicable to C code) and
362 has the same visibility as its enclosing file, it is not necessary to add a
363 ``\internal`` or ``\libinternal``.
364
365 Static functions are currently extracted for all documentation flavors to allow
366 headers to declare ``static inline`` functions (used in, for example, math code).
367 Functions in anonymous namespaces are only extracted into the full
368 documentation.  Together with the above rules, this means that you should avoid
369 putting a ``static`` function within a documented namespace, even within source
370 files, or it may inadvertently appear in the public API documentation.
371
372 If you want to exclude an item from the documentation, you need to put in
373 inside a ``\cond`` block such that Doxygen does not see it.
374 Otherwise, a warning for an undocumented function is generated.  You need to
375 enclose both the declaration and the definition with ``\cond``.
376
377 Files
378 ^^^^^
379
380 Each documented file should start with a documentation block (right after the
381 copyright notice) that documents the file.  See the examples section for exact
382 formatting.  Things to note:
383
384 * Please do not specify the file name explicitly after ``\file``.  By default,
385   a file comment applies to the file it is contained in, and an explicit file
386   name only adds one more thing that can get out of date.
387 * ``\brief`` cannot appear on the same line as the ``\file``, but should be on
388   the next line.
389 * ``\internal`` or ``\libinternal`` should indicate where the header is visible.
390   As a general guideline, all installed headers should appear in the public API
391   documentation, i.e., not contain these commands.  If nothing else, then to
392   document that it does not contain any public API functions.  Headers that
393   declare anything in the library API should be marked with ``\libinternal``,
394   and the rest with ``\internal``.
395 * All source files, as well as most test files, should be documented with
396   ``\internal``, since they do not provide anything to public or library API,
397   and this avoids unintentionally extracting things from the file into those
398   documentations.  Shared test files used in tests from other modules should be
399   marked with ``\libinternal``.
400 * ``\inpublicapi`` or ``\inlibraryapi`` should be used to indicate where the
401   header is meant to be directly included.
402 * As with modules, one or more contact persons should be listed with ``\author``.
403   If you make significant modifications or additions to a file, consider adding
404   an ``\author`` line for yourself.
405
406 Directories
407 ^^^^^^^^^^^
408
409 Directory documentation does not typically contain useful information beyond a
410 possible brief description, since they correspond very closely to modules, and
411 the modules themselves are documented.  A brief description is still useful to
412 provide a high-level overview of the source tree on the generated "Files" page.
413 A reference to the module is typically sufficient as a brief description for a
414 directory.  All directories are currently documented in
415 ``docs/doxygen/directories.cpp``.
416
417
418 Examples
419 --------
420
421 .. highlight:: c++
422
423 Basic C++
424 ^^^^^^^^^
425
426 Here is an example of documenting a C++ class and its containing header file.
427 Comments in the code and the actual documentation explain the used Doxygen
428 constructs. ::
429
430   /*! \libinternal \file
431    * \brief
432    * Declares gmx::MyClass.
433    *
434    * More details.  The documentation is still extracted for the class even if
435    * this whole comment block is missing.
436    *
437    * \author Example Author <example@author.com>
438    * \inlibraryapi
439    * \ingroup module_mymodule
440    */
441
442   namespace gmx
443   {
444
445   /*! \libinternal
446    * \brief
447    * Brief description for the class.
448    *
449    * More details.  The \libinternal tag is required for classes, since they are
450    * extracted into the documentation even in the absence of documentation for
451    * the enclosing scope.
452    * The \libinternal tag is on a separate line because of a bug in Doxygen
453    * 1.8.5 (only affects \internal, but for clarity it is also worked around
454    * here).
455    *
456    * \inlibraryapi
457    * \ingroup module_mymodule
458    */
459   class MyClass
460   {
461       public:
462           // Trivial constructors or destructors do not require documentation.
463           // But if a constructor takes parameters, it should be documented like
464           // methods below.
465           MyClass();
466           ~MyClass();
467
468           /*! \brief
469            * Brief description for the method.
470            *
471            * \param[in] param1  Description of the first parameter.
472            * \param[in] param2  Description of the second parameter.
473            * \returns   Description of the return value.
474            * \throws    std::bad_alloc if out of memory.
475            *
476            * More details describing the method.  It is not an error to put this
477            * above the parameter block, but most existing code has it here.
478            */
479           int myMethod(int param1, const char *param2) const;
480
481           //! Brief description for the accessor.
482           int simpleAccessor() const { return var_; }
483           /*! \brief
484            * Alternative, more verbose way of specifying a brief description.
485            */
486           int anotherAccessor() const;
487           /*! \brief
488            * Brief description for another accessor that is so long that it does
489            * not conveniently fit on a single line cannot be specified with //!.
490            */
491           int secondAccessor() const;
492
493       private:
494           // Private members (whether methods or variables) are currently ignored
495           // by Doxygen, so they don't need to be documented.  Documentation
496           // doesn't hurt, though.
497           int var_;
498   };
499
500   } // namespace gmx
501
502 Basic C
503 ^^^^^^^
504
505 Here is another example of documenting a C header file (so avoiding all
506 C++-style comments), and including free functions.  It also demonstrates the use
507 of ``\addtogroup`` to add multiple functions into a module group without repeated
508 ``\ingroup`` tags. ::
509
510   /*! \file
511    * \brief
512    * Declares a collection of functions for performing a certain task.
513    *
514    * More details can go here.
515    *
516    * \author Example Author <example@author.com>
517    * \inpublicapi
518    * \ingroup module_mymodule
519    */
520
521   /*! \addtogroup module_mymodule */
522   /*! \{ */
523
524   /*! \brief
525    * Brief description for the data structure.
526    *
527    * More details.
528    *
529    * \inpublicapi
530    */
531   typedef struct {
532       /** Brief description for member. */
533       int  member;
534       int  second; /**< Brief description for the second member. */
535       /*! \brief
536        * Brief description for the third member.
537        *
538        * Details.
539        */
540       int  third;
541   } gmx_mystruct_t;
542
543   /*! \brief
544    * Performs a simple operation.
545    *
546    * \param[in] value  Input value.
547    * \returns   Computed value.
548    *
549    * Detailed description.
550    * \inpublicapi cannot be used here, because Doxygen only allows a single
551    * group for functions, and module_mymodule is the preferred group.
552    */
553   int gmx_function(int value);
554
555   /* Any . in the brief description should be escaped as \. */
556   /** Brief description for this function. */
557   int gmx_simple_function();
558
559   /*! \} */
560
561 Scoping and visibility rules
562 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
563
564 The rules where Doxygen expects something to be documented, and when are
565 commands like ``\internal`` needed, can be complex.  The examples below
566 describe some of the pitfalls. ::
567
568   /*! \libinternal \file
569    * \brief
570    * ...
571    *
572    * The examples below assume that the file is documented like this:
573    * with an \libinternal definition at the beginning, with an intent to not
574    * expose anything from the file in the public API.  Things work similarly for
575    * the full documentation if you replace \libinternal with \internal
576    * everywhere in the example.
577    *
578    * \ingroup module_example
579    */
580
581
582   /*! \brief
583    * Brief description for a free function.
584    *
585    * A free function is not extracted into the documentation unless the enclosing
586    * scope (in this case, the file) is.  So a \libinternal is not necessary.
587    */
588   void gmx_function();
589
590   // Assume that the module_example group is defined in the public API.
591
592   //! \addtogroup module_example
593   //! \{
594
595   //! \cond libapi
596   /*! \brief
597    * Brief description for a free function within \addtogroup.
598    *
599    * In this case, the enclosing scope is actually the module_example group,
600    * which is documented, so the function needs to be explicitly excluded.
601    * \\libinternal does not work, since it would produce warnings about an
602    * undocumented function, so the whole declaration is hidden from Doxygen.
603    */
604   void gmx_function();
605   //! \endcond
606
607   //! \}
608
609   // For modules that are only declared in the library API, \addtogroup
610   // cannot be used without an enclosing \cond.  Otherwise, it will create
611   // a dummy module with the identifier as the name...
612
613   //! \cond libapi
614   //! \addtogroup module_libmodule
615   //! \{
616
617   /*! \brief
618    * Brief description.
619    *
620    * No \libinternal is necessary here because of the enclosing \cond.
621    */
622   void gmx_function();
623
624   //! \}
625   //! \endcond
626
627   // An alternative to the above is use this, if the enclosing scope is only
628   // documented in the library API:
629
630   //! \libinternal \addtogroup module_libmodule
631   //! \{
632
633   //! Brief description.
634   void gmx_function()
635
636   //! \}
637
638   /*! \libinternal \brief
639    * Brief description for a struct.
640    *
641    * Documented structs and classes from headers are always extracted into the
642    * documentation, so \libinternal is necessary to exclude it.
643    * Currently, undocumented structs/classes do not produce warnings, so \cond
644    * is not necessary.
645    */
646   struct t_example
647   {
648       int  member1; //!< Each non-private member should be documented.
649       bool member2; //!< Otherwise, Doxygen will produce warnings.
650   };
651
652   // This namespace is documented in the public API.
653   namespace gmx
654   {
655
656   //! \cond libapi
657   /*! \brief
658    * Brief description for a free function within a documented namespace.
659    *
660    * In this case, the enclosing scope is the documented namespace,
661    * so a \cond is necessary to avoid warnings.
662    */
663   void gmx_function();
664   //! \endcond
665
666   /*! \brief
667    * Class meant for subclassing only within the module, but the subclasses will
668    * be public.
669    *
670    * This base class still provides public methods that are visible through the
671    * subclasses, so it should appear in the public documentation.
672    * But it is not marked with \inpublicapi.
673    */
674   class BaseClass
675   {
676       public:
677           /*! \brief
678            * A public method.
679            *
680            * This method also appears in the documentation of each subclass in
681            * the public and library API docs.
682            */
683           void method();
684
685       protected:
686           // The \cond is necessary to exlude this documentation from the public
687           // API, since the public API does not support subclassing.
688           //! \cond internal
689           //! A method that only subclasses inside the module see.
690           void methodForSubclassToCall();
691
692           //! A method that needs to be implemented by subclasses.
693           virtual void virtualMethodToImplement() = 0;
694           //! \endcond
695   };
696
697   } // namespace gmx
698
699 Module documentation
700 ^^^^^^^^^^^^^^^^^^^^
701
702 Documenting a new module should place a comment like this in a central header
703 for the module, such that the "Modules" tab in the generated documentation can
704 be used to navigate to the module. ::
705
706   /*! \defgroup module_example "Example module (example)"
707    * \ingroup group_utilitymodules
708    * \brief
709    * Brief description for the module.
710    *
711    * Detailed description of the module.  Can link to a separate Doxygen page for
712    * overview, and/or describe the most important headers and/or classes in the
713    * module as part of this documentation.
714    *
715    * For modules not exposed publicly, \libinternal can be added at the
716    * beginning (before \defgroup).
717    *
718    * \author Author Name <author.name@email.com>
719    */
720
721   // In other code, use \addtogroup module_example and \ingroup module_example to
722   // add content (classes, functions, etc.) onto the module page.
723
724 Common mistakes
725 ^^^^^^^^^^^^^^^
726
727 The most common mistake, in particular in C code, is to forget to document the
728 file.  This causes Doxygen to ignore most comments in the file, so it
729 does not validate the contents of the comments either, nor is it possible to
730 actually check how the generated documentation looks like.
731
732 The following examples show some other common mistakes (and some less common)
733 that do not produce correct documentation, as well as Doxygen "features"/bugs
734 that can be confusing.
735
736 * The struct itself is not documented; other comments within the declaration
737   are ignored. ::
738
739     struct t_struct {
740
741         // The comment tries to document both members at once, but it only
742         // applies to the first.  The second produces warnings about missing
743         // documentation (if the enclosing struct was documented).
744
745         //! Angle parameters.
746         double alpha, beta;
747     };
748
749 * This does not produce any brief documentation.
750   An explicit ``\brief`` is required, or ``//!`` (C++) or ``/** */`` (C)
751   should be used. ::
752
753     /*! Brief comment. */
754     int gmx_function();
755
756 * This does not produce any documentation at all, since a ``!`` is missing at
757   the beginning. ::
758
759     /* \brief
760      * Brief description.
761      *
762      * More details.
763      */
764     int gmx_function();
765
766 * This puts the whole paragraph into the brief description.
767   A short description is preferable, separated by an empty line from the rest
768   of the text. ::
769
770     /*! \brief
771      * Brief description. The description continues with all kinds of details about
772      * what the function does and how it should be called.
773      */
774     int gmx_function();
775
776 * This may be a Doxygen bug, but this does not produce any brief description. ::
777
778     /** \internal Brief description. */
779     int gmx_function();
780
781 * If the first declaration below appears in a header, and the second in a
782   source file, then Doxygen does not associate them correctly and complains
783   about missing documentation for the latter.  The solution is to explicitly
784   add a namespace prefix also in the source file, even though the compiler
785   does not require it. ::
786
787     // Header file
788     //! Example function with a namespace-qualified parameter type.
789     int gmx_function(const gmx::SomeClass &param);
790
791     // Source file
792     using gmx::SomeClass;
793
794     int gmx_function(const SomeClass &param);
795
796 * This puts the namespace into the mentioned module, instead of the contents
797   of the namespace.  ``\addtogroup`` should go within the innermost scope. ::
798
799     //! \addtogroup module_example
800     //! \{
801
802     namespace gmx
803     {
804
805     //! Function intended to be part of module_example.
806     int gmx_function();
807
808     }
809
810 Existing code
811 ^^^^^^^^^^^^^
812
813 More examples you can find by looking at existing code in the source tree.  In
814 particular new C++ code such as that in the ``src/gromacs/analysisdata/`` and
815 ``src/gromacs/options/`` subdirectories contains a large amount of code
816 documented mostly along these guidelines.  Some comments in
817 ``src/gromacs/selection/`` (in particular, any C-like code) predate the
818 introduction of these guidelines, so those are not the best examples.
819
820 .. include:: doxygen-links.rst