doxygen文档注释编写指南
内容目录

通过doxygen生成文档

生成配置文件

通过doxygen -g <config_filename>生成Doxyfile的配置文件。

通过配置文件生成文档

使用以下命令生成文档,前提是已经生成了配置文件并且配置了相关项。

doxygen Doxyfile

doxygen注释要求

Comment blocks for C-like languages类C语言的块注释

  1. Javadoc 样式
    /**
    * ... text ...
    */
  2. Qt style
    /*!
    * ... text ...
    */
  3. 第三种选择是使用至少包含两个 C++ 注释行的块
    ///
    /// ... text ...
    ///

    or

    //!
    //!... text ...
    //!
  4. 有些人喜欢让他们的评论块在文档中更显眼。为此,您可以使用以下内容:
    /*******************************************//**
    *  ... text
    ***********************************************/

    or

    /////////////////////////////////////////////////
    /// ... text ...
    /////////////////////////////////////////////////

    or

    /***********************************************
    *  ... text
    ***********************************************/

    需要将JAVADOC_BANNER设置为YES。
    以下是一个示例:

/**
 * A brief history of JavaDoc-style (C-style) comments.
 *
 * This is the typical JavaDoc-style C-style comment. It starts with two
 * asterisks.
 *
 * @param theory Even if there is only one possible unified theory. it is just a
 *               set of rules and equations.
 */
void cstyle( int theory );
/******************************************************************************
 * A brief history of JavaDoc-style (C-style) banner comments.
 *
 * This is the typical JavaDoc-style C-style "banner" comment. It starts with
 * a forward slash followed by some number, n, of asterisks, where n > 2. It's
 * written this way to be more "visible" to developers who are reading the
 * source code.
 *
 * Often, developers are unaware that this is not (by default) a valid Doxygen
 * comment block!
 *
 * However, as long as JAVADOC_BANNER = YES is added to the Doxyfile, it will
 * work as expected.
 *
 * This style of commenting behaves well with clang-format.
 *
 * @param theory Even if there is only one possible unified theory. it is just a
 *               set of rules and equations.
 ******************************************************************************/
void javadocBanner( int theory );

/**************************************************************************//**
 * A brief history of Doxygen-style banner comments.
 *
 * This is a Doxygen-style C-style "banner" comment. It starts with a "normal"
 * comment and is then converted to a "special" comment block near the end of
 * the first line. It is written this way to be more "visible" to developers
 * who are reading the source code.
 * This style of commenting behaves poorly with clang-format.
 *
 * @param theory Even if there is only one possible unified theory. it is just a
 *               set of rules and equations.
 ******************************************************************************/
void doxygenBanner( int theory );

对于简述,有以下几种可能:

  1. 使用\brief命令。该描述结束于一个段落,中间隔了一个空行,紧跟着就是细节描述。
    
    /*! \brief Brief description.
    *         Brief description continued.
    *
    *  Detailed description starts here.
    */
2. 如果JAVADOC_AUTOBRIEF被设置为YES,可以这样使用:
```cpp
/** 简述结束于一点. 以下是
 *  细节.
 */

在成员后书写文档

这是以下几个例子:

int var; /*!< Detailed description after the member */

int var; /**< Detailed description after the member */

int var; //!< Brief description after the member

int var; ///< Brief description after the member

// 这里的[in],表示输入,且不会修改。也可以为[out]以及[in,out]
void foo(int v /**< [in] docs for input parameter v. */);

以下是一个示例:

/*! A test class */

class Afterdoc_Test
{
  public:
    /** An enum type. 
     *  The documentation block cannot be put after the enum! 
     */
    enum EnumType
    {
      int EVal1,     /**< enum value 1 */
      int EVal2      /**< enum value 2 */
    };
    void member();   //!< a member function.

  protected:
    int value;       /*!< an integer value */
};

以下是javadoc风格的示例:

/**
 *  A test class. A more elaborate class description.
 */

class Javadoc_Test
{
  public:

    /** 
     * An enum.
     * More detailed enum description.
     */

    enum TEnum { 
          TVal1, /**< enum value TVal1. */  
          TVal2, /**< enum value TVal2. */  
          TVal3  /**< enum value TVal3. */  
         } 
       *enumPtr, /**< enum pointer. Details. */
       enumVar;  /**< enum variable. Details. */

      /**
       * A constructor.
       * A more elaborate description of the constructor.
       */
      Javadoc_Test();

      /**
       * A destructor.
       * A more elaborate description of the destructor.
       */
     ~Javadoc_Test();

      /**
       * a normal member taking two arguments and returning an integer value.
       * @param a an integer argument.
       * @param s a constant character pointer.
       * @see Javadoc_Test()
       * @see ~Javadoc_Test()
       * @see testMeToo()
       * @see publicVar()
       * @return The test results
       */
       int testMe(int a,const char *s);

      /**
       * A pure virtual member.
       * @see testMe()
       * @param c1 the first argument.
       * @param c2 the second argument.
       */
       virtual void testMeToo(char c1,char c2) = 0;

      /** 
       * a public variable.
       * Details.
       */
       int publicVar;

      /**
       * a function variable.
       * Details.
       */
       int (*handler)(int a,int b);
};

常用的命令

\class  to document a C++-class.
\struct to document a C-struct.
\union to document a union.
\enum to document an enumeration type.
\fn to document a function.
\var to document a variable or typedef or enum value.
\def to document a #define.
\typedef to document a type definition.
\file to document a file.
\namespace to document a namespace.
\package to document a Java package.
\interface to document an IDL interface.
上一篇