网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 网络学院 >> 程序设计 >> VC编程 >> 文章正文
  在VC中定制Doxygen注释宏            【字体:
在VC中定制Doxygen注释宏
作者:佚名    文章来源:不详    点击数:    更新时间:2007-8-26    

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 '(' divpended 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


 


本文来源:http://blog.csdn.net/nicholasmaxwell/archive/2007/08/14/1742223.aspx
站内文章搜索 高级搜索
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
     directx 图形接口指南(…
     win2k下的api函数的拦截
     用crypto  api  实现公钥…
     根据别人的md5源码封装的…
     vc中使用gdi+合并jpg图片
     document/view的交互 --…
     windows下的函数hook技术
     windows api函数大全一
     用vc 6.0实现串行通信的…
     vc++技术内幕(第四版)…
  • 保留weblogic 中jsp编译后生…

  • 在spring MVC中配置多个视图

  • 基于对称延拓的小波变换算法…

  • OpenCV在VC.net,VC6.0等中的…

  • VC++消息映射

  • 共合网被评为2006-2007最受V…

  • 安装 VC++ 重启

  • VC/MFC.CString操作指南

  • 一些vc的基本知识,创建应用实…

  • VC6调试技巧

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    网络学院©2007 www.23book.net
    为您提供web编程,vb编程,vc编程,服务器架设管理,数据库设计等方面的知识 站长:David