Project

General

Profile

Guidelines for API documentation » History » Version 5

neels, 06/20/2017 02:12 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 4 neels
h2. Locations
13
14
Header files usually contain merely function declarations bare of any API docs. The API doc comment should be in a @.c@ file at the definition of a function.
15
16
Structs and enums defined in a header file, though, also have their API doc comments in that @.h@ file.
17
18
h2. Grammar
19
20
Always use the imperative form, i.e. omit wording like "This function does", and avoid writing documentation that merely mirrors a function's name. For example:
21
22
<pre>
23
/*! Return a (static) buffer containing a hexdump of the msg.
24
 * \param[in] msg message buffer
25
 * \returns a pointer to a static char array
26
 */
27
const char *msgb_hexdump(const struct msgb *msg)
28
{
29
...
30
</pre>
31
32
33
h2. Parameters
34
35
All parameters of a function should be documented. Input params are documented with @\param[in]@, where out-parameters (pointers to which returned data is written) are documented with @\param[out]@. Rarely, a param is both: @\param[inout]@.
36
37
<pre>
38
/*! Apply nifty algorithm.
39
 * \param[in] x0  First factor.
40
 * \param[in] n   Amount of values to calculate.
41
 * \param[out] buf  Write calculated values to this buffer.
42
 *
43
 * Optional longer function description. */
44
</pre>
45
46 1 neels
h2. File comments
47
48
If a file contains a descriptive comment, this comment should be right at the start of the file, as a doxygen @\file@ section.
49
The first sentence must be ended by a full stop "." to mark the end of the short description.
50
The copyright notice shall not be part of such API doc file comment.
51
52
<pre>
53
/*! \file foo.c
54
 * Short description. */
55
/*
56
 * (C) 2017 ... Copyright not in a doxygen comment
57
 * license information
58
 */
59
</pre>
60
61
or
62
63
<pre>
64
/*! \file foo.c
65
 * Short description.
66
 *
67
 * More information in multiple lines.
68
 */
69
/*
70
 * (C) 2017 ...
71
 */
72
</pre>
73
74
h2. Groups
75
76
Doxygen allows grouping elements: a group can include code elements and also entire files.
77
78
This works by enclosing the items to be grouped between an opening and a closing marker:
79
80
* A @\defgroup@ initially defines a group, this shall exist only once.
81
* More items can be added using an @\addtogroup@ marker.
82
* Both have to be closed by "@}".
83
84
For example:
85
86
<pre>
87
/*! \defgroup groupname Short description of the group.
88
 * @{
89
 */
90
91
struct type_that_belongs_to_group {
92
 ...
93
};
94
95
void func_that_belongs_to_group()
96
{
97
 ...
98
}
99
100
/*! @} */
101
</pre>
102
103
and 
104
105
<pre>
106
/*! \addtogroup groupname
107
 * @{
108
 */
109
110 3 neels
...
111 1 neels
112
/*! @} */
113
</pre>
114
115 5 neels
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:
116 1 neels
117
<pre>
118
/*! \file foo.c
119 2 neels
 * File's description. */
120 1 neels
/*
121
 * (C) ...
122
 */
123
124
/*! \addtogroup groupname
125
 * @{
126
 * \file foo.c */
127
128
...
129
130
/*! @} */
131
</pre>
132
133
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.
134
135
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:
136
137
@.h@ file:
138
<pre>
139
/*! \defgroup groupname Short description of the group.
140
 * @{
141
 */
142
143
...
144
145
/*! @} */
146
</pre>
147
148
@.c file:
149
150
<pre>
151
/*! \addtogroup groupname
152
 * @{
153
 * Longer description of the group.
154
 * - contains a
155
 * - bullet list
156
 * 
157
 * As well as a 
158
 *
159
 *     Code example
160
 *     block
161
 *
162
 * All of which must not be below the directive adding this file to the group:
163
 *
164
 * \file foo.c */
165
166
[...]
167
168
/*! @} */
169
</pre>
170
171
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.
172
173
<pre>
174
/*
175
 * (C) 2017 ...
176
 */
177
178
/* \addtogroup group
179
 * @{
180
 * Description...
181
 *
182
 * \file foo.c */
183
184
...
185
186
/* @} */
187
</pre>
Add picture from clipboard (Maximum size: 48.8 MB)