在VC中定制Doxygen注释宏

转自:http://blog.donews.com/glassyang/archive/2006/09/28/1048939.aspx

 

1 参照vc自带的sample.dsm生成文档yymacro.dsm

2 编辑yymacro.dsm内容,添加如下三个宏:

       A)

'生成Doxygen样式的函数注释

YYAddDoxygenFunctionDescription()

对应注释为:

       /**

        * Func1 declaration

        * @param int a input1 a

        * @param int b input2 b

        * @see TestMe()

        * @return int

 */

对应按钮为:

Ctrl+shift+f

 

       B)

'生成doxygen样式的公开变量的注释

YYAddDoxygenValDescription ()

对应注释为:

/**< . . */

对应按钮为:

Ctrl+shift+v

       C)

'生成doxygen样式的一般通用的注释

YYAddDoxygenCommenDescription ()

对应注释为:

/**

       *

 */

对应按钮为:

Ctrl+shift+c

3 保存yymacro.dsm,并添加该宏文件到sample.dsm所在目录中。

4 参照msdn To assign a macro to a toolbar button”,” To assign a macro to a key sequence映射对应宏到按钮和菜单。

 

5 附录:

A yymacro.dsm

'------------------------------------------------------------------------------

'FILE DESCRIPTION: 杨勇定制的宏,内含doxygen注释宏等。

'------------------------------------------------------------------------------

 

'辅助函数

'Strips the leading tab spaces.

Function YYStripTabs (ByVal MyStr)

       Do While InStr(MyStr, vbTab) <> 0

              MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))

       Loop

       YYStripTabs = Trim(MyStr)

End Function

 

'生成Doxygen样式的函数注释

Sub YYAddDoxygenFunctionDescription()

'DESCRIPTION: AddDoxygenFunctionDescription

'DESCRIPTION: Creates a comment block for the currently selected C/C++ function prototype

 

       'Throughout this file, ActiveDocument.Selection is used in place

       'of ActiveDocument.Selection.Text.  The two are equivalent, and can

       'be used interchangeably. The reason for the equivalence is that

       'Text is regarded as the default property to use. All uses of

       'ActiveDocument.Selection without any other property default to the Text

       'property.

       '

       if ActiveDocument.Language = dsCPP Then

              Header = YYStripTabs(Trim(ActiveDocument.Selection))

 

              'Get the function return type.

              'RetTp 返回类型

              if Header <> "" then

                     Reti = InStr(Header, " ")

                     Loc = InStr(Header, "(")

                     if Reti < Loc Then

                       RetTp = Left(Header, Reti)

                       Header = Right(Header, Len(Header) - Reti)

                     End If

 

                     'Get the function name.

                     'fcName 函数名城

                     Loc = InStr(Header, "(") - 1

                     Loc2 = InStr(Header, ")")

                     if Loc > 0 And Loc2 > 0 then 'make sure there is a '(' and a ')'

                            fcName = Left(Header, Loc)

                            Header = Right(Header, Len(Header) - Len(fcName))

 

                            'Do we have storage type on the return type?

                            Trim (fcName)

                            If InStr(fcName," ") <> 0 Then

                                   retTp = retTp + Left(fcName,InStr (fcName," "))

                                   fcName = Right(fcName, Len(fcName) - InStr(fcName," "))

                            End If

 

                            'Get the function parameters.

                            iPrm = 0

                            iPrmA = 0

                            prms = Header

 

                            'Count the number of parameters.

                            Do While InStr(prms, ",") <> 0

                                   iPrm = iPrm + 1

                                   prms = Right(prms, Len(prms) - InStr(prms, ","))

                            Loop

                           

                            'Store the parameter list in the array.

                            If iPrm > 0 Then  ' If multiple params.

                                   iPrm = iPrm + 1

                                   iPrmA = iPrm

                                   Redim ParamArr(iPrm)

                                   Do While InStr(header, ",") <> 0

                                          ParamArr(iPrm) = Left(Header, InStr (Header, ",") - 1)

                                          'Remove brace from first parameter.

                                          If InStr(ParamArr(iPrm), " (") <> 0 Then

                                                 ParamArr(iPrm) = Right(ParamArr(iPrm), _

                                                               Len(ParamArr(iPrm))-InStr(ParamArr(iPrm)," ("))

                                                 Trim(ParamArr(iPrm))

                                          End If

                                          Header = Right(Header, Len(Header) - InStr(Header,","))

                                          iPrm = iPrm - 1

                                          Loop

                                   ParamArr(iPrm) = Header

                                   'Remove trailing brace from last parameter.

                                   If InStr(ParamArr(iPrm), ")") <> 0 Then

                                          ParamArr(iPrm) = Left(ParamArr(iPrm), _

                                                        InStr(ParamArr(iPrm), ")") - 1)

                                          Trim(ParamArr(iPrm))

                                   End If

                            Else 'Possibly one param.

                                   Redim ParamArr(1)

                                   Header = Right(Header, Len(Header) - 1) ' Strip the first brace.

                                   Trim(Header)

                                   ParamArr(1) = YYStripTabs(Header)

                                   If InStr(ParamArr(1), ")") <> 1 Then

                                          ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)

                                          Trim(ParamArr(1))

                                          iPrmA = 1

                                   End If

                            End If

 

                            'Position the cursor one line above the selected text.

                            ActiveDocument.Selection.LineUp

                            ActiveDocument.Selection.LineDown

                            ActiveDocument.Selection.StartOfLine

                            ActiveDocument.Selection = vbLf

 

                            '声称Doxygen样注释文档

                            Descr = vbTab + "/**" + _                                                    

                                          vbLf + vbTab + " * " + fcName + _

                                          vbLf

                           

                            'Print the parameter list.

                            Last = iPrmA

                            Do While iPrmA <> 0

                                   'Remove a line feed from any of the arguments.

                                   If InStr(ParamArr(iPrmA), vbLf) <> 0 Then

                                          ParamArr(iPrmA) = Right(ParamArr(iPrmA), _

                                                        (Len(ParamArr(iPrmA)) - _

                                                        InStr(ParamArr(iPrmA), vbLf)))

                                          Trim(ParamArr(iPrmA))

                                   End If

                                   ParamArr(iPrmA) = YYStripTabs(ParamArr(iPrmA))

                                   'If there are 2+ parameters, the first parameter will

                                   'have a '(' prepended to it, remove it here:

                                   if iPrmA = Last AND Last <> 1 then

                                     ParamArr(iPrmA) = Right(ParamArr(iPrmA), _

                                                 Len(ParamArr(iPrmA)) - 1)

                                   End If

                                   Descr = Descr + _

                                                 vbTab + " * @param " + ParamArr(iPrmA) + _

                                                 vbLf

                                   iPrmA = iPrmA - 1

                            Loop

 

                            Descr = Descr + _

                                          vbTab + " * @return " + RetTp + _

                                          vbLf + vbTab + " */" + _

                                          vbLf

                            ActiveDocument.Selection = Descr

                     Else

                            MsgBox("It is possible that the function you are trying to"+_

                                          " work with has a syntax error.")

                     End if

              End If

       Else

              MsgBox("You need to have an active C/C++ document open"+ _

                            vbLF+"with the function prototype selected.")

       End If

End Sub

 

'生成doxygen样式的公开变量的注释

Sub YYAddDoxygenValDescription ()

       if ActiveDocument.Language = dsCPP Then

              ActiveDocument.Selection = ActiveDocument.Selection + _

                                                               vbTab + "/**< . . */"                          

       End if

End Sub

 

'生成doxygen样式的一般通用的注释

Sub YYAddDoxygenCommenDescription ()

       if ActiveDocument.Language = dsCPP Then

              ActiveDocument.Selection = "/** " + _

                                                               vbLf + " * " + _

                                                               vbLf + " */"

       End if

End Sub

 

'

 

B)测试文件

