Orb/Doxygen/doc/docblocks.doc
changeset 0 42188c7ea2d9
equal deleted inserted replaced
-1:000000000000 0:42188c7ea2d9
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
       
     6  *
       
     7  * Permission to use, copy, modify, and distribute this software and its
       
     8  * documentation under the terms of the GNU General Public License is hereby 
       
     9  * granted. No representations are made about the suitability of this software 
       
    10  * for any purpose. It is provided "as is" without express or implied warranty.
       
    11  * See the GNU General Public License for more details.
       
    12  *
       
    13  * Documents produced by Doxygen are derivative works derived from the
       
    14  * input used in their production; they are not affected by this license.
       
    15  *
       
    16  */
       
    17 /*! \page docblocks Documenting the code
       
    18 
       
    19 \section specialblock Special documentation blocks
       
    20 
       
    21 A special documentation block is a C or C++ style comment block with some 
       
    22 additional markings, so doxygen knows it is a piece of documentation that
       
    23 needs to end up in the generated documentation. For Python and VHDL
       
    24 code there are a different comment conventions, which can be found in section 
       
    25 \ref pythonblocks and \ref vhdlblocks respectively.
       
    26 
       
    27 For each code item there are two (or in some cases three) types of descriptions, 
       
    28 which together form the documentation: a \e brief description and \e detailed
       
    29 description, both are optional. For methods and functions there is also a third
       
    30 type of description, the so called "in body" description, which consists of 
       
    31 the concatenation of all comment blocks found within the body of the method or function.
       
    32 
       
    33 Having more than one brief or detailed description is allowed (but not recommended,
       
    34 as the order in which the descriptions will appear is not specified).
       
    35 
       
    36 As the name suggest, a brief description is
       
    37 a short one-liner, whereas the detailed description provides longer, 
       
    38 more detailed documentation. An "in body" description can also act as a detailed
       
    39 description or can describe a collection of implementation details.
       
    40 For the HTML output brief descriptions are also
       
    41 use to provide tooltips at places where an item is referenced.
       
    42 
       
    43 There are several ways to mark a comment block as a detailed description:
       
    44 <ol>
       
    45 <li> You can use the JavaDoc style, which consist of a C-style comment
       
    46 block starting with two *'s, like this:
       
    47 
       
    48 \verbatim
       
    49 /**
       
    50  * ... text ...
       
    51  */
       
    52 \endverbatim
       
    53 
       
    54 <li> or you can use the Qt style and add an exclamation mark (!) 
       
    55 after the opening of a C-style comment block, as shown in this example:
       
    56 
       
    57 \verbatim
       
    58 /*!
       
    59  * ... text ...
       
    60  */
       
    61 \endverbatim
       
    62 
       
    63 In both cases the intermediate *'s are optional, so
       
    64 
       
    65 \verbatim
       
    66 /*!
       
    67  ... text ...
       
    68 */
       
    69 \endverbatim
       
    70 
       
    71 is also valid.
       
    72 
       
    73 <li> A third alternative is to use a block of <i>at least two</i> C++ comment 
       
    74 lines, where each line starts with an additional slash or an 
       
    75 exclamation mark. Here are examples of the two cases:
       
    76 
       
    77 \verbatim
       
    78 ///
       
    79 /// ... text ...
       
    80 ///
       
    81 \endverbatim
       
    82 
       
    83 or
       
    84 
       
    85 \verbatim
       
    86 //!
       
    87 //!... text ...
       
    88 //!
       
    89 \endverbatim
       
    90 
       
    91 Note that a blank line ends a documentation block in this case.
       
    92 
       
    93 <li>
       
    94 
       
    95 Some people like to make their comment blocks more visible in the
       
    96 documentation. For this purpose you can use the following:
       
    97 
       
    98 \verbatim
       
    99 /********************************************//**
       
   100  *  ... text
       
   101  ***********************************************/
       
   102 \endverbatim
       
   103 (note the 2 slashes to end the normal comment block and start a special comment block).
       
   104 
       
   105 or
       
   106 
       
   107 \verbatim
       
   108 /////////////////////////////////////////////////
       
   109 /// ... text ...
       
   110 /////////////////////////////////////////////////
       
   111 \endverbatim
       
   112 
       
   113 </ol>
       
   114 
       
   115 For the brief description there are also several posibilities:
       
   116 <ol>
       
   117 <li>One could use the \ref cmdbrief "\\brief" command with one of the 
       
   118 above comment blocks. This command ends at the end of a paragraph, 
       
   119 so the detailed description follows after an empty line.
       
   120 
       
   121 Here is an example:
       
   122 
       
   123 \verbatim
       
   124 /*! \brief Brief description.
       
   125  *         Brief description continued.
       
   126  *
       
   127  *  Detailed description starts here.
       
   128  */
       
   129 \endverbatim
       
   130 
       
   131 <li>If \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" is set to \c YES 
       
   132     in the configuration file, 
       
   133     then using JavaDoc style comment
       
   134     blocks will automatically start a brief description which ends at the
       
   135     first dot followed by a space or new line. Here is an example:
       
   136 
       
   137 \verbatim
       
   138 /** Brief description which ends at this dot. Details follow
       
   139  *  here.
       
   140  */
       
   141 \endverbatim
       
   142 The option has the same effect for multi-line special C++ comments:
       
   143 \verbatim
       
   144 /// Brief description which ends at this dot. Details follow
       
   145 /// here.
       
   146 \endverbatim
       
   147 
       
   148 <li>A third option is to use a special C++ style comment which does not 
       
   149     span more than one line. Here are two examples:
       
   150 \verbatim
       
   151 /// Brief description.
       
   152 /** Detailed description. */
       
   153 \endverbatim
       
   154 
       
   155 or
       
   156 
       
   157 \verbatim
       
   158 //! Brief descripion.
       
   159 
       
   160 //! Detailed description 
       
   161 //! starts here.
       
   162 \endverbatim
       
   163 
       
   164 Note the blank line in the last example, which is required to separate the 
       
   165 brief description from the block containing the detailed description. The
       
   166 \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" should also be set to \c NO
       
   167 for this case.
       
   168 
       
   169 </ol>
       
   170 
       
   171 As you can see doxygen is quite flexible. If you have multiple
       
   172 detailed descriptions, like in the following example:
       
   173 
       
   174 \verbatim
       
   175 //! Brief description, which is
       
   176 //! really a detailed description since it spans multiple lines.
       
   177 /*! Another detailed description!
       
   178  */
       
   179 \endverbatim
       
   180 
       
   181 They will be joined. Note that this is also the case if the descriptions
       
   182 are at different places in the code! In this case the order will depend
       
   183 on the order in which doxygen parses the code.
       
   184 
       
   185 Here is an example of a documented piece of C++ code using the Qt style:
       
   186 \include qtstyle.cpp
       
   187  \htmlonly
       
   188  Click <a href="$(DOXYGEN_DOCDIR)/examples/qtstyle/html/class_test.html">here</a>
       
   189  for the corresponding HTML documentation that is generated by doxygen.
       
   190  \endhtmlonly
       
   191 
       
   192 The one-line comments contain a brief description, 
       
   193 whereas the multi-line comment blocks contain a more detailed description.
       
   194 
       
   195 The brief descriptions are included in the member overview of a 
       
   196 class, namespace or file and are printed using a small italic font 
       
   197 (this description can be hidden by setting 
       
   198 \ref cfg_brief_member_desc "BRIEF_MEMBER_DESC" to \c NO in 
       
   199 the config file). By default the brief descriptions become the first 
       
   200 sentence of the detailed descriptions 
       
   201 (but this can be changed by setting the \ref cfg_repeat_brief "REPEAT_BRIEF" 
       
   202 tag to \c NO). Both the brief and the detailed descriptions are optional 
       
   203 for the Qt style. 
       
   204 
       
   205 By default a JavaDoc style documentation block behaves the same way as a
       
   206 Qt style documentation block. This is not according the JavaDoc specification
       
   207 however, where the first sentence of the documentation block is automatically
       
   208 treated as a brief description. To enable this behaviour you should set
       
   209 \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" to YES in the configuration
       
   210 file. If you enable this option and want to put a dot in the middle of a
       
   211 sentence without ending it, you should put a backslash and a space after it.
       
   212 Here is an example:
       
   213 \verbatim
       
   214   /** Brief description (e.g.\ using only a few words). Details follow. */
       
   215 \endverbatim
       
   216 
       
   217 Here is the same piece of code as shown above, this time documented using the 
       
   218 JavaDoc style and \ref cfg_javadoc_autobrief "JAVADOC_AUTOBRIEF" set to YES:
       
   219 \include jdstyle.cpp
       
   220  \htmlonly
       
   221  Click <a href="$(DOXYGEN_DOCDIR)/examples/jdstyle/html/class_test.html">here</a>
       
   222  for the corresponding HTML documentation that is generated by doxygen.
       
   223  \endhtmlonly
       
   224 
       
   225 Similarly, if one wishes the first sentence of a Qt style documentation
       
   226 block to automatically be treated as a brief description, one may set
       
   227 \ref cfg_qt_autobrief "QT_AUTOBRIEF" to YES in the configuration file.
       
   228 
       
   229 Unlike most other documentation systems, doxygen also allows you to put
       
   230 the documentation of members (including global functions) in front of 
       
   231 the \e definition. This way the documentation can be placed in the source 
       
   232 file instead of the header file. This keeps the header file compact, and allows the 
       
   233 implementer of the members more direct access to the documentation.
       
   234 As a compromise the brief description could be placed before the
       
   235 declaration and the detailed description before the member definition.
       
   236 
       
   237 \section memberdoc Putting documentation after members 
       
   238 
       
   239 If you want to document the members of a file, struct, union, class, or enum,
       
   240 and you want to put the documentation for these members inside the compound,
       
   241 it is sometimes desired to place the documentation block after the member 
       
   242 instead of before. For this purpose you have to put an additional \< marker
       
   243 in the comment block. Note that this also works for the parameters 
       
   244 of a function.
       
   245 
       
   246 Here are some examples:
       
   247 \verbatim
       
   248 int var; /*!< Detailed description after the member */
       
   249 \endverbatim
       
   250 This block can be used to put a Qt style detailed 
       
   251 documentation block \e after a member. Other ways to do the
       
   252 same are:
       
   253 \verbatim
       
   254 int var; /**< Detailed description after the member */
       
   255 \endverbatim
       
   256 or 
       
   257 \verbatim
       
   258 int var; //!< Detailed description after the member
       
   259          //!< 
       
   260 \endverbatim
       
   261 or 
       
   262 \verbatim
       
   263 int var; ///< Detailed description after the member
       
   264          ///< 
       
   265 \endverbatim
       
   266 
       
   267 Most often one only wants to put a brief description after a member.
       
   268 This is done as follows:
       
   269 \verbatim
       
   270 int var; //!< Brief description after the member
       
   271 \endverbatim
       
   272 or
       
   273 \verbatim
       
   274 int var; ///< Brief description after the member
       
   275 \endverbatim
       
   276 
       
   277 For functions one can use \@param to document the parameters
       
   278 and then use <code>[in]</code>, <code>[out]</code>, <code>[in,out]</code> 
       
   279 to document the direction. For inline documentation this is also possible 
       
   280 by starting with the direction attribute, e.g.
       
   281 \verbatim
       
   282 void foo(int v /**< [in] docs for input parameter v. */);
       
   283 \endverbatim
       
   284 
       
   285 Note that these blocks have the same structure and meaning as the 
       
   286 special comment blocks in the previous section 
       
   287 only the \< indicates that the member is 
       
   288 located in front of the block instead of after the block.
       
   289 
       
   290 Here is an example of the use of these comment blocks:
       
   291 \include afterdoc.h
       
   292  \htmlonly
       
   293  Click <a href="$(DOXYGEN_DOCDIR)/examples/afterdoc/html/class_test.html">here</a>
       
   294  for the corresponding HTML documentation that is generated by doxygen.
       
   295  \endhtmlonly
       
   296 
       
   297 \warning These blocks can only be used to document \e members and \e parameters.
       
   298          They cannot be used to document files, classes, unions, structs,
       
   299          groups, namespaces and enums themselves. Furthermore, the structural 
       
   300          commands mentioned in the next section 
       
   301          (like <code>\\class</code>) are not allowed 
       
   302          inside these comment blocks.
       
   303 
       
   304 \section structuralcommands Documentation at other places
       
   305 
       
   306 So far we have assumed that the documentation blocks are always located \e in 
       
   307 \e front of the declaration or definition of a file, class or namespace or in
       
   308 front or after one of its members. 
       
   309 Although this is often comfortable, there may sometimes be reasons to put the 
       
   310 documentation somewhere else. For documenting a file this is even 
       
   311 required since there is no such thing as "in front of a file". 
       
   312 
       
   313 Doxygen allows you to put your documentation blocks practically 
       
   314 anywhere (the exception is inside the body of a function or inside a 
       
   315 normal C style comment block). 
       
   316 
       
   317 The price you pay for not putting the
       
   318 documentation block directly before (or after) an item is the need to put a  
       
   319 structural command inside the documentation block, which leads to some
       
   320 duplication of information. So in practice you should \e avoid the use of
       
   321 structural commands \e unless other requirements force you to do so.
       
   322 
       
   323 Structural commands (like all other commands) start with a backslash 
       
   324 (<tt>\\</tt>), or an at-sign (<tt>\@</tt>) if you prefer JavaDoc style, 
       
   325 followed by a command name and one or more parameters.
       
   326 For instance, if you want to document the class \c Test in the example
       
   327 above, you could have also put the following documentation block somewhere
       
   328 in the input that is read by doxygen:
       
   329 \verbatim
       
   330 /*! \class Test
       
   331     \brief A test class.
       
   332 
       
   333     A more detailed class description.
       
   334 */
       
   335 \endverbatim
       
   336 
       
   337 Here the special command \c \\class is used to indicate that the
       
   338 comment block contains documentation for the class \c Test.
       
   339 Other structural commands are:
       
   340 <ul>
       
   341 <li>\c \\struct to document a C-struct.
       
   342 <li>\c \\union to document a union.
       
   343 <li>\c \\enum to document an enumeration type.
       
   344 <li>\c \\fn to document a function.
       
   345 <li>\c \\var to document a variable or typedef or enum value.
       
   346 <li>\c \\def to document a \#define.
       
   347 <li>\c \\typedef to document a type definition.
       
   348 <li>\c \\file to document a file.
       
   349 <li>\c \\namespace to document a namespace.
       
   350 <li>\c \\package to document a Java package.
       
   351 <li>\c \\interface to document an IDL interface.
       
   352 </ul>
       
   353 See section \ref commands for detailed information about these and many other 
       
   354 commands. 
       
   355 
       
   356 To document a member of a C++ class, you must also document the class 
       
   357 itself. The same holds for namespaces. To document a global C function, 
       
   358 typedef, enum or preprocessor definition you must first document the file 
       
   359 that contains it (usually this will be a header file, because that file 
       
   360 contains the information that is exported to other source files).
       
   361 
       
   362 Let's repeat that, because it is often overlooked:
       
   363 to document global objects (functions, typedefs, enum, macros, etc), you
       
   364 <em>must</em> document the file in which they are defined. In other words, 
       
   365 there <em>must</em> at least be a \verbatim /*! \file */ \endverbatim
       
   366 or a \verbatim /** @file */ \endverbatim line in this file.
       
   367 
       
   368 Here is an example of a C header named \c structcmd.h that is documented 
       
   369 using structural commands:
       
   370 \include structcmd.h
       
   371  \htmlonly
       
   372  Click <a href="$(DOXYGEN_DOCDIR)/examples/structcmd/html/structcmd_8h.html">here</a>
       
   373  for the corresponding HTML documentation that is generated by doxygen.
       
   374  \endhtmlonly
       
   375 
       
   376  Because each comment block in the example above contains a structural command, all
       
   377  the comment blocks could be moved to another location or input file 
       
   378  (the source file for instance), without affecting the generated 
       
   379  documentation. The disadvantage of this approach is that prototypes are
       
   380  duplicated, so all changes have to be made twice! Because of this you
       
   381  should first consider if this is really needed, and avoid structural
       
   382  commands if possible. I often receive examples that contain \\fn command
       
   383  in comment blocks which are place in front of a function. This is clearly
       
   384  a case where the \\fn command is redundant and will only lead to problems.
       
   385 
       
   386 \section pythonblocks Special documentation blocks in Python
       
   387 
       
   388 For Python there is a standard way of documenting the code using 
       
   389 so called documentation strings. Such strings are stored in \c __doc__
       
   390 and can be retrieved at runtime. Doxygen will extract such comments
       
   391 and assume they have to be represented in a preformatted way.
       
   392 
       
   393 \include docstring.py
       
   394  \htmlonly
       
   395  Click <a href="$(DOXYGEN_DOCDIR)/examples/docstring/html/index.html">here</a>
       
   396  for the corresponding HTML documentation that is generated by doxygen.
       
   397  \endhtmlonly
       
   398 
       
   399 Note that in this case none of doxygen's \ref cmd_intro "special commands" 
       
   400 are supported.
       
   401 
       
   402 There is also another way to document Python code using comments that 
       
   403 start with "##". These type of comment blocks are more in line with the 
       
   404 way documentation blocks work for the other languages supported by doxygen 
       
   405 and this also allows the use of special commands. 
       
   406 
       
   407 Here is the same example again but now using doxygen style comments:
       
   408 
       
   409 \include pyexample.py
       
   410  \htmlonly
       
   411  Click <a href="$(DOXYGEN_DOCDIR)/examples/pyexample/html/index.html">here</a>
       
   412  for the corresponding HTML documentation that is generated by doxygen.
       
   413  \endhtmlonly
       
   414 
       
   415 Since python looks more like Java than like C or C++, you should set 
       
   416 \ref cfg_optimize_output_java "OPTMIZE_OUTPUT_JAVA" to \c YES in the
       
   417 config file. 
       
   418 
       
   419 
       
   420 \htmlonly
       
   421 Go to the <a href="lists.html">next</a> section or return to the
       
   422  <a href="index.html">index</a>.
       
   423 \endhtmlonly
       
   424 
       
   425 \section vhdlblocks Special documentation blocks in VHDL
       
   426 
       
   427 For VHDL a comment normally start with "--". Doxygen will extract comments
       
   428 starting with "--!". There are only two types of comment blocks in VHDL;
       
   429 a one line --! comment representing a brief description, and a multiline
       
   430 --! comment (where the --! prefix is repeated for each line) representing
       
   431 a detailed description.
       
   432 
       
   433 Comments are always located in front of the item that is being documented
       
   434 with one exception: for ports the comment can also be after the item
       
   435 and is then treated as a brief description for the port.
       
   436 
       
   437 Here is an example VHDL file with doxygen comments:
       
   438 
       
   439 \include  mux.vhdl
       
   440  \htmlonly
       
   441  Click <a href="$(DOXYGEN_DOCDIR)/examples/mux/html/index.html">here</a>
       
   442  for the corresponding HTML documentation that is generated by doxygen.
       
   443  \endhtmlonly
       
   444 
       
   445 To get proper looking output you need to set
       
   446 \ref cfg_optimize_output_vhdl "OPTIMIZE_OUTPUT_VHDL" to \c YES in the
       
   447 config file. This will also affect a number of other settings. When they
       
   448 were not already set correctly doxygen will produce a warning telling which
       
   449 settings where overruled.
       
   450 
       
   451 */