|
在members之后添加注释
如果需要为file,struct,union,class或enmu的members添加注释,并且你需要将这些注释放在compound之内,可以考虑将注释块放在member的后面。这样就要在注释块中添加一个“<”标记。
下面是个例子:
int var; /*!< Detailed description after the member */
这个块在用来在在一个member之后添加一个注释块(Qt风格)
还有一种方式
int var; /**< Detailed description after the member */
或者是
int var; //!< Detailed description after the member
//!<
或者是
int var; ///< Detailed description after the member
///<
多数情况下只是需要在一个member后添加一个brief描述,如下:
int var; //!< Brief description after the member
或者
int var; ///< Brief description after the member
注意这些块有相同的结构,不过是使用了<来表明在前或在后。
这里有个使用注释块的例子:
/*! A test class */
class 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 */
};
Click here for the corresponding HTML documentation that is generated by doxygen.
警告:
这些块只能用来给members和parameters注释。不能用来给files,classes,unions,structs,groups,namespaces和enums添加注释。还有下一节中论述的structural commands在这种注释块中被忽略掉了
Documentation at other places
截止目前,我们谈到的注释块都是在file,class或namespace的declaration或definition之前还有是在member的前后。尽管这通常已经达到目的,但有时要将注释放在其他地方。为一个文件添加注释也是有必要的,但是没有“在文件之前”这种地方。Doxygen允许将注释块放在其他的任何地方(也有不允许的:例如函数体内或一个标准的C-style注释块中)。
这样作比较麻烦的是需要在注释块中添加一些structural命令。
Structual commands(像其他的commands)以“\”开头,或是一个“@”(使用JavaDoc风格),后面是命令名和一或多个参数。例如,如果你想给上面的Test类添加一个注释:
/*! \class Test
\brief A test class.
A more detailed class description.
*/
这里特殊命令“\class”用于指出该注释块中含有对Test类的注释。还有一些其他的structural命令:
·\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.
·\file to document a file.
·\namespace to document a namespace.
·\package to document a Java package.
·\interface to document an IDL interface.
参看Special Commands获得更详细资料。
为了注释一个类中的member,首先要对该类作注释。同样的问题上升到namespace。要注释一个全局的function,typedef,enum或preprocessor定义,你需要首先定义包含它的文件(通常情况下是一个.h文件,因为这些文件包含可以export到其他源文件的信息)。
让我们重复一下,因为常常被忽视:要注释一个global objects(functions,typedefs, enum,macros等),必须注释它们所在的.h文件。换句话,至少要这样注释一下
/*! \file */
或这样一个
/** @file */
行在该文件中
这里用个名为structcmd.h的C头文件,讲解如何使用structal commands。
/*! \file structcmd.h
\brief A Documented file.
Details.
*/
/*! \def MAX(a,b)
\brief A macro that returns the maximum of \a a and \a b.
Details.
*/
/*! \var typedef unsigned int UINT32
\brief A type definition for a .
Details.
*/
/*! \var int errno
\brief Contains the last erro [1] [2] 下一页 |