#ifndef __A__H

#define __A__H

 

#include <iostream>

 

/**

 *   class A's declaration

 */

class A

{

public:

       enum TEnum

       {

              TVal1,           /**< enum value TVal1. */ 

              TVal2,           /**< enum value TVal2. */ 

              TVal3            /**< enum value TVal3. */ 

       };

 

       TEnum *enumPtr; /**< enum pointer. Details. */

       TEnum enumVar;  /**< enum variable. Details. */

 

       /**

        * Func1 declaration

        * @param int a input1 a

        * @param int b input2 b

        * @see TestMe()

        * @return int

        */

 

       int Func1(int a, int b);

 

 

       /**

        * TestMe

        * @param int a

        * @param const char *s

        * @return int

        */

       int TestMe(int a,const char *s);

 

 

       /**

        * TestAutoComment

        * @param int a param1 description

        * @param int b param2 description

        * @param char c param3 description

        * @return int ret description

        */

       int TestAutoComment(int a, int b, char c);

 

       int iA;     /**< iA1. iA's Details1. */

                     /**< iA2. iA's Details2. */

      

       /**

       * a public variable iB.

       * Details1.

       * Details2.

       */

       int iB;     /**< . . */

 

       int iC; /**< iC1 中文注释测试. iC's Details1. */

                     /**< iC2. iC's Details2. */

};

 

#endif//__A__H


Trackback: http://tb.donews.net/TrackBack.aspx?PostId=1048939

Doxygen 文使用文档 及 适合Doxygen注释 使注释更简单 统一 注释 已经过修改 使用简单方便 Doxygen 是一个程序的文件产生工具,可将程序的特定批注转换成为说明文件。通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打捞铁达尼号同样的辛苦。大部分有用的批注都是属于针对函式,类别等等的说明。所以,如果能依据程序本身的结构,将批注经过处理重新整理成为一个纯粹的参考手册,对于后面利用您的程序代码的人而言将会减少许多的负担。不过,反过来说,整理文件的工作对于您来说,就是沉重的负担。   对于未归档的源文件,也可以通过配置Doxygen来提取代码结构。或者借助自动生成的包含依赖图(includedependency graphs)、继承图(inheritance diagram)以及协作图(collaborationdiagram)来可视化文档之间的关系。Doxygen生成的帮助文档的格式可以是CHM、RTF、PostScript、PDF、HTML和Unixman page等。   一个好的程序设计师,在写程序时,都会在适当的地方加上合适的批注。如果,能够在撰写批注时,稍微符合某种格式,接着就可以透过一个工具程序依据程序结构及您的批注产生出漂亮的文件。这将令许多工作繁重的程序设计师有时间多喝几杯咖啡。   Doxygen 就是这样的一个工具。在您写批注时,稍微按照一些它所制订的规则。接着,他就可以帮您产生出漂亮的文件了。因此,Doxygen 的使用可分为两大部分。首先是特定格式的批注撰写,第二便是利用Doxygen的工具来产生文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值