Комментарии в Doxygen'е
От: Watch Россия  
Дата: 02.06.09 14:23
Оценка:
Доброго всем времени суток!
Пишу на С++... юзаю Doxygen под VS2008, но немного обламывает набирать теги в h-никах, особенно когда комментирую функции. Может быть знает кто инструмент, который автоматизирует создание тегов-комментариев.
Заранее благодарю.
Что нас не убивает — делает нас сильнее!
doxygen документация комменты
Re: Комментарии в Doxygen'е
От: Vlad_SP  
Дата: 02.06.09 18:37
Оценка: 4 (1)
Здравствуйте, Watch,

в Visual Studio есть страшно мощная штука — макросы. Я для аналогичной цели просто выделяю заголовок функции и жму волшебную кнопочку, — и вуаля! Шаблон описания готов, нужно только дописать нужное. Аналогичные макросы есть для описания файла, класса.... короче, все зависит только от твоей фантазии. С подобным инстументарием писание документации прямо в исходниках превращается в удовольствие
Тем более, что заготовки макросов уже есть в среде, нужно только допилить напильником "под себя".
    Sub AddFunctionDescription()
        AddFunctionDescriptionImp(False)
    End Sub


    Sub AddFunctionDoxyDescription()
        AddFunctionDescriptionImp(True)
    End Sub


    Sub AddFunctionDescriptionImp(ByVal ForDoxygen As Boolean)
        'Description: Creates a comment block for the currently selected C/C++ function prototype
        'Param: ForDoxygen - если True, то вставляет комментарии в стиле(doxygen)

        Dim Header, prms As String
        Dim fcName, Descr As String
        Dim iPrm, iPrmA, iFirst As Integer
        Dim selection As TextSelection
        Dim RetTp As String

        '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() Is Nothing) Then
            Exit Sub
        End If
        If ActiveDocument().Language = EnvDTE.Constants.dsCPP Or ActiveDocument().Language = "CSharp" Then

            selection = DTE.ActiveDocument.Selection()
            Trim(selection.Text)
            Header = ""

            If selection.Text <> "" Then
                Header = StripTabs(Trim(selection.Text))
            End If

            'Get the function return type.
            If Header <> "" Then
                If ActiveDocument().Language = "CSharp" Then
                    'skip the protection info (public/private ...)
                    Header = Right(Header, Len(Header) - InStr(Header, " "))
                End If
                Reti = InStr(Header, " ")
                Loc1 = InStr(Header, "(")
                If Reti < Loc1 Then
                    RetTp = Left(Header, Loc1 - 1)
                    Header = Right(Header, Len(Header) - Reti)
                End If
                RetTp = Left(RetTp, InStr(RetTp, " "))

                'Get the function name.
                Loc1 = InStr(Header, "(") - 1
                Loc2 = InStr(Header, ")")

                If Loc1 > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
                    fcName = Left(Header, Loc1)
                    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 - 1) = Left(Header, InStr(Header, ",") - 1)
                            'Remove brace from first parameter.
                            If InStr(ParamArr(iPrm - 1), " (") <> 0 Then
                                ParamArr(iPrm - 1) = Right(ParamArr(iPrm - 1), (Len(ParamArr(iPrm - 1)) - (Len(ParamArr(iPrm - 1)) - (Len(ParamArr(iPrm - 1)) - InStr(ParamArr(iPrm - 1), " (")))))
                                Trim(ParamArr(iPrm))
                            End If
                            Header = Right(Header, Len(Header) - InStr(Header, ","))
                            iPrm = iPrm - 1
                        Loop
                        ParamArr(iPrm - 1) = Header

                        'Remove trailing brace from last parameter.
                        If InStr(ParamArr(iPrm - 1), ")") <> 0 Then
                            ParamArr(iPrm - 1) = Left(ParamArr(iPrm - 1), InStr(ParamArr(iPrm - 1), ")") - 1)
                            Trim(ParamArr(iPrm - 1))
                        End If
                    Else 'Possibly one param.

                        ReDim ParamArr(1)
                        Header = Right(Header, Len(Header) - 1) ' Strip the first brace.
                        Trim(Header)
                        ParamArr(0) = StripTabs(Header)
                        If InStr(ParamArr(0), ")") <> 1 Then
                            ParamArr(0) = Left(ParamArr(0), InStr(ParamArr(0), ")") - 1)
                            Trim(ParamArr(0))
                            iPrmA = 1
                        End If
                    End If

                    'Position the cursor one line above the selected text.
                    DTE.ActiveDocument.Selection.LineUp()
                    DTE.ActiveDocument.Selection.LineDown()
                    DTE.ActiveDocument.Selection.StartOfLine()
                    selection = DTE.ActiveDocument.Selection()
                    'selection.text = Lf

                    If ForDoxygen Then
                        Descr = "//  Функция   : " + fcName + CStr(Lf) + _
                                "/// Назначение: " + CStr(Lf) + _
                                "/// \return     " + RetTp + CStr(Lf)
                    Else
                        Descr = "// Функция   : " + fcName + CStr(Lf) + _
                                "// Назначение: " + CStr(Lf) + _
                                "// Возвращает: " + RetTp + CStr(Lf)
                    End If

                    'Print the parameter list.
                    If iPrmA <> 0 Then
                        If ForDoxygen Then
                            Descr = Descr + "/// \param      "
                        Else
                            Descr = Descr + "// Аргументы : "
                        End If

                    End If

                    Last = iPrmA
                    iFirst = 0

                    Dim ParamList As String
                    '======================
                    Do While iPrmA > 0
                        'Remove a line feed from any of the arguments.
                        If InStr(ParamArr(iPrmA - 1), vbLf) <> 0 Then
                            ParamArr(iPrmA - 1) = Right(ParamArr(iPrmA - 1), _
                                 (Len(ParamArr(iPrmA - 1)) - _
                                 InStr(ParamArr(iPrmA - 1), vbLf)))
                            Trim(ParamArr(iPrmA - 1))
                        End If
                        ParamArr(iPrmA - 1) = StripTabs(ParamArr(iPrmA - 1))
                        '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 - 1) = Right(ParamArr(iPrmA - 1), _
                             Len(ParamArr(iPrmA - 1)) - 1)
                        End If

                        If iFirst = 0 Then
                            Descr = Descr + ParamArr(iPrmA - 1) + vbLf
                            iFirst = 1
                        Else
                            If ForDoxygen Then
                                Descr = Descr + "/// \param      " + ParamArr(iPrmA - 1) + " " + vbLf
                            Else
                                Descr = Descr + "//             " + ParamArr(iPrmA - 1) + " " + vbLf
                            End If
                        End If
                        iPrmA = iPrmA - 1
                    Loop
                    '======================

                    If ForDoxygen Then
                        Descr = Descr + "/// \remarks    " + CStr(Lf)
                    Else
                        Descr = Descr + "// Примечания: " + CStr(Lf)
                    End If

                    selection = DTE.ActiveDocument.Selection()
                    selection.Text = Descr
                Else
                    MsgBox("Невозможно создать описание." + CStr(Lf) + _
                           "Вероятно, синтаксические ошибки в функции.")
                End If
            End If

        Else

            MsgBox("You need to have an active C/C++ document open" + CStr(Lf) + "with the function prototype selected.")
        End If
    End Sub
Re: Комментарии в Doxygen'е
От: byleas  
Дата: 02.06.09 19:47
Оценка: 4 (1)
Здравствуйте, Watch

Как вариант, Visual Assist, "Document method"; шаблон по умолчанию не для доксигена, но можно отредактировать в нужную сторону.
Re[2]: Комментарии в Doxygen'е
От: kvser  
Дата: 03.06.09 03:58
Оценка:
Здравствуйте, byleas, Вы писали:

B>Здравствуйте, Watch


B>Как вариант, Visual Assist, "Document method"; шаблон по умолчанию не для доксигена, но можно отредактировать в нужную сторону.


А если не только применительно к VS?
Re[3]: Комментарии в Doxygen'е
От: byleas  
Дата: 03.06.09 07:42
Оценка:
Здравствуйте, kvser

K>А если не только применительно к VS?

Без понятия.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.