- ¼±ÅÃµÈ ¶óÀε鿡¼ Áߺ¹µÈ ¶óÀεéÀº »èÁ¦ÇÏ°í ³ª¸ÓÁö¸¦ Á¤·ÄÇϱâ
- Ȱ¼ºÈµÈ ¾ÆÀÌÅÛ ÃßÀûÇϱâ
- ÁÖ¼® Ä ¸ÂÃß±â
- º¹»ç »ý¼ºÀÚ ¹× ´ëÀÔ ¿¬»êÀÚ ÀÚµ¿À¸·Î »ý¼ºÇϱâ
- ¾Æ¸§´Ù¿î º¯¼ö ¼±¾ð¹® ¸¸µé±â
- ¹®ÀÚ¿ _T() ¸ÅÅ©·Î·Î °¨½Î±â
- ÇöÀç ÆíÁý ÁßÀÎ ¹®¼ ¼Ö·ç¼Ç ÀͽºÇ÷η¯¿¡¼ ã±â
- ¼Ö·ç¼Ç ÀͽºÇ÷η¯ Æ®¸® Á¢±â
- ¼Ò½º ÆÄÀÏ ±âº» ±¸¹® Áý¾î³Ö±â
- ÇÔ¼ö ¼³¸í Áý¾î³Ö±â
- H <-> CPP ÀüȯÇϱâ
- ±×·ì ±¸¹® Áý¾î³Ö±â
- ÀÚµ¿À¸·Î Accessor »ý¼ºÇϱâ
- ¹®ÀÚ¿ °Ë»ö
Visual Studio 2005 ±âÁØ
1 ¼±ÅÃµÈ ¶óÀε鿡¼ Áߺ¹µÈ ¶óÀεéÀº »èÁ¦ÇÏ°í ³ª¸ÓÁö¸¦ Á¤·ÄÇϱâ
include ±¸¹®µéÀ» Á¤¸®Çϱâ À§Çؼ »ç¿ëÇϸé ÁÁ´Ù.
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 SortCollection(ByRef oCollection As Collection, Optional ByVal bSortAscending As Boolean = True)
Dim lSort1 As Integer
Dim lSort2 As Integer
Dim vTempItem1 As Object
Dim vTempItem2 As Object
Dim bSwap As Boolean
For lSort1 = 1 To oCollection.Count - 1
For lSort2 = lSort1 + 1 To oCollection.Count
If bSortAscending Then
If oCollection(lSort1) > oCollection(lSort2) Then
bSwap = True
Else
bSwap = False
End If
Else
If oCollection(lSort1) < oCollection(lSort2) Then
bSwap = True
Else
bSwap = False
End If
End If
If bSwap Then
vTempItem1 = oCollection(lSort1)
vTempItem2 = oCollection(lSort2)
oCollection.Add(vTempItem1, Nothing, lSort2)
oCollection.Add(vTempItem2, Nothing, lSort1)
oCollection.Remove(lSort1 + 1)
oCollection.Remove(lSort2 + 1)
End If
Next
Next
End Sub
Sub SortAndRemoveDuplicatedLine()
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 objStream As New StringBuilder
For Each strLine In objSel.Text.Split(Lf)
strLine = Strip(strLine)
If objLines.Contains(strLine) = False Then
objLines.Add(strLine, strLine)
End If
Next
SortCollection(objLines)
For Each strLine In objLines
objStream.AppendLine(strLine)
Next
objSel.Text = ""
objStartPt.Insert(objStream.ToString())
End Sub
2 Ȱ¼ºÈµÈ ¾ÆÀÌÅÛ ÃßÀûÇϱâ
"µµ±¸ -> ¿É¼Ç -> ÇÁ·ÎÁ§Æ® ¹× ¼Ö·ç¼Ç -> ÀÏ¹Ý -> ¼Ö·ç¼Ç Ž»ö±â¿¡¼ Ȱ¼ºÈµÈ Ç׸ñ ÃßÀû" ¿É¼ÇÀ» Äѵθé ÇöÀç ÆíÁý ÁßÀÎ ÆÄÀÏÀ» ¼Ö·ç¼Ç Ž»ö±â¿¡¼ ½±°Ô ã¾Æº¼ ¼ö ÀÖ´Ù. ¹®Á¦´Â ÀÌ ¿É¼ÇÀ» Ç×»ó ÄÑµÎ¸é »ó´çÈ÷ ³ÀâÇÏ´Ù´Â Á¡ÀÌ´Ù. ±×·¯¹Ç·Î ÀÌ ¿É¼Ç ÀÚü´Â ²ô°í, ¸ÅÅ©·Î¸¦ ÅëÇØ ÇÊ¿äÇÒ ¶§¸¸ ÃßÀûÇϵµ·Ï ÇØµÎ´Â °ÍÀÌ ÁÁ´Ù.
Sub FindInSolution()
' ÇöÀç ÆíÁý ÁßÀÎ ÆÄÀÏÀ» ¼Ö·ç¼Ç ÀͽºÇ÷η¯¿¡¼ ã¾Æ¼ ÇÏÀ̶óÀÌÆ®½ÃŲ´Ù.
p = DTE.Properties("Environment", "ProjectsAndSolution").Item("TrackFileSelectionInExplorer")
p.value = 1
p.value = 0
End Sub ´ÜÃà۸¦ µî·ÏÇØµÎ´Â °ÍÀÌ ÁÁ´Ù. ALT+Q Ãßõ
3 ÁÖ¼® Ä ¸ÂÃß±â
DoxyGen ÇüÅÂÀÇ ÁÖ¼®À» Ä÷³¿¡ ¸Â°Ô ¿öµå·¦ÇØÁÖ´Â ¸ÅÅ©·Î´Ù. ¾à°£ ¼öÁ¤Çϸé ÀÏ¹Ý ÁÖ¼®¿¡ ¾µ ¼öµµ ÀÖÀ» ÅÍ.
Before
//////////////////////////////////////////////////////////////////////////////////////////
/// \brief ±ÛÀÚ°¡
/// óÀ½À¸·Î
/// ³ªÅ¸³ª´Â À§Ä¡¸¦
/// ¹ÝȯÇÑ´Ù.
/// \param caseSensitive ´ë¼Ò¹®ÀÚ ±¸º°À» Çϴ°¡?
/// \return size_t À½ À̰ÍÀº ±×³É ºÙ¿©º¸´Â ÁÖ¼®À̶õ´Ù.
//////////////////////////////////////////////////////////////////////////////////////////
After
//////////////////////////////////////////////////////////////////////////////////////////
/// \brief ±ÛÀÚ°¡ óÀ½À¸·Î ³ªÅ¸³ª´Â À§Ä¡¸¦ ¹ÝȯÇÑ´Ù.
/// \param text °Ë»ö ´ë»ó ¹®ÀÚ¿
/// \return size_t À½ À̰ÍÀº ±×³É ºÙ¿©º¸´Â ÁÖ¼®À̶õ´Ù.
//////////////////////////////////////////////////////////////////////////////////////////
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
Function GetAsciiLength(ByVal str As String)
Return Encoding.Default.GetBytes(str).Length
End Function
Sub WrapDoxygenComment()
Dim nMaxLength As Integer = 90 - 4 - 1 ' -4´Â ÁÖ¼® ¾Õ¿¡ ºÙ´Â "/// " ¹®ÀÚ¿ÀÇ ±æÀÌ, -1Àº µü ºÙ¾îÀÖ´Â °Å ÂóÂóÇØ¼
Dim nLineLength As Integer = 0
Dim objRegex As RegularExpressions.Regex
Dim objMatch As RegularExpressions.Match
Dim objStream As New 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 strLine In objSel.Text.Split(CrLf)
strLine = Strip(strLine)
If objRegex.IsMatch(strLine, "^////+$") Then
Else
objMatch = objRegex.Match(strLine, "^///")
If objMatch.Success Then
strLine = Strip(strLine.SubString(objMatch.Length))
End If
End If
objLines.Add(strLine)
Next
For i = 1 To objLines.Count
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 RegularExpressions.Match In 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
4 º¹»ç »ý¼ºÀÚ ¹× ´ëÀÔ ¿¬»êÀÚ ÀÚµ¿À¸·Î »ý¼ºÇϱâ
Sub MakeCopyAndAssignment()
Dim objSel As TextSelection
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
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
strFileName = ActiveDocument().Name
If strFileName = "" Then
MsgBox("ó¸® ÁßÀÎ ÆÄÀÏ¿¡ È®ÀåÀÚ°¡ ¾ø½À´Ï´Ù." + CrLf + "C/C++ ¼Ò½º ÆÄÀÏÀÌ ¸Â½À´Ï±î?")
Exit Sub
End If
' ÆÄÀÏ À̸§À¸·Î Ŭ·¡½º À̸§À» ÃßÁ¤ÇÑ´Ù.
strClassName = "c" + Left(strFileName, InStrRev(strFileName, ".") - 1)
' ½ÇÁ¦ Ŭ·¡½º À̸§À» ÀԷ¹޴´Ù.
strClassName = InputBox("Type class name", "Class name required", strClassName)
If Len(strClassName) > 0 Then
objSel = ActiveDocument().Selection
objRanges = objSel.TextRanges
objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
' º¯¼ö ÆÄ½Ì
ParseVariableDeclarations(Trim(objSel.Text), colTypes, colNames, colComments)
' º¹»ç »ý¼ºÀÚ
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 + Tab + "}" + CrLf + CrLf)
' »ý¼ºÇÑ ¹®ÀÚ¿ ´ëÀÔ
objSel.Text = ""
objStartPt.Insert(objStream.ToString())
End If
End Sub
5 ¾Æ¸§´Ù¿î º¯¼ö ¼±¾ð¹® ¸¸µé±â
Sub MakePrettyVariableDeclaration()
Dim objSel As TextSelection
Dim objRanges As TextRanges
Dim objStartPt As EditPoint
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim nMaxTypeLength As Integer
Dim nMaxNameLength As Integer
Dim objStream As New System.Text.StringBuilder
objSel = ActiveDocument().Selection
objRanges = objSel.TextRanges
objStartPt = objRanges.Item(1).StartPoint.CreateEditPoint()
ParseVariableDeclarations(Trim(objSel.Text), colTypes, colNames, colComments)
nMaxTypeLength = 0
For Each line In colTypes
nMaxTypeLength = System.Math.Max(nMaxTypeLength, Len(line))
Next
nMaxNameLength = 0
For Each line In colNames
nMaxNameLength = System.Math.Max(nMaxNameLength, Len(line))
Next
For i = 1 To colTypes.Count
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(Trim(line) + CStr(Lf))
Next
objStartPt.Delete(objSel.Text.Length)
objStartPt.Insert(objStream.ToString())
End Sub
6 ¹®ÀÚ¿ _T() ¸ÅÅ©·Î·Î °¨½Î±â
¹®ÀÚ¿À» ¼±ÅÃÇÒ ÇÊ¿ä ¾øÀÌ ¹®ÀÚ¿ °¡¿îµ¥¿¡¼, ±×³É ¸ÅÅ©·Î¸¦ ½ÇÇàÇÏ¸é µÈ´Ù. ¹®ÀÚ¿À» ¼±ÅÃÇÑ »óÅ¿¡¼ »ç¿ëÇØµµ µ¿ÀÛ¿¡´Â º° Â÷À̰¡ ¾ø´Ù. ´ÜÃàŰ´Â Ctrl+K, Ctrl+T Ãßõ.
Sub WrapStringWithTcharMacro()
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)
' ÀÌ¹Ì _T ¸ÅÅ©·Î·Î °¨½Î¿© ÀÖ´Â ¹®ÀÚ¿ÀÌ ¾Æ´Ï¶ó¸é °¨½ÎÁØ´Ù.
If objStartPt.GetText(-3) <> "_T(" Then
objStartPt.Insert("_T(")
objEndPt.Insert(")")
End If
End Sub
7 ÇöÀç ÆíÁý ÁßÀÎ ¹®¼ ¼Ö·ç¼Ç ÀͽºÇ÷η¯¿¡¼ ã±â
Sub FindInSolution()
p = DTE.Properties("Environment", "ProjectsAndSolution").Item("TrackFileSelectionInExplorer")
p.value = 1
p.value = 0
End Sub
8 ¼Ö·ç¼Ç ÀͽºÇ÷η¯ Æ®¸® Á¢±â
Sub CollapseNode(ByRef item As UIHierarchyItem)
Dim subitem As UIHierarchyItem
For Each subitem In item.UIHierarchyItems
If (subitem.UIHierarchyItems.Expanded = True) Then
CollapseNode(subitem)
subitem.UIHierarchyItems.Expanded = False
End If
Next
End Sub
Sub CollapseAll()
' Get the the Solution Explorer tree
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item(EnvDTE.Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (UIHSolutionExplorer.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 = UIHSolutionExplorer.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
9 ¼Ò½º ÆÄÀÏ ±âº» ±¸¹® Áý¾î³Ö±â
»õ·Î¿î Çì´õ/¼Ò½º ÆÄÀÏ¿¡´Ù ±âº» ±¸¹® Áý¾î³Ö±â
Sub DecorateSourceFile()
' ¼³¸í: doxygen ½ºÅ¸ÀÏÀÇ ÆÄÀÏ ¼³¸í°ú Ŭ·¡½º ¼±¾ðÀ» Çì´õ/¼Ò½º ÆÄÀÏ¿¡´Ù Ãß°¡ÇÑ´Ù.
Dim fileName As String
Dim fileExt As String
Dim includeGuard As String
Dim selection As TextSelection
Dim pos As Integer
Dim className As String
Dim author As String
Dim dateString As String
Dim commentLine As String
Dim usePragmaOnce As Boolean
Dim classNamePrefix As String
Dim pchName As String
' ¼öÁ¤ »çÇ×µé. Çʿ信 µû¶ó ¼öÁ¤ÇÑ´Ù.
author = "excel96"
dateString = CStr(Year(Now())) + "." + CStr(Month(Now())) + "." + CStr(Day(Now()))
commentLine = "////////////////////////////////////////////////////////////////////////////////"
usePragmaOnce = True
classNamePrefix = "c"
pchName = "PCH.h"
' ÆÄÀÏ À̸§À» È®ÀÎÇÑ´Ù.
fileName = ActiveDocument().Name
If fileName = "" Then
If MsgBox("ó¸® ÁßÀÎ ÆÄÀÏ¿¡ È®ÀåÀÚ°¡ ¾ø½À´Ï´Ù." + Lf + _
"C/C++ ¼Ò½º ÆÄÀÏÀÌ ¸Â½À´Ï±î?", 4) = MsgBoxResult.Cancel Then
Exit Sub
End If
fileName = "NoFileNameGiven.h"
End If
' ÆÄÀÏ À̸§À» ºÐ¸®Çϰí, Ŭ·¡½º À̸§À» »ý¼ºÇÑ´Ù.
fileExt = UCase(Right(fileName, Len(fileName) - InStrRev(fileName, ".")))
fileName = Left(fileName, Len(fileName) - Len(fileExt) - 1)
className = classNamePrefix + fileName
' ÆÄÀÏÀÇ È®ÀåÀÚ¿¡ µû¶ó ¾Ë¸ÂÀº 󸮸¦ ÇØÁØ´Ù.
If fileExt = "H" Or fileExt = "HPP" Then
ActiveDocument().Selection.StartOfDocument(False)
selection = ActiveDocument().Selection
includeGuard = "__" + UCase(fileName) + "_" + fileExt + "__" + Lf
' ÆÄÀÏ Çì´õ Ãß°¡.
selection.Text = commentLine + CStr(Lf)
selection.Text += "/// \file " + ActiveDocument().Name + CStr(Lf)
selection.Text += "/// \author " + author + CStr(Lf)
selection.Text += "/// \date " + dateString + CStr(Lf)
selection.Text += commentLine + CStr(Lf) + CStr(Lf)
' ÀÎŬ·çµå °¡µå Ãß°¡.
If usePragmaOnce Then
selection.Text += "#pragma once" + CStr(Lf) + CStr(Lf)
Else
selection.Text += "#ifndef " + includeGuard + "#define " + includeGuard + CStr(Lf) + CStr(Lf)
End If
' Ŭ·¡½º ¼³¸í¹® Ãß°¡.
selection.Text += commentLine + CStr(Lf)
selection.Text += "/// \class " + className + CStr(Lf)
selection.Text += "/// \brief " + CStr(Lf)
selection.Text += commentLine + CStr(Lf) + CStr(Lf)
' Ŭ·¡¼ ¼±¾ð ¹× »ý¼ºÀÚ & ¼Ò¸êÀÚ Ãß°¡.
selection.Text += "class " + className + CStr(Lf)
selection.Text += "{" + CStr(Lf)
selection.Text += "private:" + CStr(Lf) + CStr(Lf)
selection.Text += "public:" + CStr(Lf)
selection.Text += "/// \brief »ý¼ºÀÚ" + CStr(Lf)
selection.Text += className + "();" + CStr(Lf) + CStr(Lf)
selection.Text += "/// \brief ¼Ò¸êÀÚ" + CStr(Lf)
selection.Text += "virtual ~" + className + "();" + CStr(Lf) + CStr(Lf) + CStr(Lf)
selection.Text += "public:" + CStr(Lf) + CStr(Lf)
selection.Text += "};" + CStr(Lf)
' ÀÎŬ·çµå °¡µå ¸¶¹«¸®.
If Not usePragmaOnce Then
ActiveDocument().Selection.EndOfDocument(False)
selection.Text = CStr(Lf) + "#endif //" + includeGuard
End If
ElseIf fileExt = "C" Or fileExt = "CPP" Or fileExt = "CC" Then
ActiveDocument().Selection.StartOfDocument(False)
selection = ActiveDocument().Selection
' ÆÄÀÏ Çì´õ Ãß°¡.
selection.Text = commentLine + CStr(Lf)
selection.Text += "/// \file " + ActiveDocument().Name + CStr(Lf)
selection.Text += "/// \author " + author + CStr(Lf)
selection.Text += "/// \date " + dateString + CStr(Lf)
selection.Text += commentLine + CStr(Lf) + CStr(Lf)
' ÀÎŬ·çµå ÆÄÀÏ Ãß°¡.
selection.Text += "#include " + CStr(Quote) + pchName + CStr(Quote) + CStr(Lf)
selection.Text += "#include " + CStr(Quote) + fileName + ".h" + CStr(Quote) + CStr(Lf)
selection.Text += CStr(Lf)
' »ý¼ºÀÚ Ãß°¡.
selection.Text += commentLine + CStr(Lf)
selection.Text += "/// \brief »ý¼ºÀÚ" + CStr(Lf)
selection.Text += commentLine + CStr(Lf)
selection.Text += className + "::" + className + "()" + CStr(Lf)
selection.Text += "{" + CStr(Lf)
selection.Text += "}" + CStr(Lf) + CStr(Lf)
' ¼Ò¸êÀÚ Ãß°¡.
selection.Text += commentLine + CStr(Lf)
selection.Text += "/// \brief ¼Ò¸êÀÚ" + CStr(Lf)
selection.Text += commentLine + CStr(Lf)
selection.Text += className + "::~" + className + "()" + CStr(Lf)
selection.Text += "{" + CStr(Lf)
selection.Text += "}" + CStr(Lf) + CStr(Lf)
ActiveDocument().Selection.EndOfDocument(False)
Else
MsgBox("ÀÌ ¸ÅÅ©·Î´Â C/C++ ¼Ò½º ÆÄÀÏ¿¡¼¸¸ µ¿ÀÛÇÕ´Ï´Ù.")
End If
End Sub
10 ÇÔ¼ö ¼³¸í Áý¾î³Ö±â
Sub AddFunctionDescriptionEx()
' ¼³¸í: doxygen ½ºÅ¸ÀÏÀÇ ÇÔ¼ö ¼³¸í¹®À» Ãß°¡ÇÑ´Ù.
Dim header, prms As String
Dim functionName, description As String
Dim iPrm, iPrmA As Integer
Dim selection As TextSelection
Dim returnType As String
Dim commentLine As String
Dim p, l As Integer
If (ActiveDocument() Is Nothing) Then
Exit Sub
End If
commentLine = "////////////////////////////////////////////////////////////////////////////////"
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
returnType = Left(header, Loc1 - 1)
header = Right(header, Len(header) - Reti)
End If
returnType = Left(returnType, InStr(returnType, " "))
'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 ')'
functionName = Left(header, Loc1)
header = Right(header, Len(header) - Len(functionName))
'Do we have storage type on the return type?
Trim(functionName)
If InStr(functionName, " ") <> 0 Then
returnType = returnType + Left(functionName, InStr(functionName, " "))
functionName = Right(functionName, Len(functionName) - InStr(functionName, " "))
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
p = iPrm - 1
l = Len(ParamArr(p))
ParamArr(p) = Right(ParamArr(p), (l - (l - (l - InStr(ParamArr(p), " (")))))
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
description = commentLine + CStr(Lf)
description += "/// \brief " + CStr(Lf)
If (iPrmA <> 0) Then
description += "/// " + 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))))))
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
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 = Trim(Right(ParamArr(iPrmA - 1), Len(ParamArr(iPrmA - 1)) - RealIndex))
If (Len(RealParam) > 0 And InStr(RealParam, "void") = 0) Then
description = description + "/// \param " + RealParam + " " + CStr(Lf)
End If
iPrmA = iPrmA - 1
Loop
returnType = Trim(returnType)
If (Len(returnType) > 0 And InStr(returnType, "void") = 0) Then
description += "/// \return " + returnType + CStr(Lf)
End If
description += commentLine + CStr(Lf)
selection = DTE.ActiveDocument.Selection()
selection.Text = description
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
11 H <-> CPP ÀüȯÇϱâ
'DESCRIPTION: Opens the corresponding .h / .cpp file
Sub GetFriendFile()
currentFileName = Application.ActiveDocument.FullName
newFileName = ""
If (UCase(Right(currentFileName, 2)) = ".H") Then
newFileName = Left(currentFileName, Len(currentFileName) - 2) + ".CPP"
ElseIf (UCase(Right(currentFileName, 4)) = ".CPP") Then
newFileName = Left(currentFileName, Len(currentFileName) - 4) + ".H"
End If
On Error Resume Next
If newFileName <> "" Then
Application.Documents.Open(newFileName)
If (Err.Number <> 0) Then
MsgBox("Error opening corresponding file - " & Err.Description)
End If
End If
End Sub
12 ±×·ì ±¸¹® Áý¾î³Ö±â
Sub AddMemberGroupDescription()
'DESCRIPTION: Adds memver group description template for doxygen.
Dim selection As TextSelection
selection = ActiveDocument().Selection
selection.Text = selection.Text + "/// \name " + CStr(Lf)
selection.Text = selection.Text + "/// \{ " + CStr(Lf)
selection.Text = selection.Text + "/// \brief " + CStr(Lf)
selection.Text = selection.Text + "/// \} " + CStr(Lf)
End Sub
13 ÀÚµ¿À¸·Î Accessor »ý¼ºÇϱâ
Getter/Setter ÀÚµ¿À¸·Î »ý¼ºÇϱâ
Function ParseVariableDeclarations( _
ByVal strText As String, ByRef colTypes As Collection, ByRef colNames As Collection, ByRef colComments As Collection)
' ´ÙÀ½°ú °°Àº ÇüÅÂÀÇ ±¸¹®À» Àоîµé¿©¼ ŸÀÔ°ú º¯¼ö À̸§ÀÇ ¹è¿À» »ý¼ºÇÑ´Ù.
'
' SkillId_t m_SkillId; ///< ½ºÅ³ÀÇ Á¾·ù.
' cTraitDataEx m_CasterData; ///< ½ºÅ³·Î ÀÎÇØ º¯ÇÑ ½ÃÀüÀÚÀÇ ÆÄ¶ó¹ÌÅÍ.
' ObjectId_t m_PrimaryTarget; ///< ÁÖ ´ë»óÀÇ OID.
'
' types[1] = "SkillId_t", names[1] = "m_SkillId"
' types[2] = "cTraitDataEx", names[2] = "m_CasterData"
' types[3] = "ObjectId_t", names[3] = "m_PrimaryTarget"
arrLines = strText.Split(Lf)
For Each line In arrLines
strLine = line
' ÁÂ¿ì °ø¹é Á¦°Å
strLine = Trim(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
' ¶óÀÎ Á¦ÀÏ Ã³À½ ³ª¿À´Â ';' ±ÛÀÚ¿Í ';' ±ÛÀÚ ¾Õ¿¡¼ Á¦ÀÏ Ã³À½ ³ªÅ¸³ª´Â ' ' ±ÛÀÚ¸¦ ã´Â´Ù.
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 = Trim(Mid(strLine, 1, nSpacePos))
strVarName = Trim(Mid(strLine, nSpacePos, nSemicolonPos - nSpacePos))
strVarComment = ""
If nSemicolonPos <> 0 Then
strVarComment = Trim(Mid(strLine, nSemicolonPos + 1, Len(strLine) - nSemicolonPos))
End If
strVarType = Trim(Replace(strVarType, vbTab, " "))
strVarName = Trim(Replace(strVarName, vbTab, " "))
strVarComment = Trim(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 GenerateAccessor(ByVal strVarType As String, ByVal strVarName As String, ByVal strMode As String)
Dim strResult As String
If strVarType <> "" And strVarName <> "" Then
Dim objRegex As New System.Text.RegularExpressions.Regex("")
Dim colBasicTypes As New System.Collections.Generic.Dictionary(Of String, String)
Dim objStream As New System.Text.StringBuilder
' ´ë¹®Àڷθ¸ ÀÌ·ç¾îÁ³Áö¸¸, ±¸Á¶Ã¼·Î Ãë±ÞÇÏÁö ¾ÊÀ» ŸÀÔµé »ý¼º
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", "")
' Çʵå À̸§ »ý¼º
Dim strFieldName As String
strFieldName = strVarName
If Left(strFieldName, 2) = "m_" 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
' PODÀÎÁö ¾Æ´ÑÁö üũ
Dim bComplexType = False
If objRegex.IsMatch(strVarType, "^c[A-Z][A-Za-z0-9]+[^\*\&]$") Then
' cDateTime, cTokenizer
bComplexType = True
ElseIf objRegex.IsMatch(strVarType, "^[A-Z0-9_]+[^\*\&]$") And Not colBasicTypes.ContainsKey(strVarType) Then
' D3DXVECTOR, OVERLAPPED
bComplexType = True
ElseIf objRegex.IsMatch(strVarType, "^.+<.+>$") Then
' std::vector<int>, cMyTemplate<bool>
bComplexType = True
End If
' ¸î °¡Áö ŸÀÔÀº µû·Î ó¸®
If strVarType = "std::string" Then strVarType = "const std::string&"
If strVarType = "tstring" Then strVarType = "const tstring&"
' Getter? Setter?
If strMode = "Getter" Then
If bComplexType Then
strResult += strVarType + "& Get" + strFieldName + "() { return " + strVarName + "; }" + CStr(Lf)
strResult += "const " + strVarType + "& Get" + strFieldName + "() const { return " + strVarName + "; }" + CStr(Lf)
ElseIf strVarType = "bool" Or strVarType = "BOOL" Then
strResult += strVarType + " Is" + strFieldName + "() const { return " + strVarName + "; }" + CStr(Lf)
Else
strResult += strVarType + " Get" + strFieldName + "() const { return " + strVarName + "; }" + CStr(Lf)
End If
Else
If bComplexType Then
strResult += "void Set" + strFieldName + "(const " + strVarType + "& value) { " + strVarName + " = value; }" + CStr(Lf) + CStr(Lf)
ElseIf strVarType = "bool" Or strVarType = "BOOL" Then
strResult += "void Set" + strFieldName + "(" + strVarType + " value) { " + strVarName + " = value; }" + CStr(Lf) + CStr(Lf)
Else
strResult += "void Set" + strFieldName + "(" + strVarType + " value) { " + strVarName + " = value; }" + CStr(Lf) + CStr(Lf)
End If
End If
End If
Return strResult
End Function
Sub MakeSimpleGetterSetter()
Dim objSel As TextSelection
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim objStream As New System.Text.StringBuilder
objSel = ActiveDocument().Selection
ParseVariableDeclarations(Trim(objSel.Text), 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"))
Next
objSel.Text = objStream.ToString()
End Sub
¾Æ·¡´Â ÇöÀç ÇÁ·ÎÁ§Æ®¿¡¼ ÆÐŶ ±¸ÇöÀ» ½±°Ô Çϱâ À§ÇØ »ç¿ëÇÏ´Â ¸ÅÅ©·Î.
Sub MakePacketInterface()
Dim colTypes As New Collection
Dim colNames As New Collection
Dim colComments As New Collection
Dim nCount As Integer
Dim objStream As New System.Text.StringBuilder
ParseVariableDeclarations(Trim(ActiveDocument().Selection.Text), colTypes, colNames, colComments)
'------------------------------------------------------------------------------------------
objStream.Append("public:" + CStr(Lf))
objStream.Append("/// \brief ÆÐŶÀÇ ½ÇÁ¦ ±æÀ̸¦ ¹ÝȯÇÑ´Ù." + CStr(Lf))
objStream.Append("virtual PacketSize_t GetSize() const" + CStr(Lf))
objStream.Append("{" + CStr(Lf))
If colNames.Count = 1 Then
If colNames.Item(1) <> "" Then
objStream.Append("return bytes(" + colNames.Item(1) + ");" + CStr(Lf))
End If
Else
nCount = 1
For Each strLine In colNames
If strLine <> "" Then
If nCount = 1 Then
objStream.Append("return bytes(" + strLine + ") +" + CStr(Lf))
ElseIf nCount = colNames.Count Then
objStream.Append("bytes(" + strLine + ");" + CStr(Lf))
Else
objStream.Append("bytes(" + strLine + ") +" + CStr(Lf))
End If
End If
nCount = nCount + 1
Next
End If
objStream.Append("}" + CStr(Lf) + CStr(Lf))
'------------------------------------------------------------------------------------------
objStream.Append("/// \brief ÆÐŶÀÇ ÃÖ´ë ±æÀ̸¦ ¹ÝȯÇÑ´Ù." + CStr(Lf))
objStream.Append("virtual PacketSize_t GetMaxSize() const" + CStr(Lf))
objStream.Append("{" + CStr(Lf))
If colNames.Count = 1 Then
If colNames.Item(1) <> "" Then
objStream.Append("return max_bytes(" + colNames.Item(1) + ");" + CStr(Lf))
End If
Else
nCount = 1
For Each strLine In colNames
If strLine <> "" Then
If nCount = 1 Then
objStream.Append("return max_bytes(" + strLine + ") +" + CStr(Lf))
ElseIf nCount = colNames.Count Then
objStream.Append("max_bytes(" + strLine + ");" + CStr(Lf))
Else
objStream.Append("max_bytes(" + strLine + ") +" + CStr(Lf))
End If
End If
nCount = nCount + 1
Next
End If
objStream.Append("}" + CStr(Lf) + CStr(Lf))
'------------------------------------------------------------------------------------------
objStream.Append("/// \brief ÆÐŶ ³»ºÎ µ¥ÀÌÅ͸¦ Á÷·ÄÈÇÏ¿© ¹ÙÀÌÆ® ¹öÆÛ¿¡´Ù ¾´´Ù." + CStr(Lf))
objStream.Append("virtual PacketSize_t Marshall(cSocketStream& oBuffer) const" + CStr(Lf))
objStream.Append("{" + CStr(Lf))
objStream.Append("PacketSize_t count = 0;" + CStr(Lf))
For Each strLine In colNames
If strLine <> "" Then
objStream.Append("count += oBuffer.Write(" + strLine + ");" + CStr(Lf))
End If
Next
objStream.Append("return count; " + CStr(Lf))
objStream.Append("}" + CStr(Lf) + CStr(Lf))
'------------------------------------------------------------------------------------------
objStream.Append("/// \brief ¹ÙÀÌÆ® ¹öÆÛ¿¡¼ µ¥ÀÌÅ͸¦ Àоîµé¿© ÆÐŶ °´Ã¼¸¦ ±¸¼ºÇÑ´Ù." + CStr(Lf))
objStream.Append("virtual PacketSize_t Unmarshall(cSocketStream& iBuffer)" + CStr(Lf))
objStream.Append("{" + CStr(Lf))
objStream.Append("PacketSize_t count = 0;" + CStr(Lf))
For Each strLine In colNames
If strLine <> "" Then
objStream.Append("count += iBuffer.Read(" + strLine + ");" + CStr(Lf))
End If
Next
objStream.Append("return count; " + CStr(Lf))
objStream.Append("}" + CStr(Lf) + CStr(Lf) + CStr(Lf))
'------------------------------------------------------------------------------------------
objStream.Append("public:" + CStr(Lf))
objStream.Append("/// \name Simple getter/setter" + CStr(Lf))
objStream.Append("/// \{" + CStr(Lf))
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"))
Next
objStream.Append("/// \}" + CStr(Lf) + CStr(Lf))
'------------------------------------------------------------------------------------------
ActiveDocument().Selection.Text = objStream.ToString()
End Sub
14 ¹®ÀÚ¿ °Ë»ö
Sub QuickFind()
' ÇöÀç ¼±ÅÃµÈ ´Ü¾î°¡ ÀÖ´Ù¸é ´ÙÀ½¿¡ ÀÖ´Â ÇØ´ç ´Ü¾î¸¦ ã°í,
' ¼±ÅÃµÈ ´Ü¾î°¡ ¾ø´Ù¸é ã±â ´ëÈâÀ» ¶ç¿î´Ù.
Dim doc
doc = ActiveDocument()
If doc Is Nothing Then
Exit Sub
ElseIf doc.Type <> "Text" Then
Exit Sub
End If
lookFor = doc.Selection.Text
curLine = doc.Selection.CurrentLine
curCol = doc.Selection.CurrentColumn
If Len(lookFor) = 0 Then
ExecuteCommand("Edit.FindNext")
If Len(doc.Selection.Text) = 0 Then
ExecuteCommand("Edit.Find")
End If
Else
doc.Selection.Cancel()
doc.Selection.MoveTo(curLine, curCol)
doc.Selection.FindText(lookFor)
End If
End Sub
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)