在VC中定制Doxygen注释宏

感谢曾发明同学

 

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

编辑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

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

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

 

附录:

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

你可能感兴趣的:(注释)