Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports Microsoft.VisualBasic.ControlChars
Imports System.Diagnostics
Public Module Utility
Sub CollapseNode(ByRef item As UIHierarchyItem)
' CollapseAll ¿¡¼ »ç¿ëÇϱâ À§ÇÑ ÇÔ¼ö
Dim objSubItem As UIHierarchyItem
For Each objSubItem In item.UIHierarchyItems
CollapseNode(objSubItem)
objSubItem.UIHierarchyItems.Expanded = False
'If (objSubItem.UIHierarchyItems.Expanded = True) Then
' CollapseNode(objSubItem)
' objSubItem.UIHierarchyItems.Expanded = False
'End If
Next
End Sub
Sub CollapseAll()
' ¼Ö·ç¼Ç ÀͽºÇ÷η¯¿¡ ÆîÃÄÁø ³ëµåµéÀ» ¸ðµÎ Á¢´Â´Ù.
Dim objSolutionExplorer As UIHierarchy
objSolutionExplorer = DTE.Windows.Item(EnvDTE.Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (objSolutionExplorer.UIHierarchyItems.Count = 0) Then
' MsgBox("Nothing to collapse. You must have an open solution.")
Return
End If
' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
UIHSolutionRootNode = objSolutionExplorer.UIHierarchyItems.Item(1)
CollapseNode(UIHSolutionRootNode)
' Select the solution node, or else when you click on the solution window
' scrollbar, it will synchronize the open document with the tree and pop
' out the corresponding node which is probably not what you want.
UIHSolutionRootNode.Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub
Sub FindInSolution()
' ÇöÀç ÆíÁý ÁßÀÎ ÆÄÀÏÀ» ¼Ö·ç¼Ç ÀͽºÇ÷η¯¿¡¼ ã¾Æ¼ ÇÏÀ̶óÀÌÆ®½ÃŲ´Ù.
p = DTE.Properties("Environment", "ProjectsAndSolution").Item("TrackFileSelectionInExplorer")
p.value = 1
p.value = 0
End Sub
Sub GetFriendFile()
' H <--> CPP ÆÄÀÏ Àüȯ
strCurrentFileName = Application.ActiveDocument.FullName
strNewFileName = ""
If (UCase(Right(strCurrentFileName, 2)) = ".H") Then
strNewFileName = Left(strCurrentFileName, Len(strCurrentFileName) - 2) + ".CPP"
ElseIf (UCase(Right(strCurrentFileName, 4)) = ".CPP") Then
strNewFileName = Left(strCurrentFileName, Len(strCurrentFileName) - 4) + ".H"
End If
On Error Resume Next
If strNewFileName <> "" Then
Application.Documents.Open(strNewFileName)
If (Err.Number <> 0) Then
MsgBox("Error opening corresponding file - " & Err.Description)
End If
End If
End Sub
Function Strip(ByVal strLine As String)
' ¹®ÀÚ¿ Á¿ìÀÇ °ø¹éÀ» Á¦°ÅÇÑ´Ù.
If Len(strLine) > 0 Then
nBegin = 1
nEnd = Len(strLine)
For i = 1 To Len(strLine)
c = Mid(strLine, i, 1)
If c <> " " And c <> Tab And c <> Lf And c <> Cr Then
nBegin = i
Exit For
End If
Next
For i = 1 To Len(strLine)
c = Mid(strLine, Len(strLine) - i + 1, 1)
If c <> " " And c <> Tab And c <> Lf And c <> Cr Then
nEnd = Len(strLine) - i + 1
Exit For
End If
Next
Return Mid(strLine, nBegin, nEnd - nBegin + 1)
Else
Return ""
End If
End Function
Sub Split(ByVal strLine As String, ByVal strSeperators As String, ByRef objLines As System.Collections.Generic.List(Of String))
' ¹®ÀÚ¿À» ÅäÅ«ÀÇ ¸ñ·ÏÀ¸·Î ºÐ¸®ÇÑ´Ù. ±¸ºÐÀÚ´Â ¿©·¯ °³°¡ µÉ ¼ö ÀÖ´Ù.
strToken = ""
For i = 1 To Len(strLine)
strChar = Mid(strLine, i, 1)
If InStr(strSeperators, strChar) > 0 Then
If Len(strToken) > 0 Then
objLines.Add(strToken)
End If
strToken = ""
Else
strToken = strToken + strChar
End If
Next
If Len(strToken) > 0 Then
objLines.Add(strToken)
End If
End Sub
Sub PadLeft(ByRef objLines As System.Collections.Generic.List(Of String), ByVal strPad As String)
' ¹®ÀÚ¿ Áß¿¡ Á¦ÀÏ ±ä ³ðÀ» ±âÁØÀ¸·Î ªÀº ³ðµéÀÇ ¿ÞÂÊ¿¡´Ù ÁÖ¾îÁø ÆÐµù ¹®ÀÚ¿À» ºÙÀδÙ.
nMaxLength = 0
For Each s In objLines
If Len(s) > nMaxLength Then
nMaxLength = Len(s)
End If
Next
For i = 0 To objLines.Count - 1
strLine = objLines.Item(i)
nMargin = nMaxLength - Len(strLine)
For m = 1 To nMargin
strLine = strPad + strLine
Next
objLines.Item(i) = strLine
Next
End Sub
Sub PadRight(ByRef objLines As System.Collections.Generic.List(Of String), ByVal strPad As String)
' ¹®ÀÚ¿ Áß¿¡ Á¦ÀÏ ±ä ³ðÀ» ±âÁØÀ¸·Î ªÀº ³ðµéÀÇ ¿À¸¥ÂÊ¿¡´Ù ÁÖ¾îÁø ÆÐµù ¹®ÀÚ¿À» ºÙÀδÙ.
nMaxLength = 0
For Each s In objLines
If Len(s) > nMaxLength Then
nMaxLength = Len(s)
End If
Next
For i = 0 To objLines.Count - 1
strLine = objLines.Item(i)
nMargin = nMaxLength - Len(strLine)
For m = 1 To nMargin
strLine = strLine + strPad
Next
objLines.Item(i) = strLine
Next
End Sub
Function GetSelectedText()
' ÇöÀç ¼±ÅÃµÈ ¹®ÀÚ¿À» ¹ÝȯÇÑ´Ù.
Dim objSel As TextSelection
If (DTE.ActiveDocument Is Nothing) Then Return ""
objSel = DTE.ActiveDocument.Selection()
Return objSel.Text
End Function
Sub InsertText(ByVal strText As String)
' ÇöÀç ij·µÀÌ ÀÖ´Â °÷¿¡´Ù ÁÖ¾îÁø ¹®ÀÚ¿À» »ðÀÔÇÑ´Ù.
Dim objSel As TextSelection
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
objSel = ActiveDocument().Selection
objRanges = objSel.TextRanges
objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
objStartPt.Insert(strText)
End Sub
Sub ReplaceSelectedText(ByVal strText As String)
' ÇöÀç ¼±ÅÃµÈ ¹®ÀÚ¿À» ÁÖ¾îÁø ¹®ÀÚ¿·Î ġȯÇÑ´Ù.
Dim objSel As TextSelection
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
objSel = ActiveDocument().Selection
objRanges = objSel.TextRanges
objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
objSel.Text = ""
objStartPt.Insert(strText)
End Sub
Sub DecorateSourceFile()
' H, CPP ÆÄÀÏ¿¡´Ù ±âº» ÁÖ¼®À» Áý¾î³Ö´Â´Ù.
Dim objStream As New System.Text.StringBuilder()
Dim strFileName As String
Dim strFileExt As String
Dim strClassName As String
Dim strIncludeGuard As String
Dim strSelected As String
Dim nPos As Integer
' ¼öÁ¤ »çÇ×µé. Çʿ信 µû¶ó ¼öÁ¤ÇÑ´Ù.
Dim strAuthor As String = "excel96"
Dim strDateString As String = CStr(Year(Now())) + "." + CStr(Month(Now())) + "." + CStr(Day(Now()))
Dim strCommentLine As String = "////////////////////////////////////////////////////////////////////////////////////////////////////"
Dim bUsePragmaOnce As Boolean = True
Dim strClassNamePrefix As String = "c"
Dim strPchName As String = "PCH.h"
Dim currentItem As ProjectItem = ActiveDocument().ProjectItem
If currentItem Is Nothing Then
Else
Dim result As Project = currentItem.ContainingProject
strPchName = result.Name + "PCH.h"
End If
' ÆÄÀÏ À̸§À» È®ÀÎÇÑ´Ù.
strFileName = ActiveDocument().Name
If strFileName = "" Then
If MsgBox("ó¸® ÁßÀÎ ÆÄÀÏ¿¡ È®ÀåÀÚ°¡ ¾ø½À´Ï´Ù." + CrLf + _
"C/C++ ¼Ò½º ÆÄÀÏÀÌ ¸Â½À´Ï±î?", 4) = MsgBoxResult.Cancel Then
Exit Sub
End If
strFileName = "NoFileNameGiven.h"
End If
' ÆÄÀÏ À̸§À» ºÐ¸®Çϰí, Ŭ·¡½º À̸§À» »ý¼ºÇÑ´Ù.
strFileExt = UCase(Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".")))
strFileName = Left(strFileName, Len(strFileName) - Len(strFileExt) - 1)
strClassName = strClassNamePrefix + strFileName
ActiveDocument().Selection.StartOfDocument(False)
' ÆÄÀÏÀÇ È®ÀåÀÚ¿¡ µû¶ó ¾Ë¸ÂÀº 󸮸¦ ÇØÁØ´Ù.
If strFileExt = "H" Or strFileExt = "HPP" Then
strIncludeGuard = "__" + UCase(strFileName) + "_" + strFileExt + "__" + CrLf
' ÆÄÀÏ Çì´õ Ãß°¡.
objStream.Append(strCommentLine + CrLf)
objStream.Append("/// \file " + ActiveDocument().Name + CrLf)
objStream.Append("/// \author " + strAuthor + CrLf)
objStream.Append("/// \date " + strDateString + CrLf)
objStream.Append(strCommentLine + CrLf + CrLf)
' ÀÎŬ·çµå °¡µå Ãß°¡.
If bUsePragmaOnce Then
objStream.Append("#pragma once" + CrLf + CrLf)
Else
objStream.Append("#ifndef " + strIncludeGuard + "#define " + strIncludeGuard + CrLf + CrLf)
End If
' Ŭ·¡½º ¼³¸í¹® Ãß°¡.
objStream.Append(strCommentLine + CrLf)
objStream.Append("/// \class " + strClassName + CrLf)
objStream.Append("/// \brief " + CrLf)
objStream.Append(strCommentLine + CrLf + CrLf)
' Ŭ·¡¼ ¼±¾ð ¹× »ý¼ºÀÚ & ¼Ò¸êÀÚ Ãß°¡.
objStream.Append("class " + strClassName + CrLf)
objStream.Append("{" + CrLf)
objStream.Append("private:" + CrLf + CrLf)
objStream.Append("public:" + CrLf)
objStream.Append(Tab + "/// \brief »ý¼ºÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "();" + CrLf + CrLf)
objStream.Append(Tab + "/// \brief ¼Ò¸êÀÚ" + CrLf)
objStream.Append(Tab + "virtual ~" + strClassName + "();" + CrLf + CrLf + CrLf)
objStream.Append("public:" + CrLf + CrLf)
objStream.Append("private:" + CrLf)
objStream.Append(Tab + "/// \brief º¹»ç »ý¼º ±ÝÁö" + CrLf)
objStream.Append(Tab + strClassName + "(const " + strClassName + "&) {}" + CrLf + CrLf)
objStream.Append(Tab + "/// \brief ´ëÀÔ ±ÝÁö" + CrLf)
objStream.Append(Tab + strClassName + "& operator = (const " + strClassName + "&) { return *this; }" + CrLf)
objStream.Append("};" + CrLf)
' ÀÎŬ·çµå °¡µå ¸¶¹«¸®.
If Not bUsePragmaOnce Then
objStream.Append(Lf + "#endif //" + strIncludeGuard)
End If
ElseIf strFileExt = "C" Or strFileExt = "CPP" Or strFileExt = "CC" Then
' ÆÄÀÏ Çì´õ Ãß°¡.
objStream.Append(strCommentLine + CrLf)
objStream.Append("/// \file " + ActiveDocument().Name + CrLf)
objStream.Append("/// \author " + strAuthor + CrLf)
objStream.Append("/// \date " + strDateString + CrLf)
objStream.Append(strCommentLine + CrLf + CrLf)
' ÀÎŬ·çµå ÆÄÀÏ Ãß°¡.
objStream.Append("#include " + CStr(Quote) + strPchName + CStr(Quote) + CrLf)
objStream.Append("#include " + CStr(Quote) + strFileName + ".h" + CStr(Quote) + CrLf)
objStream.Append(Lf)
' »ý¼ºÀÚ Ãß°¡.
objStream.Append(strCommentLine + CrLf)
objStream.Append("/// \brief »ý¼ºÀÚ" + CrLf)
objStream.Append(strCommentLine + CrLf)
objStream.Append(strClassName + "::" + strClassName + "()" + CrLf)
objStream.Append("{" + CrLf)
objStream.Append("}" + CrLf + CrLf)
' ¼Ò¸êÀÚ Ãß°¡.
objStream.Append(strCommentLine + CrLf)
objStream.Append("/// \brief ¼Ò¸êÀÚ" + CrLf)
objStream.Append(strCommentLine + CrLf)
objStream.Append(strClassName + "::~" + strClassName + "()" + CrLf)
objStream.Append("{" + CrLf)
objStream.Append("}" + CrLf + CrLf)
End If
InsertText(objStream.ToString())
End Sub
Sub AddFunctionDescriptionEx()
' ÇÔ¼ö ¼³¸íÀ» Ãß°¡ÇÑ´Ù.
Dim objSel As TextSelection
Dim strHeader As String
Dim strParams As String
Dim strFunctionName As String
Dim strDescription As String
Dim strReturnType As String
Dim strCommentLine As String
Dim iPrm, iPrmA As Integer
Dim p, l As Integer
If (ActiveDocument() Is Nothing) Then
Exit Sub
End If
strCommentLine = "////////////////////////////////////////////////////////////////////////////////////////////////////"
If ActiveDocument().Language = EnvDTE.Constants.dsCPP Or ActiveDocument().Language = "CSharp" Then
objSel = DTE.ActiveDocument.Selection()
Strip(objSel.Text)
strHeader = ""
If objSel.Text <> "" Then
strHeader = Strip(objSel.Text)
End If
'Get the function return type.
If strHeader <> "" Then
If ActiveDocument().Language = "CSharp" Then
'skip the protection info (public/private ...)
strHeader = Right(strHeader, Len(strHeader) - InStr(strHeader, " "))
End If
Reti = InStr(strHeader, " ")
Loc1 = InStr(strHeader, "(")
If Reti < Loc1 Then
strReturnType = Left(strHeader, Loc1 - 1)
strHeader = Right(strHeader, Len(strHeader) - Reti)
End If
strReturnType = Left(strReturnType, InStr(strReturnType, " "))
'Get the function name.
Loc1 = InStr(strHeader, "(") - 1
Loc2 = InStr(strHeader, ")")
If Loc1 > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
strFunctionName = Left(strHeader, Loc1)
strHeader = Right(strHeader, Len(strHeader) - Len(strFunctionName))
'Do we have storage type on the return type?
Strip(strFunctionName)
If InStr(strFunctionName, " ") <> 0 Then
strReturnType = strReturnType + Left(strFunctionName, InStr(strFunctionName, " "))
strFunctionName = Right(strFunctionName, Len(strFunctionName) - InStr(strFunctionName, " "))
End If
'Get the function parameters.
iPrm = 0
iPrmA = 0
strParams = strHeader
'Count the number of parameters.
Do While InStr(strParams, ",") <> 0
iPrm = iPrm + 1
strParams = Right(strParams, Len(strParams) - InStr(strParams, ","))
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(strHeader, ",") <> 0
ParamArr(iPrm - 1) = Left(strHeader, InStr(strHeader, ",") - 1)
'Remove brace from first parameter.
If InStr(ParamArr(iPrm - 1), " (") <> 0 Then
p = iPrm - 1
l = Len(ParamArr(p))
ParamArr(p) = Right(ParamArr(p), (l - (l - (l - InStr(ParamArr(p), " (")))))
Strip(ParamArr(iPrm))
End If
strHeader = Right(strHeader, Len(strHeader) - InStr(strHeader, ","))
iPrm = iPrm - 1
Loop
ParamArr(iPrm - 1) = strHeader
'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)
Strip(ParamArr(iPrm - 1))
End If
Else 'Possibly one param.
ReDim ParamArr(1)
strHeader = Right(strHeader, Len(strHeader) - 1) ' Strip the first brace.
Strip(strHeader)
ParamArr(0) = Strip(strHeader)
If InStr(ParamArr(0), ")") <> 1 Then
ParamArr(0) = Left(ParamArr(0), InStr(ParamArr(0), ")") - 1)
Strip(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()
objSel = DTE.ActiveDocument.Selection()
'selection.text = Lf
strDescription = strCommentLine + CStr(Lf)
strDescription += "/// \brief " + CStr(Lf)
If (iPrmA <> 0) Then
strDescription += "/// " + CStr(Lf)
End If
'Print the parameter list.
Last = iPrmA
Do While iPrmA <> 0
'Remove a line feed from any of the arguments.
If InStr(ParamArr(iPrmA - 1), CStr(Lf)) <> 0 Then
p = iPrmA - 1
l = Len(ParamArr(p))
ParamArr(p) = Right(ParamArr(p), (l - (l - (l - InStr(ParamArr(p), CStr(Lf))))))
Strip(ParamArr(iPrmA - 1))
End If
ParamArr(iPrmA - 1) = Strip(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
SpaceIndex = InStrRev(ParamArr(iPrmA - 1), " ")
StarIndex = InStrRev(ParamArr(iPrmA - 1), "*")
AmpIndex = InStrRev(ParamArr(iPrmA - 1), "&")
RealIndex = System.Math.Max(SpaceIndex, StarIndex)
RealIndex = System.Math.Max(RealIndex, AmpIndex)
RealParam = Strip(Right(ParamArr(iPrmA - 1), Len(ParamArr(iPrmA - 1)) - RealIndex))
If (Len(RealParam) > 0 And InStr(RealParam, "void") = 0) Then
strDescription = strDescription + "/// \param " + RealParam + " " + CStr(Lf)
End If
iPrmA = iPrmA - 1
Loop
strReturnType = Strip(strReturnType)
If (Len(strReturnType) > 0 And InStr(strReturnType, "void") = 0) Then
strDescription += "/// \return " + strReturnType + CStr(Lf)
End If
strDescription += strCommentLine + CStr(Lf)
objSel = DTE.ActiveDocument.Selection()
objSel.Text = strDescription
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" + CStr(Lf) + "with the function prototype selected.")
End If
End Sub
Sub AddMemberGroupDescription()
' ±×·ì ÁÖ¼®À» Áý¾î³Ö´Â´Ù.
InsertText(Tab + "/// \name Simple getter & setter" + CrLf + Tab + "/// \{ " + CrLf + Tab + "/// \brief " + CrLf + Tab + "/// \} " + CrLf)
End Sub
Sub WrapStringWithTcharMacro()
' ÇöÀç ¼±ÅÃµÈ ¹®ÀÚ¿À» _T() ¸ÅÅ©·Î·Î °¨½Ñ´Ù.
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
Dim objEndPt As EditPoint
objRanges = ActiveDocument().Selection.TextRanges
objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
objEndPt = objRanges.Item(objRanges.Count).EndPoint.CreateEditPoint()
' ¹®ÀÚ¿ÀÇ Ã³À½À» ã´Â´Ù.
While objStartPt.GetText(-1) <> """" Or objStartPt.GetText(-2) = "\"""
objStartPt.CharLeft(1)
End While
objStartPt.CharLeft(1)
' ¹®ÀÚ¿ÀÇ ³¡À» ã´Â´Ù.
While objEndPt.GetText(1) <> """" Or objEndPt.GetText(-1) = "\"
objEndPt.CharRight(1)
End While
objEndPt.CharRight(1)
If objStartPt.GetText(-3) <> "_T(" Then
' ÀÌ¹Ì _T ¸ÅÅ©·Î·Î °¨½Î¿© ÀÖ´Â ¹®ÀÚ¿ÀÌ ¾Æ´Ï¶ó¸é °¨½ÎÁØ´Ù.
objStartPt.Insert("_T(")
objEndPt.Insert(")")
Else
' _T ¸ÅÅ©·Î·Î °¨½ÎÀÎ »óŶó¸é ¸ÅÅ©·Î¸¦ Á¦°ÅÇÑ´Ù.
objStartPt.Delete(-3)
objEndPt.Delete(1)
End If
End Sub
Function ParseVariableDeclarations( _
ByVal strText As String, ByRef colTypes As Collection, ByRef colNames As Collection, ByRef colComments As Collection)
' º¯¼ö ¼±¾ð¹®À» ÆÄ½ÌÇØ¼, º¯¼ö ŸÀÔ + º¯¼ö À̸§ + ÁÖ¼®À¸·Î ºÐ¸®½ÃŲ´Ù.
arrLines = strText.Split(Lf)
For Each line In arrLines
strLine = line
' ÁÂ¿ì °ø¹é Á¦°Å
strLine = Strip(strLine)
If Len(strLine) = 0 Then Continue For
' ¹®ÀÚ¿ ¾È¿¡ ÀÖ´Â 2°³ ÀÌ»óÀÇ ½ºÆäÀ̽º¸¦ Çϳª·Î ¸¸µç´Ù.
Do
nSpacePos = InStr(strLine, " ")
If nSpacePos <> 0 Then
strLine = Replace(strLine, " ", " ")
Else
Exit Do
End If
Loop
' ¹®ÀÚ¿ ¾È¿¡ ÀÖ´Â ÅÇÀ» ½ºÆäÀ̽º·Î ġȯÇÑ´Ù.
Do
nSpacePos = InStr(strLine, vbTab)
If nSpacePos <> 0 Then
strLine = Replace(strLine, vbTab, " ")
Else
Exit Do
End If
Loop
' ¶óÀÎ Á¦ÀÏ Ã³À½ ³ª¿À´Â ';' ±ÛÀÚ¿Í ';' ±ÛÀÚ ¾Õ¿¡¼ Á¦ÀÏ Ã³À½ ³ªÅ¸³ª´Â ' ' ±ÛÀÚ¸¦ ã´Â´Ù.
bSuccess = False
nSemicolonPos = InStr(strLine, ";")
If nSemicolonPos <> 0 Then
nSpacePos = InStrRev(strLine, " ", nSemicolonPos)
If nSpacePos <> 0 Then
bSuccess = True
End If
End If
' µÎ ±ÛÀÚ ¸ðµÎ¸¦ ã¾Ò´Ù¸é, º¯¼ö ¼±¾ð¹®À̶ó°í ÇÒ ¼ö ÀÖ´Ù.
If bSuccess Then
strVarType = Strip(Mid(strLine, 1, nSpacePos))
strVarName = Strip(Mid(strLine, nSpacePos, nSemicolonPos - nSpacePos))
strVarComment = ""
If nSemicolonPos <> 0 Then
strVarComment = Strip(Mid(strLine, nSemicolonPos + 1, Len(strLine) - nSemicolonPos))
End If
strVarType = Strip(Replace(strVarType, vbTab, " "))
strVarName = Strip(Replace(strVarName, vbTab, " "))
strVarComment = Strip(Replace(strVarComment, vbTab, " "))
If strVarType <> "" And strVarName <> "" Then
colTypes.Add(strVarType)
colNames.Add(strVarName)
colComments.Add(strVarComment)
End If
End If
Next
End Function
Function ParseVariableDeclarationsEx( _
ByVal strText As String, ByRef colTypes As Collection, ByRef colNames As Collection, ByRef colComments As Collection, ByRef colWholeComments As Collection)
' º¯¼ö ¼±¾ð¹®À» ÆÄ½ÌÇØ¼, º¯¼ö ŸÀÔ + º¯¼ö À̸§ + ÁÖ¼®À¸·Î ºÐ¸®½ÃŲ´Ù.
arrLines = strText.Split(Lf)
For Each line In arrLines
strLine = line
' ÁÂ¿ì °ø¹é Á¦°Å
strLine = Strip(strLine)
If Len(strLine) = 0 Then
colTypes.Add("")
colNames.Add("")
colComments.Add("")
colWholeComments.Add("")
Continue For
End If
' ¹®ÀÚ¿ ¾È¿¡ ÀÖ´Â 2°³ ÀÌ»óÀÇ ½ºÆäÀ̽º¸¦ Çϳª·Î ¸¸µç´Ù.
Do
nSpacePos = InStr(strLine, " ")
If nSpacePos <> 0 Then
strLine = Replace(strLine, " ", " ")
Else
Exit Do
End If
Loop
' ¹®ÀÚ¿ ¾È¿¡ ÀÖ´Â ÅÇÀ» ½ºÆäÀ̽º·Î ġȯÇÑ´Ù.
Do
nSpacePos = InStr(strLine, vbTab)
If nSpacePos <> 0 Then
strLine = Replace(strLine, vbTab, " ")
Else
Exit Do
End If
Loop
' ¶óÀÎ Á¦ÀÏ Ã³À½ ³ª¿À´Â ';' ±ÛÀÚ¿Í ';' ±ÛÀÚ ¾Õ¿¡¼ Á¦ÀÏ Ã³À½ ³ªÅ¸³ª´Â ' ' ±ÛÀÚ¸¦ ã´Â´Ù.
bSuccess = False
nSemicolonPos = InStr(strLine, ";")
If nSemicolonPos <> 0 Then
nSpacePos = InStrRev(strLine, " ", nSemicolonPos)
If nSpacePos <> 0 Then
bSuccess = True
End If
End If
' µÎ ±ÛÀÚ ¸ðµÎ¸¦ ã¾Ò´Ù¸é, º¯¼ö ¼±¾ð¹®À̶ó°í ÇÒ ¼ö ÀÖ´Ù.
If bSuccess Then
strVarType = Strip(Mid(strLine, 1, nSpacePos))
strVarName = Strip(Mid(strLine, nSpacePos, nSemicolonPos - nSpacePos))
strVarComment = ""
If nSemicolonPos <> 0 Then
strVarComment = Strip(Mid(strLine, nSemicolonPos + 1, Len(strLine) - nSemicolonPos))
End If
strVarType = Strip(Replace(strVarType, vbTab, " "))
strVarName = Strip(Replace(strVarName, vbTab, " "))
strVarComment = Strip(Replace(strVarComment, vbTab, " "))
If strVarType <> "" And strVarName <> "" Then
colTypes.Add(strVarType)
colNames.Add(strVarName)
colComments.Add(strVarComment)
colWholeComments.Add("")
Else
colTypes.Add("")
colNames.Add("")
colComments.Add("")
colWholeComments.Add(strLine)
End If
Else
colTypes.Add("")
colNames.Add("")
colComments.Add("")
colWholeComments.Add(strLine)
End If
Next
End Function
Function IsComplexType(ByVal strVarType)
' ÇØ´ç º¯¼ö°¡ C ±âº» ŸÀÔÀÎÁö ¾Æ´ÑÁö¸¦ ¹ÝȯÇÑ´Ù.
If strVarType <> "" Then
Dim objRegex As New System.Text.RegularExpressions.Regex("")
Dim colBasicTypes As New System.Collections.Generic.Dictionary(Of String, String)()
' ´ë¹®Àڷθ¸ ÀÌ·ç¾îÁ³Áö¸¸, ±¸Á¶Ã¼·Î Ãë±ÞÇÏÁö ¾ÊÀ» ŸÀÔµé »ý¼º
colBasicTypes.Add("DWORD", "")
colBasicTypes.Add("BOOL", "")
colBasicTypes.Add("BYTE", "")
colBasicTypes.Add("WORD", "")
colBasicTypes.Add("FLOAT", "")
colBasicTypes.Add("PFLOAT", "")
colBasicTypes.Add("PBOOL", "")
colBasicTypes.Add("LPBOOL", "")
colBasicTypes.Add("PBYTE", "")
colBasicTypes.Add("LPBYTE", "")
colBasicTypes.Add("PINT", "")
colBasicTypes.Add("LPINT", "")
colBasicTypes.Add("PWORD", "")
colBasicTypes.Add("LPWORD", "")
colBasicTypes.Add("LPLONG", "")
colBasicTypes.Add("PDWORD", "")
colBasicTypes.Add("LPDWORD", "")
colBasicTypes.Add("LPVOID", "")
colBasicTypes.Add("LPCVOID", "")
colBasicTypes.Add("INT", "")
colBasicTypes.Add("UINT", "")
colBasicTypes.Add("PUINT", "")
colBasicTypes.Add("WPARAM", "")
colBasicTypes.Add("LPARAM", "")
colBasicTypes.Add("LRESULT", "")
If objRegex.IsMatch(strVarType, "^c[A-Z][A-Za-z0-9]+[^\*\&]$") Then
' cDateTime, cTokenizer
Return True
ElseIf objRegex.IsMatch(strVarType, "^[A-Za-z]+_t$") Then
' wchar_t, ObjectId_t
Return False
ElseIf objRegex.IsMatch(strVarType, "^LP[A-Z0-9_]+$") Then
' LPD3DXMESH, LPDIRECT3D9
Return False
ElseIf objRegex.IsMatch(strVarType, "^[A-Z0-9_]+[^\*\&]$") And Not colBasicTypes.ContainsKey(strVarType) Then
' D3DXVECTOR, OVERLAPPED
Return True
ElseIf objRegex.IsMatch(strVarType, "^.+<.+>$") Then
' std::vector<int>, cMyTemplate<bool>
Return True
End If
End If
Return False
End Function
Function GetFieldName(ByVal strVarName)
' º¯¼ö À̸§À» ÅëÇØ, Get/Set ÇÔ¼ö µî¿¡ ¾²ÀÌ´Â Çʵå À̸§À» ÃßÁ¤ÇÑ´Ù.
Dim strFieldName As String
Dim objRegex As New System.Text.RegularExpressions.Regex("")
strFieldName = strVarName
If Left(strFieldName, 2) = "m_" Then
strFieldName = Right(strFieldName, Len(strFieldName) - 2)
ElseIf Left(strFieldName, 2) = "s_" Then
strFieldName = Right(strFieldName, Len(strFieldName) - 2)
End If
If objRegex.IsMatch(strFieldName, "^[a-z]+[^a-z].+$") Then
strFieldName = objRegex.Replace(strFieldName, "^([a-z]+)([^a-z].+)$", "$2")
End If
Return strFieldName
End Function
Sub MakeSimpleGetterSetter()
' ÇöÀç ¼±ÅÃµÈ º¯¼öµé¿¡ ´ëÇÑ Á¢±Ù ÇÔ¼ö¸¦ ¸¸µç´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim objStream As New System.Text.StringBuilder
ParseVariableDeclarations(Strip(GetSelectedText()), colTypes, colNames, colComments)
For i = 1 To colNames.Count
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Getter"))
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Setter"))
If i < colNames.Count Then
objStream.Append(Lf)
End If
Next
ReplaceSelectedText(objStream.ToString())
End Sub
Sub MakeSimpleGetterSetterEx()
' ÇöÀç ¼±ÅÃµÈ º¯¼öµé¿¡ ´ëÇÑ Á¢±Ù ÇÔ¼ö¸¦ ¸¸µç´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim objStream As New System.Text.StringBuilder
ParseVariableDeclarations(Strip(GetSelectedText()), colTypes, colNames, colComments)
For i = 1 To colNames.Count
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Getter"))
Next
objStream.Append(Lf)
For i = 1 To colNames.Count
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Setter"))
Next
ReplaceSelectedText(objStream.ToString())
End Sub
Sub MakePacketInterface()
' ÆÐŶ ÇÔ¼öµéÀ» »ý¼ºÇÑ´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim colWholeComments As New Collection
Dim nCount As Integer
Dim objStream As New System.Text.StringBuilder
ParseVariableDeclarations(Strip(ActiveDocument().Selection.Text), colTypes, colNames, colComments)
If colTypes.Count = 0 Then
Exit Sub
End If
'------------------------------------------------------------------------------------------
objStream.Append("public:" + CrLf)
objStream.Append(Tab + "/// \brief ÆÐŶÀÇ ½ÇÁ¦ ±æÀ̸¦ ¹ÝȯÇÑ´Ù." + CrLf)
objStream.Append(Tab + "virtual uint32 GetSize() const" + CrLf)
objStream.Append(Tab + "{" + CrLf)
If colNames.Count = 1 Then
If colNames.Item(1) <> "" Then
objStream.Append(Tab + Tab + "return Bytes(" + colNames.Item(1) + ");" + CrLf)
End If
Else
nCount = 1
For Each strLine In colNames
If strLine <> "" Then
If nCount = 1 Then
objStream.Append(Tab + Tab + "return Bytes(" + strLine + ") +" + CrLf)
ElseIf nCount = colNames.Count Then
objStream.Append(Tab + Tab + Tab + "Bytes(" + strLine + ");" + CrLf)
Else
objStream.Append(Tab + Tab + Tab + "Bytes(" + strLine + ") +" + CrLf)
End If
End If
nCount = nCount + 1
Next
End If
objStream.Append(Tab + "}" + CrLf + CrLf)
'------------------------------------------------------------------------------------------
objStream.Append(Tab + "/// \brief ÆÐŶÀÇ ÃÖ´ë ±æÀ̸¦ ¹ÝȯÇÑ´Ù." + CrLf)
objStream.Append(Tab + "virtual uint32 GetMaxSize() const" + CrLf)
objStream.Append(Tab + "{" + CrLf)
If colNames.Count = 1 Then
If colNames.Item(1) <> "" Then
objStream.Append(Tab + Tab + "return MaxBytes(" + colNames.Item(1) + ");" + CrLf)
End If
Else
nCount = 1
For Each strLine In colNames
If strLine <> "" Then
If nCount = 1 Then
objStream.Append(Tab + Tab + "return MaxBytes(" + strLine + ") +" + CrLf)
ElseIf nCount = colNames.Count Then
objStream.Append(Tab + Tab + Tab + "MaxBytes(" + strLine + ");" + CrLf)
Else
objStream.Append(Tab + Tab + Tab + "MaxBytes(" + strLine + ") +" + CrLf)
End If
End If
nCount = nCount + 1
Next
End If
objStream.Append(Tab + "}" + CrLf + CrLf)
'------------------------------------------------------------------------------------------
objStream.Append(Tab + "/// \brief ÆÐŶ ³»ºÎ µ¥ÀÌÅ͸¦ Á÷·ÄÈÇÏ¿© ¹ÙÀÌÆ® ¹öÆÛ¿¡´Ù ¾´´Ù." + CrLf)
objStream.Append(Tab + "virtual uint32 Marshall(cSocketStream& oBuffer) const" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + Tab + "uint32 count = 0;" + CrLf)
For Each strLine In colNames
If strLine <> "" Then
objStream.Append(Tab + Tab + "count += oBuffer.Write(" + strLine + ");" + CrLf)
End If
Next
objStream.Append(Tab + Tab + "return count; " + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
'------------------------------------------------------------------------------------------
objStream.Append(Tab + "/// \brief ¹ÙÀÌÆ® ¹öÆÛ¿¡¼ µ¥ÀÌÅ͸¦ Àоîµé¿© ÆÐŶ °´Ã¼¸¦ ±¸¼ºÇÑ´Ù." + CrLf)
objStream.Append(Tab + "virtual uint32 Unmarshall(cSocketStream& iBuffer)" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + Tab + "uint32 count = 0;" + CrLf)
For Each strLine In colNames
If strLine <> "" Then
objStream.Append(Tab + Tab + "count += iBuffer.Read(" + strLine + ");" + CrLf)
End If
Next
objStream.Append(Tab + Tab + "return count; " + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
'------------------------------------------------------------------------------------------
objStream.Append(Tab + "/// \brief Àç»ç¿ëÀ» À§ÇØ ÆÐŶÀ» Á¤¸®ÇÑ´Ù." + CrLf)
objStream.Append(Tab + "virtual void Reset()" + CrLf)
objStream.Append(Tab + "{" + CrLf)
For Each strLine In colNames
If strLine <> "" Then
objStream.Append(Tab + Tab + "ResetVariable(" + strLine + ");" + CrLf)
End If
Next
objStream.Append(Tab + "}" + CrLf + CrLf + CrLf)
'------------------------------------------------------------------------------------------
objStream.Append("public:" + CrLf)
objStream.Append(Tab + "/// \name Simple getter/setter" + CrLf)
objStream.Append(Tab + "/// \{" + CrLf)
For i = 1 To colNames.Count
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Getter"))
objStream.Append(GenerateAccessor(colTypes.Item(i), colNames.Item(i), "Setter"))
If i < colNames.Count Then
objStream.Append(Lf)
End If
Next
objStream.Append(Tab + "/// \}" + CrLf)
'------------------------------------------------------------------------------------------
ReplaceSelectedText(objStream.ToString())
End Sub
Sub MakePrettyVariableDeclaration()
' º¯¼ö ¼±¾ð¹®ÀÇ ÅÇÀ» Á¤·ÄÇÑ´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim colWholeComments As New Collection
Dim nMaxTypeLength As Integer
Dim nMaxNameLength As Integer
Dim objStream As New System.Text.StringBuilder
ParseVariableDeclarationsEx(Strip(GetSelectedText()), colTypes, colNames, colComments, colWholeComments)
nMaxTypeLength = 0
For Each s In colTypes
nMaxTypeLength = System.Math.Max(nMaxTypeLength, Len(s))
Next
nMaxNameLength = 0
For Each s In colNames
nMaxNameLength = System.Math.Max(nMaxNameLength, Len(s))
Next
For i = 1 To colTypes.Count
If colTypes.Item(i) <> "" And colNames.Item(i) <> "" Then
vtype = colTypes.Item(i)
vname = colNames.Item(i)
vcomment = colComments.Item(i)
typeSpaces = nMaxTypeLength - Len(vtype)
nameSpaces = nMaxNameLength - Len(vname)
For t = 1 To typeSpaces
vtype += " "
Next
vname += ";"
For n = 1 To nameSpaces
vname += " "
Next
line = vtype + " " + vname + " " + vcomment
objStream.Append(vbTab + Strip(line) + CrLf)
Else
objStream.Append(vbTab + colWholeComments.Item(i) + CrLf)
End If
Next
ReplaceSelectedText(objStream.ToString())
End Sub
Sub MakeConstructors()
' ±âº» »ý¼ºÀÚ, º¹»ç »ý¼ºÀÚ, ´ëÀÔ ¿¬»êÀÚ, ¼Ò¸êÀÚ¸¦ ¸ðµÎ »ý¼ºÇÑ´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim colWholeComments As New Collection
Dim objStream As New System.Text.StringBuilder
Dim strFileName As String
Dim strClassName As String
Dim strVarName As String
strFileName = ActiveDocument().Name
If strFileName = "" Then
Exit Sub
End If
' ÆÄÀÏ À̸§À¸·Î Ŭ·¡½º À̸§À» ÃßÁ¤ÇÑ´Ù.
strClassName = "c" + Left(strFileName, InStrRev(strFileName, ".") - 1)
' ½ÇÁ¦ Ŭ·¡½º À̸§À» ÀԷ¹޴´Ù.
strClassName = InputBox("Ŭ·¡½º À̸§À» ÀÔ·ÂÇϼ¼¿ä.", "Ŭ·¡½º À̸§ÀÌ ÇÊ¿äÇÕ´Ï´Ù.", strClassName)
If Len(strClassName) > 0 Then
ParseVariableDeclarations(Strip(GetSelectedText()), colTypes, colNames, colComments)
' ±âº» »ý¼ºÀÚ
objStream.Append(Tab + "/// \brief »ý¼ºÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "()" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' º¹»ç »ý¼ºÀÚ
objStream.Append(Tab + "/// \brief º¹»ç »ý¼ºÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "(const " + strClassName + "& rhs)" + CrLf)
objStream.Append(Tab + Tab + ": ")
For i = 1 To colNames.Count
strVarName = colNames.Item(i)
If i > 1 Then
objStream.Append(Tab + Tab)
End If
objStream.Append(strVarName + "(rhs." + strVarName + ")")
If i < colNames.Count Then
objStream.Append(", ")
End If
objStream.Append(CrLf)
Next
objStream.Append(Tab + "{" + CrLf + Tab + "}" + CrLf + CrLf)
' ´ëÀÔ ¿¬»êÀÚ
objStream.Append(Tab + "/// \brief ´ëÀÔ ¿¬»êÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "& operator = (const " + strClassName + "& rhs)" + CrLf)
objStream.Append(Tab + "{" + CrLf)
For i = 1 To colNames.Count
strVarName = colNames.Item(i)
objStream.Append(Tab + Tab + strVarName + " = rhs." + strVarName + ";" + CrLf)
Next
objStream.Append(Tab + Tab + "return *this; " + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' ¼Ò¸êÀÚ
objStream.Append(Tab + "/// \brief ¼Ò¸êÀÚ" + CrLf)
objStream.Append(Tab + "virtual ~" + strClassName + "()" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' »ý¼ºÇÑ ¹®ÀÚ¿ ´ëÀÔ
ReplaceSelectedText(objStream.ToString())
End If
End Sub
Sub MakeStlContainerConstructors()
' STL ÄÁÅ×ÀÌ³Ê¿ë ±âº» »ý¼ºÀÚ, º¹»ç »ý¼ºÀÚ, ´ëÀÔ ¿¬»êÀÚ, ¼Ò¸êÀÚ¸¦ »ý¼ºÇÑ´Ù.
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim objStream As New System.Text.StringBuilder
Dim strFileName As String
Dim strClassName As String
Dim strVarName As String
Dim strContainerType As String
strFileName = ActiveDocument().Name
If strFileName = "" Then
Exit Sub
End If
' ÆÄÀÏ À̸§À¸·Î Ŭ·¡½º À̸§À» ÃßÁ¤ÇÑ´Ù.
strClassName = "c" + Left(strFileName, InStrRev(strFileName, ".") - 1)
' ½ÇÁ¦ Ŭ·¡½º À̸§À» ÀԷ¹޴´Ù.
strClassName = InputBox("Ŭ·¡½º À̸§À» ÀÔ·ÂÇϼ¼¿ä.", "Ŭ·¡½º À̸§ÀÌ ÇÊ¿äÇÕ´Ï´Ù.", strClassName)
' Ŭ·¡½º À̸§ÀÌ ¿Ã¹Ù¸¥Áö üũÇÑ´Ù.
If Len(strClassName) = 0 Then
Exit Sub
End If
' ÄÁÅ×À̳ÊÀÇ Á¾·ù¸¦ ÀԷ¹޴´Ù.
strContainerType = InputBox("ÄÁÅ×ÀÌ³Ê Å¸ÀÔÀ» ÀÔ·ÂÇϼ¼¿ä." + CrLf + "vector, list, set, map 4°¡Áö ŸÀÔÀÌ Çã¿ëµË´Ï´Ù.", "ÄÁÅ×ÀÌ³Ê Å¸ÀÔÀÌ ÇÊ¿äÇÕ´Ï´Ù", "list")
strContainerType = Strip(strContainerType).ToLower()
' ÄÁÅ×À̳ÊÀÇ Á¾·ù°¡ ¿Ã¹Ù¸¥Áö üũÇÑ´Ù.
If strContainerType <> "vector" And strContainerType <> "list" And _
strContainerType <> "set" And strContainerType <> "map" Then
Exit Sub
End If
' ±âº» »ý¼ºÀÚ
objStream.Append(Tab + "/// \brief »ý¼ºÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "()" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' º¹»ç »ý¼ºÀÚ
objStream.Append(Tab + "/// \brief º¹»ç »ý¼ºÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "(const " + strClassName + "& rhs)" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + Tab + "const_iterator e(rhs.end());" + CrLf)
objStream.Append(Tab + Tab + "for (const_iterator itr(rhs.begin()); itr != e; ++itr)" + CrLf)
If strContainerType = "vector" Or strContainerType = "list" Then
objStream.Append(Tab + Tab + Tab + "push_back(*itr);" + CrLf)
Else
objStream.Append(Tab + Tab + Tab + "insert(*itr);" + CrLf)
End If
objStream.Append(Tab + "}" + CrLf + CrLf)
' ´ëÀÔ ¿¬»êÀÚ
objStream.Append(Tab + "/// \brief ´ëÀÔ ¿¬»êÀÚ" + CrLf)
objStream.Append(Tab + strClassName + "& operator = (const " + strClassName + "& rhs)" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + Tab + "clear();" + CrLf + CrLf)
objStream.Append(Tab + Tab + "const_iterator e(rhs.end());" + CrLf)
objStream.Append(Tab + Tab + "for (const_iterator itr(rhs.begin()); itr != e; ++itr)" + CrLf)
If strContainerType = "vector" Or strContainerType = "list" Then
objStream.Append(Tab + Tab + Tab + "push_back(*itr);" + CrLf + CrLf)
Else
objStream.Append(Tab + Tab + Tab + "insert(*itr);" + CrLf + CrLf)
End If
objStream.Append(Tab + Tab + "return *this; " + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' ¼Ò¸êÀÚ
objStream.Append(Tab + "/// \brief ¼Ò¸êÀÚ" + CrLf)
objStream.Append(Tab + "virtual ~" + strClassName + "()" + CrLf)
objStream.Append(Tab + "{" + CrLf)
objStream.Append(Tab + Tab + "clear();" + CrLf)
objStream.Append(Tab + "}" + CrLf + CrLf)
' »ý¼ºÇÑ ¹®ÀÚ¿ ´ëÀÔ
InsertText(objStream.ToString())
End Sub
Sub EnumToString()
' ¿°ÅÇü ¹®ÀÚ¿ º¯È¯
Dim objRegex As New System.Text.RegularExpressions.Regex("")
Dim objMatch As System.Text.RegularExpressions.Match
Dim objGroup1 As System.Text.RegularExpressions.Group
Dim objGroup2 As System.Text.RegularExpressions.Group
Dim objStream As New System.Text.StringBuilder
Dim arrLines As Array
Dim colIds As New Collection
Dim nValidIds As Integer
Dim colStripped As New Collection
Dim colComments As New Collection
' ÆÄ½Ì
arrLines = GetSelectedText().Split(Lf)
nValidIds = 0
For Each strLine In arrLines
strLine = Strip(strLine)
If Len(strLine) > 0 Then
objMatch = objRegex.Match(strLine, "^\s*(\w+)\s*,\s*([^ \t].*)$")
If objMatch.Success Then
objGroup1 = objMatch.Groups(1)
objGroup2 = objMatch.Groups(2)
colIds.Add(Strip(objGroup1.ToString()))
colComments.Add(Strip(objGroup2.ToString()))
nValidIds = nValidIds + 1
Else
colIds.Add("")
colComments.Add("")
End If
Else
colIds.Add("")
colComments.Add("")
End If
Next
If nValidIds = 1 Then
For i = 1 To colIds.Count
If colIds.Item(i) <> "" Then
objStream.Append("""" + colIds.Item(i) + """, " + colComments.Item(i) + CrLf)
End If
Next
ReplaceSelectedText(objStream.ToString())
ElseIf nValidIds > 1 Then
' ¹®ÀÚ¿ ¿ÞÂÊ¿¡¼ °øÅëµÇ´Â ºÎºÐÀ» ã´Â´Ù.
' SOME_TYPE_FIRST
' SOME_TYPE_SECOND
' ÀÌ·± °ªµé¿¡¼ SOME_TYPE_ ºÎºÐÀ» ã´Â´Ù´Â ¸»ÀÌ´Ù.
bContinue = True
nPrefixLength = 0
While bContinue
For i = 2 To colIds.Count
strPrev = colIds.Item(i - 1)
strCurrent = colIds.Item(i)
If Len(strPrev) > 0 And Len(strCurrent) > 0 And _
Left(strPrev, nPrefixLength + 1) <> Left(strCurrent, nPrefixLength + 1) Then
bContinue = False
End If
Next
nPrefixLength = nPrefixLength + 1
End While
' °øÅëµÇ´Â ºÎºÐÀ» Á¦°ÅÇϰí, ½Öµû¿ÈÇ¥¸¦ ºÙÀδÙ.
' SOME_TYPE_FIRST --> "FIRST",
' SOME_TYPE_SECOND --> "SECOND",
For i = 1 To colIds.Count
strId = colIds.Item(i)
If Len(strId) > 0 Then
colStripped.Add("_T(""" + Mid(strId, nPrefixLength, 9999) + """),")
Else
colStripped.Add("")
End If
Next
' °øÅëµÇ´Â ºÎºÐÀ» Á¦°ÅÇÑ ¹®ÀÚ¿¿¡¼ Á¦ÀÏ ±ä ³ðÀ» ã¾Æ³½´Ù.
nMaxLength = 0
For i = 1 To colStripped.Count
strId = colStripped.Item(i)
If Len(strId) > nMaxLength Then
nMaxLength = Len(strId)
End If
Next
For i = 1 To colStripped.Count
strId = colStripped.Item(i)
strComment = colComments.Item(i)
If Len(strId) > 0 Then
' Á¦ÀÏ ±ä ³ðº¸´Ù ª´Ù¸é ¸ðÀÚ¶õ ¼ýÀÚ¸¸ÅÀÇ ½ºÆäÀ̽º¸¦ ºÙÀδÙ.
nMargin = nMaxLength - Len(strId)
For m = 1 To nMargin
strId += " "
Next
objStream.Append(strId + " " + strComment + CrLf)
Else
objStream.Append(Lf)
End If
Next
ReplaceSelectedText(objStream.ToString())
End If
End Sub
Sub MakeEnumToStringStatement()
' ¿°ÅÇü ¹®ÀÚ¿ º¯È¯
Dim objRegex As New System.Text.RegularExpressions.Regex("")
Dim objMatch As System.Text.RegularExpressions.Match
Dim objStream As New System.Text.StringBuilder
objStream.Append(Tab + "BEGIN_CONVERSION" + CrLf)
For Each strLine In GetSelectedText().Split(Lf)
strLine = Strip(strLine)
If Len(strLine) > 0 Then
objMatch = objRegex.Match(strLine, "^\s*([A-Za-z0-9_]+).*$")
If objMatch.Success Then
objStream.Append(Tab + Tab + "ADD_CONVERSION(" + Strip(objMatch.Groups(1).ToString()) + ")" + CrLf)
End If
End If
Next
objStream.Append(Tab + "END_CONVERSION" + CrLf + CrLf)
objStream.Append(Tab + "return INT2STRING(m_ResultCode);" + CrLf)
ReplaceSelectedText(objStream.ToString)
End Sub
Function GetAsciiLength(ByVal str As String)
Return System.Text.Encoding.Default.GetBytes(str).Length
End Function
Sub WrapDoxygenComment()
Dim nMaxLength As Integer = 100 - 1 ' -1Àº µü ºÙ¾îÀÖ´Â °Å ÂóÂóÇØ¼
Dim nLineLength As Integer = 0
Dim objRegex As System.Text.RegularExpressions.Regex
Dim objMatch As System.Text.RegularExpressions.Match
Dim objStream As New System.Text.StringBuilder
Dim objLines As New Collection
Dim objSel As TextSelection = ActiveDocument().Selection
Dim objRanges As TextRanges = objSel.TextRanges
Dim objStartPt As EditPoint = objRanges.Item(1).StartPoint.CreateEditPoint()
For Each s In objSel.Text.Split(Lf)
s = Strip(s)
If objRegex.IsMatch(s, "^////+$") Then
Else
objMatch = objRegex.Match(s, "^///")
If objMatch.Success Then
s = Strip(s.Substring(objMatch.Length))
End If
End If
objLines.Add(s)
Next
For i = 1 To objLines.Count - 1
strLine = objLines.Item(i)
If strLine.Length = 0 Then
objStream.Append(CrLf)
objStream.Append("/// ")
nLineLength = 0
ElseIf objRegex.IsMatch(strLine, "^////+$") Then
objStream.Append(CrLf)
objStream.Append(strLine)
nLineLength = 0
Else
For Each match As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(strLine, "\S+\s*")
If nLineLength = 0 Or match.Value.StartsWith("\") Or nLineLength + GetAsciiLength(match.Value) > nMaxLength Then
objStream.Append(CrLf)
objStream.Append("/// ")
nLineLength = 4
End If
objStream.Append(Strip(match.Value) + " ")
nLineLength += GetAsciiLength(Strip(match.Value)) + 1
Next
End If
Next
objStream.Append(CrLf)
' ÇöÀç ¼±ÅÃµÈ ¹®ÀÚ¿À» ÁÖ¾îÁø ¹®ÀÚ¿·Î ġȯÇÑ´Ù.
objSel.Text = ""
objStartPt.Insert(objStream.ToString().Substring(2))
End Sub
Structure EnumDesc
Public IntName As String
Public EnumName As String
Public MaxName As String
End Structure
Function GenerateAccessor(ByVal strVarType As String, ByVal strVarName As String, ByVal strMode As String)
Dim strResult As String
Dim colEnumList As New System.Collections.Generic.List(Of EnumDesc)
Dim objReader As New System.IO.StreamReader("D:\Project\VSMacros\Enums.txt")
Dim arrTokens As Array
Dim bFound As Boolean
Dim colBasicTypes As New System.Collections.Generic.Dictionary(Of String, String)
Dim objStream As New System.Text.StringBuilder
Dim bComplexType As Boolean
Dim strFieldName As String
Try
Do
strLine = objReader.ReadLine
arrTokens = strLine.split(",")
If arrTokens.Length = 3 Then
Dim objDesc As New EnumDesc
objDesc.IntName = arrTokens.GetValue(0)
objDesc.EnumName = arrTokens.GetValue(1)
objDesc.MaxName = arrTokens.GetValue(2)
colEnumList.Add(objDesc)
End If
Loop Until objReader.Peek = -1
Catch
Finally
objReader.Close()
End Try
If strVarType <> "" And strVarName <> "" Then
bComplexType = IsComplexType(strVarType)
strFieldName = GetFieldName(strVarName)
bFound = False
For Each desc In colEnumList
If strVarType = desc.IntName Then
If strMode = "Getter" Then
strResult += Tab + desc.EnumName + " Get" + strFieldName + "() const { return static_cast<" + desc.EnumName + ">(" + strVarName + "); }" + CrLf
Else
strResult += Tab + "void Set" + strFieldName + "(" + desc.EnumName + " value) { " + strVarName + " = static_cast<" + desc.IntName + ">(value); }" + CrLf
End If
bFound = True
Exit For
End If
Next
If Not bFound Then
If strVarType = "std::string" Then
If strMode = "Getter" Then
strResult += Tab + "const std::string& Get" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
Else
strResult += Tab + "void Set" + strFieldName + "(const char* value) { " + strVarName + " = value ? value : """"; }" + CrLf
strResult += Tab + "void Set" + strFieldName + "(const std::string& value) { " + strVarName + " = value; }" + CrLf
End If
ElseIf strVarType = "std::wstring" Then
If strMode = "Getter" Then
strResult += Tab + "const std::wstring& Get" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
Else
strResult += Tab + "void Set" + strFieldName + "(LPCWSTR value) { " + strVarName + " = value ? value : L""""; }" + CrLf
strResult += Tab + "void Set" + strFieldName + "(const std::wstring& value) { " + strVarName + " = value; }" + CrLf
End If
ElseIf strVarType = "tstring" Then
If strMode = "Getter" Then
strResult += Tab + "const tstring& Get" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
Else
strResult += Tab + "void Set" + strFieldName + "(LPCTSTR value) { " + strVarName + " = value ? value : _T(""""); }" + CrLf
strResult += Tab + "void Set" + strFieldName + "(const tstring& value) { " + strVarName + " = value; }" + CrLf
End If
ElseIf strVarType = "uint8" And strFieldName = "ResultCode" Then
If strMode = "Getter" Then
strResult += Tab + "ResultCode GetResultCode() const { return static_cast<ResultCode>(m_ResultCode); }" + CrLf
Else
strResult += Tab + "void SetResultCode(ResultCode result) { m_ResultCode = static_cast<uint8>(result); }" + CrLf
End If
ElseIf strVarType = "uint8" And strFieldName = "OpCode" Then
If strMode = "Getter" Then
strResult += Tab + "OpCode GetOpCode() const { return static_cast<OpCode>(m_OpCode); }" + CrLf
Else
strResult += Tab + "void SetOpCode(OpCode result) { m_OpCode = static_cast<uint8>(result); }" + CrLf
End If
ElseIf strVarType = "uint8" And strFieldName = "ErrorCode" Then
If strMode = "Getter" Then
strResult += Tab + "ErrorCode GetErrorCode() const { return static_cast<ErrorCode>(m_ErrorCode); }" + CrLf
Else
strResult += Tab + "void SetErrorCode(ErrorCode result) { m_ErrorCode = static_cast<uint8>(result); }" + CrLf
End If
Else
If strMode = "Getter" Then
If bComplexType Then
strResult += Tab + strVarType + "& Get" + strFieldName + "() { return " + strVarName + "; }" + CrLf
strResult += Tab + "const " + strVarType + "& Get" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
ElseIf strVarType = "bool" Or strVarType = "BOOL" Then
strResult += Tab + strVarType + " Is" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
Else
strResult += Tab + strVarType + " Get" + strFieldName + "() const { return " + strVarName + "; }" + CrLf
End If
Else
If bComplexType Then
strResult += Tab + "void Set" + strFieldName + "(const " + strVarType + "& value) { " + strVarName + " = value; }" + CrLf
ElseIf strVarType = "bool" Or strVarType = "BOOL" Then
strResult += Tab + "void Set" + strFieldName + "(" + strVarType + " value) { " + strVarName + " = value; }" + CrLf
Else
strResult += Tab + "void Set" + strFieldName + "(" + strVarType + " value) { " + strVarName + " = value; }" + CrLf
End If
End If
End If
End If
End If
Return strResult
End Function
Sub MakeMemberVariableInitializationStatements()
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim colWholeComments As New Collection
Dim objStream As New System.Text.StringBuilder
Dim strVarName As String
Dim strVarType As String
Dim colUserTypes As New System.Collections.Generic.Dictionary(Of String, String)
Dim colEnumList As New System.Collections.Generic.List(Of EnumDesc)
Dim objReader As New System.IO.StreamReader("D:\Project\VSMacros\Enums.txt")
Dim arrTokens As Array
ParseVariableDeclarations(Strip(GetSelectedText()), colTypes, colNames, colComments)
Try
Do
strLine = objReader.ReadLine
arrTokens = strLine.split(",")
If arrTokens.Length = 3 Then
colUserTypes.Add(arrTokens.GetValue(1), arrTokens.GetValue(2))
End If
Loop Until objReader.Peek = -1
Catch
Finally
objReader.Close()
End Try
colUserTypes.Add("bool", "false")
colUserTypes.Add("BOOL", "FALSE")
colUserTypes.Add("float", "0.0f")
colUserTypes.Add("std::string", """""")
colUserTypes.Add("std::wstring", "L""""")
colUserTypes.Add("tstring", "_T("""")")
colUserTypes.Add("D3DXVECTOR2", "0.0f, 0.0f")
colUserTypes.Add("D3DXVECTOR3", "0.0f, 0.0f, 0.0f")
colUserTypes.Add("D3DXVECTOR4", "0.0f, 0.0f, 0.0f, 0.0f")
colUserTypes.Add("EffectId_t", "static_cast<EffectId_t>(EFFECT_MAX)")
colUserTypes.Add("InstanceId_t", "INVALID_INSTANCE_ID")
colUserTypes.Add("ItemOptionId_t", "INVALID_ITEM_OPTION_ID")
colUserTypes.Add("Model_t", "INVALID_MODEL")
colUserTypes.Add("ObjectId_t", "INVALID_OBJECT_ID")
colUserTypes.Add("PartyId_t", "INVALID_PARTY_ID")
colUserTypes.Add("QuestId_t", "INVALID_QUEST_ID")
colUserTypes.Add("SerialNumber_t", "INVALID_SERIAL_NUMBER")
colUserTypes.Add("ServerId_t", "INVALID_SERVER_ID")
colUserTypes.Add("ShopId_t", "INVALID_SHOP_ID")
colUserTypes.Add("WorldId_t", "INVALID_WORLD_ID")
colUserTypes.Add("ZoneId_t", "INVALID_ZONE_ID")
colUserTypes.Add("cItemInstanceKey", "ITEM_CLASS_MAX, INVALID_SERIAL_NUMBER")
colUserTypes.Add("cItemKey", "ITEM_CLASS_MAX, 0")
colUserTypes.Add("cItemPosition", "STORAGE_TYPE_MAX, 0, 0")
colUserTypes.Add("cItemStorageKey", "STORAGE_TYPE_MAX, 0")
colUserTypes.Add("cPoint2", "0.0f, 0.0f")
colUserTypes.Add("cPoint3", "0.0f, 0.0f, 0.0f")
colUserTypes.Add("cPoint4", "0.0f, 0.0f, 0.0f, 0.0f")
colUserTypes.Add("MailId_t", "INVALID_MAIL_ID")
colUserTypes.Add("AuctionId_t", "INVALID_AUCTION_ID")
objStream.Append(": " + CrLf)
For i = 1 To colNames.Count
strVarName = colNames.Item(i)
strVarType = colTypes.Item(i)
If colUserTypes.ContainsKey(strVarType) Then
objStream.Append(strVarName + "(" + colUserTypes.Item(strVarType) + ")")
ElseIf IsComplexType(strVarType) Then
objStream.Append(strVarName + "()")
Else
objStream.Append(strVarName + "(0)")
End If
If i < colNames.Count Then
objStream.Append(",")
End If
objStream.Append(CrLf)
Next
ReplaceSelectedText(objStream.ToString())
End Sub
Structure CommaDesc
Public Left As String
Public Right As String
Public Comment As String
End Structure
Sub MakeCommaAlignedStatements()
Dim colDescList As New System.Collections.Generic.List(Of CommaDesc)
Dim nMaxLeftLength As Integer
Dim objStream As New System.Text.StringBuilder
arrLines = Strip(GetSelectedText()).Split(Lf)
For Each line In arrLines
strLine = line
strLine = Strip(strLine)
If Len(strLine) = 0 Then
objDesc = New CommaDesc
objDesc.Left = ""
objDesc.Right = ""
objDesc.Comment = ""
colDescList.Add(objDesc)
Continue For
End If
Do
nSpacePos = InStr(strLine, " ")
If nSpacePos <> 0 Then
strLine = Replace(strLine, " ", " ")
Else
Exit Do
End If
Loop
Do
nSpacePos = InStr(strLine, vbTab)
If nSpacePos <> 0 Then
strLine = Replace(strLine, vbTab, " ")
Else
Exit Do
End If
Loop
nColonPos = InStr(strLine, ",")
If nColonPos <> 0 Then
NewDesc = New CommaDesc
NewDesc.Left = Strip(Mid(strLine, 1, nColonPos))
NewDesc.Right = Strip(Right(strLine, strLine.Length - nColonPos))
NewDesc.Comment = ""
' MsgBox("[" + objDesc.Left + "][" + objDesc.Right + "]")
colDescList.Add(NewDesc)
Else
strLine = line
NewDesc = New CommaDesc
NewDesc.Left = ""
NewDesc.Right = ""
NewDesc.Comment = Strip(strLine)
colDescList.Add(NewDesc)
End If
Next
nMaxLeftLength = 0
For Each objDesc In colDescList
If objDesc.Comment = "" Then
nMaxLeftLength = System.Math.Max(nMaxLeftLength, Len(objDesc.Left))
End If
Next
For Each objDesc In colDescList
If objDesc.Comment = "" Then
strLeft = objDesc.Left
strRight = objDesc.Right
nLeftSpaces = nMaxLeftLength - Len(strLeft)
For t = 1 To nLeftSpaces
strLeft += " "
Next
objStream.Append(vbTab + Strip(strLeft + " " + strRight) + CrLf)
Else
objStream.Append(objDesc.Comment + CrLf)
End If
Next
ReplaceSelectedText(objStream.ToString())
End Sub
Sub MakeHouseStyle()
Dim objLines As New Collection
Dim objSel As TextSelection = ActiveDocument().Selection
Dim objRanges As TextRanges = objSel.TextRanges
Dim objStartPt As EditPoint = objRanges.Item(1).StartPoint.CreateEditPoint()
Dim objRegex As New System.Text.RegularExpressions.Regex("")
Dim objStream As New System.Text.StringBuilder
For Each strLine In objSel.Text.Split(Lf)
strBuffer = strLine
strBuffer = objRegex.Replace(strBuffer, "if\(", "if (")
strBuffer = objRegex.Replace(strBuffer, "for\(", "for (")
strBuffer = objRegex.Replace(strBuffer, "\s+\)", ")")
strBuffer = objRegex.Replace(strBuffer, "\(\s+", "(")
strBuffer = objRegex.Replace(strBuffer, "\){", ") {")
strBuffer = objRegex.Replace(strBuffer, "([A-Za-z0-9]+)\s+\*\s+([A-Za-z0-9]+)\s*\;", "$1* $2;")
strBuffer = objRegex.Replace(strBuffer, "([A-Za-z0-9]+)=([A-Za-z0-9\.]+)", "$1 = $2")
objStream.Append(strBuffer)
Next
objSel.Text = ""
objStartPt.Insert(objStream.ToString())
End Sub
Sub PrepareIdxStatement()
Dim objRegex As New System.Text.RegularExpressions.Regex("([A-Z][a-z0-9]+)")
Dim objStream As New System.Text.StringBuilder
Dim objSel As TextSelection = ActiveDocument().Selection
objStream.AppendLine("try")
objStream.AppendLine("{")
For Each o In objSel.Text.Trim.Split((" " + vbTab).ToCharArray, StringSplitOptions.RemoveEmptyEntries)
Dim c As String = objRegex.Replace(o, "$1_").ToUpper()
If c.EndsWith("_") Then
c = c.Remove(c.Length - 1)
End If
c = "size_t IDX_" + c + " = table.GetColumnIndex(_T(""" + o + """));"
objStream.AppendLine(c)
Next
objStream.AppendLine("}")
objStream.AppendLine("catch (cException& e)")
objStream.AppendLine("{")
objStream.AppendLine("WriteError(_T(""error occured - %s""), e.GetDesc());")
objStream.AppendLine("}")
objSel.Text = objStream.ToString()
End Sub
Sub MakeIdxStatement()
Dim objSel As TextSelection = ActiveDocument().Selection
Dim text As String = objSel.Text
Dim objRegex As New System.Text.RegularExpressions.Regex("([A-Z][a-z0-9]+)")
If text.StartsWith("_T(") Then
text = text.Substring(3)
text = text.Remove(text.Length - 1)
End If
text = text.Substring(1)
text = text.Remove(text.Length - 1)
text = objRegex.Replace(text, "$1_").ToUpper()
If text.EndsWith("_") Then
text = text.Remove(text.Length - 1)
End If
text = "IDX_" + text
objSel.Text = text
End Sub
End Module
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)