2006年09月28日

VC中定制Doxygen注释宏

 

感谢曾发明同学

 

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

2006年09月13日
Doxygen注释风格
 
1 类的申明
/**
 *   class declaration
 */
 
2 变量申明
/**< val’s brief. val’s details1. */
 
3 函数申明
       /**
       * a normal member taking two arguments and returning an integer value.
       * @param a an integer argument.
       * @param s a constant character pointer.
       * @see Test()
       * @see ~Test()
       * @see testMeToo()
       * @see publicVar()
       * @return The test results
       */
 
4 config文件中的OUTPUT_LANGUAGE设为Chinese即可支持中文。
5 Doxygen下载:
http://www.stack.nl/~dimitri/doxygen/
2006年09月03日

    从10点多出门,在街上溜达了大半夜,虽然其间奢侈的作了足疗,可到了三点这个坎上,还是累得想找个地方歇歇了。原计划是要在天大找个平坦的地露宿一晚的,后来想想后果的严重性,还是打消了这个念头。工作两年多了,也慢慢的有点点经验了,一个人在外,作践自己的身体也得有个度,过了头没法收场也是不好玩的。

    走了一路,思维几乎是停滞的,想来想去总是想不清楚自己该怎么做。还好,有一双可爱的手,可以让我借以舒缓舒缓这种压力。顺便感谢感谢某人,教我这么好的一招。不过我这双手确实也欠奏啊,该罚!说过很多被“誉为”肉麻的话,在承认自己嘴贫的同时,我也不得不承认我是一个不知天高地厚的幻想狂,一个虚伪的爱情受害者。 爱情,我对你的态度,连我自己都很失望,也许有一天我真的能敞开胸怀,翘首以待,那个王老五的时代的到来…

   不愿意想,更不愿意说,自闭的最高境界是自己都不知道在想些什么!头大,好像找个人痛痛快快的打上一架。不情愿的事接着在作,对于未来……

 

 

    人是生而自由的,确是无往不在枷锁之中。