Guidelines for API documentation » History » Version 3
neels, 06/20/2017 01:59 AM
1 | 1 | neels | h1. Guidelines for API documentation |
---|---|---|---|
2 | |||
3 | We use doxygen for API documentation, following these guidelines: |
||
4 | |||
5 | Use the @/*!@ (Qt-style) doxygen markers. |
||
6 | |||
7 | Since we are using the AUTOBRIEF feature, always end the first sentence with a full-stop "." to mark the end of the short description. |
||
8 | This allows omitting the @\brief@ markers everywhere. |
||
9 | |||
10 | Never rely on line breaks as semantic separation or to end a sentence, always use proper punctuation. The API doc may be rendered with different line breaks than in the source file. |
||
11 | |||
12 | h2. File comments |
||
13 | |||
14 | If a file contains a descriptive comment, this comment should be right at the start of the file, as a doxygen @\file@ section. |
||
15 | The first sentence must be ended by a full stop "." to mark the end of the short description. |
||
16 | The copyright notice shall not be part of such API doc file comment. |
||
17 | |||
18 | <pre> |
||
19 | /*! \file foo.c |
||
20 | * Short description. */ |
||
21 | /* |
||
22 | * (C) 2017 ... Copyright not in a doxygen comment |
||
23 | * license information |
||
24 | */ |
||
25 | </pre> |
||
26 | |||
27 | or |
||
28 | |||
29 | <pre> |
||
30 | /*! \file foo.c |
||
31 | * Short description. |
||
32 | * |
||
33 | * More information in multiple lines. |
||
34 | */ |
||
35 | /* |
||
36 | * (C) 2017 ... |
||
37 | */ |
||
38 | </pre> |
||
39 | |||
40 | h2. Groups |
||
41 | |||
42 | Doxygen allows grouping elements: a group can include code elements and also entire files. |
||
43 | |||
44 | This works by enclosing the items to be grouped between an opening and a closing marker: |
||
45 | |||
46 | * A @\defgroup@ initially defines a group, this shall exist only once. |
||
47 | * More items can be added using an @\addtogroup@ marker. |
||
48 | * Both have to be closed by "@}". |
||
49 | |||
50 | For example: |
||
51 | |||
52 | <pre> |
||
53 | /*! \defgroup groupname Short description of the group. |
||
54 | * @{ |
||
55 | */ |
||
56 | |||
57 | struct type_that_belongs_to_group { |
||
58 | ... |
||
59 | }; |
||
60 | |||
61 | void func_that_belongs_to_group() |
||
62 | { |
||
63 | ... |
||
64 | } |
||
65 | |||
66 | /*! @} */ |
||
67 | </pre> |
||
68 | |||
69 | and |
||
70 | |||
71 | <pre> |
||
72 | /*! \addtogroup groupname |
||
73 | * @{ |
||
74 | */ |
||
75 | |||
76 | 3 | neels | ... |
77 | 1 | neels | |
78 | /*! @} */ |
||
79 | </pre> |
||
80 | |||
81 | If a *file* should be added to a group, add a (possibly) second, short descriptionless @\file@ tag to the group start. To clearly mark that the purpose is to add to the group, do so within the same comment block: |
||
82 | |||
83 | <pre> |
||
84 | /*! \file foo.c |
||
85 | 2 | neels | * File's description. */ |
86 | 1 | neels | /* |
87 | * (C) ... |
||
88 | */ |
||
89 | |||
90 | /*! \addtogroup groupname |
||
91 | * @{ |
||
92 | * \file foo.c */ |
||
93 | |||
94 | ... |
||
95 | |||
96 | /*! @} */ |
||
97 | </pre> |
||
98 | |||
99 | The point is that we like to have a file's short description near the start of the file, to also serve us well when we're reading only the .h file. But to be included in a group, the doxygen group start must precede the @\file@ tag. Also, the doxygen group should rather not enclose @#include@ directives, to clearly exclude those from the group. Hence, the best way is to keep the file's actual description at the top of the file, and add a second descriptionless @\file@ with the group opening. |
||
100 | |||
101 | A group may contain a short as well as a longer description. We often @\defgroup@ in a @.h@ file but keep the longer description in an @\addtogroup@ in a @.c@ file. Any @\file@ tags must follow *after* such description, or the description will be associated with the file instead of the group: |
||
102 | |||
103 | @.h@ file: |
||
104 | <pre> |
||
105 | /*! \defgroup groupname Short description of the group. |
||
106 | * @{ |
||
107 | */ |
||
108 | |||
109 | ... |
||
110 | |||
111 | /*! @} */ |
||
112 | </pre> |
||
113 | |||
114 | @.c file: |
||
115 | |||
116 | <pre> |
||
117 | /*! \addtogroup groupname |
||
118 | * @{ |
||
119 | * Longer description of the group. |
||
120 | * - contains a |
||
121 | * - bullet list |
||
122 | * |
||
123 | * As well as a |
||
124 | * |
||
125 | * Code example |
||
126 | * block |
||
127 | * |
||
128 | * All of which must not be below the directive adding this file to the group: |
||
129 | * |
||
130 | * \file foo.c */ |
||
131 | |||
132 | [...] |
||
133 | |||
134 | /*! @} */ |
||
135 | </pre> |
||
136 | |||
137 | Often, a file's description matches or is identical with a group's description. In that case, the file's description header comment can be omitted to avoid duplicating identical descriptions. |
||
138 | |||
139 | <pre> |
||
140 | /* |
||
141 | * (C) 2017 ... |
||
142 | */ |
||
143 | |||
144 | /* \addtogroup group |
||
145 | * @{ |
||
146 | * Description... |
||
147 | * |
||
148 | * \file foo.c */ |
||
149 | |||
150 | ... |
||
151 | |||
152 | /* @} */ |
||
153 | </pre> |