This macro writes a an empty C++ class with:
- a default constructor,
- an unimplemented copy constructor,
- a non virtual destructor,
- and an unimplemented assignment operator.
When you invoke this macro, a user prompt is shown to get the class name and the author's name. Author's name is taken for the documentation header. The class is defined in a classname.h and implemented in classname.cpp. These files are created in the current directory of the DevStudio. The files are not added to the current project intentionally
The .h and the .cpp files contain appropriate preprocessor directives to prevent multiple inclusions of the .h file.
In the header file,
#ifndef _MYCLASS_H_INCLUDED_
#define _MYCLASS_H_INCLUDED_
#endif // _MYCLASS_H_INCLUDED_
And in the .cpp file,
#include "StdAfx.h"
#ifndef _MYCLASS_H_INCLUDED_
#include "MyClass.h"
#endif // _MYCLASS_H_INCLUDED_
Also, it defines pointer types for the defined class. i.e.
typedef CMyClass * LPCMYCLASS;
typedef const MyClass * LPCCMYCLASS;
Below this line is the entire code of the macro.
Function emitDocHeader(aDocFile_inout, bHFile_in, strClassName_in, <BR> strAuthorName_in)
aDocFile_inout.Selection.StartOfDocument
strHeader = Application.ActiveDocument.Selection
If bHFile_in = true Then
defnOrDecl = "definition"
extension = ".h"
Else
defnOrDecl = "implementation"
extension = ".cpp"
End If
strHeader = "/*-----------------------------------------------" +_<BR> "-------------------------------" + vbLf
strHeader = strHeader + Chr(09) + "File name : " +_<BR> strClassName_in + extension + vbLf + vbLf
strHeader = strHeader + Chr(09) + "Author : " +_<BR> strAuthorName_in + vbLf + vbLf
strHeader = strHeader + Chr(09) +_<BR> "Description : This file cotains the " + defnOrDecl +_<BR> " of the class " + strClassName_in + vbLf
strHeader = strHeader+_<BR> "--------------------------------------------------" +_<BR> "----------------------------*/" + vbLf + vbLf + vbLf + vbLf
aDocFile_inout.Selection = strHeader
End Function
Function emitHFileIfDef(aDocFile_inout, strClassName_in)
strIfdefMacro = "_" + Ucase(strClassName_in) + "_H_INCLUDED_"
aDocFile_inout.Selection = "#ifndef " + strIfdefMacro + vbLf +_<BR> "#define " + strIfdefMacro + vbLf
aDocFile_inout.Selection.EndOfDocument
aDocFile_inout.Selection = vbLf + vbLf + vbLf + vbLf +_<BR> "#endif // " + strIfdefMacro + vbLf
emitHFileIfDef = strIfdefMacro
End Function
Function includeHeaderFileInCPP(aDocFile_inout, strIfdefMacro_in,<BR> strHeaderFileName_in)
aDocFile_inout.Selection = vbCrLf + "#include " + Chr(34) +_<BR> "StdAfx.h" + Chr(34) + vbLf + vbLf + vbLf
aDocFile_inout.Selection = "#ifndef " + strIfdefMacro_in + vbLf +_<BR> vbLf
aDocFile_inout.Selection = Chr(09) + "#include " + Chr(34) +_<BR> strHeaderFileName_in + Chr(34) + vbLf + vbLf
aDocFile_inout.Selection = "#endif // " + strIfdefMacro_in +_<BR> vbLf + vbLf + vbLf + vbLf
End Function
Function defineClass(aDocFile_inout, strClassName_in)
aDocFile_inout.Selection.EndOfDocument
aDocFile_inout.Selection.LineUp dsMove, 3
classDefinition = "class " + strClassName_in + vbLf
classDefinition = classDefinition + "{" + vbLf + vbLf
classDefinition = classDefinition + "public: // methods." + vbLf +_<BR> vbLf
classDefinition = classDefinition + Chr(09) + strClassName_in +_<BR> "(); // Default constructor." + vbLf + vbLf
classDefinition = classDefinition + Chr(09) + strClassName_in +_<BR> "(const " + strClassName_in +_<BR> " & rhs_in); // unimplemented copy constructor." + vbLf + vbLf
classDefinition = classDefinition + Chr(09) + "~" + strClassName_in +_<BR> "(); // Destructor." + vbLf + vbLf
classDefinition = classDefinition + Chr(09) + "const " +_<BR> strClassName_in +_<BR> " & operator = (const " + strClassName_in +_<BR> " & rhs_in); // unimplemented assignment operator." +_<BR> vbLf + vbLf + vbLf
classDefinition = classDefinition + "public: // data." + vbLf +_<BR> vbLf + vbLf + vbLf
classDefinition = classDefinition + "protected: // methods." +_<BR> vbLf + vbLf + vbLf
classDefinition = classDefinition + "protected: // data." +_<BR> vbLf + vbLf + vbLf + vbLf
classDefinition = classDefinition + "private: // methods." +_<BR> vbLf + vbLf + vbLf
classDefinition = classDefinition + "private: // data." + vbLf +_<BR> vbLf + vbLf
classDefinition = classDefinition + "};" + vbLf + vbLf + vbLf + vbLf
classDefinition = classDefinition + "typedef " + strClassName_in +_<BR> " * LP" +_<BR> Ucase(strClassName_in) + ";" + vbLf + vbLf
classDefinition = classDefinition + "typedef const " +_<BR> strClassName_in + " * LPC" + Ucase(strClassName_in) +_<BR> ";" + vbLf + vbLf
aDocFile_inout.Selection = classDefinition
End Function
Function implementClass(aDocFile_inout, strClassName_in)
aDocFile_inout.Selection.EndOfDocument
classImpl = strClassName_in + "::" + strClassName_in + "()" + vbLf
classImpl = classImpl + "{" + vbLf
classImpl = classImpl + Chr(09) +_<BR> "// TODO: write your INITIALIZATION code here" + vbLf
classImpl = classImpl + "}" + vbLf + vbLf + vbLf + vbLf + vbLf + vbLf
classImpl = classImpl + strClassName_in + "::~" +_<BR> strClassName_in + "()" + vbLf
classImpl = classImpl + "{" + vbLf
classImpl = classImpl + Chr(09) +_<BR> "// TODO: write your CLEANUP code here" + vbLf
classImpl = classImpl + "}" + vbLf + vbLf + vbLf + vbLf +_<BR> vbLf + vbLf
aDocFile_inout.Selection = classImpl
End Function
Sub writeClass()
Dim headerFileDoc, cppFileDoc
strUserInput = InputBox("Dhandy will write an empty class for you " +_<BR> " in the given classname.h and classname.cpp file in the " +_<BR> "current directory" + vbLf + vbLf +_<BR> "Enter the class' name and the author's name. Put a ^ between " +_<BR> "class name and author's name. Don't worry about the spaces " +_<BR> "around the ^." + vbLf + vbLf + "e.g. CString ^ Shri " +_<BR> "Chullumal Popatmal Khatri, Jhumritaliya, Bharat." + vbLf +_<BR> vbLf + "The class will be 'CString' and Author will be " +_<BR> "'Shri Chullumal Popatmal Khatri, Jhumritaliya, Bharat.'" ,<BR> "Dhandy writes a class for you!")
strUserInput = Trim(strUserInput)
If strUserInput = "" Then
Exit Sub
End If
iCaretPos = Instr(strUserInput, "^")
If(iCaretPos = 0) Then
strClassName = strUserInput
strAuthorName = "_AUTHOR_NAME_"
else
strClassName = Mid(strUserInput, 1, iCaretPos - 1)
strAuthorName = Mid(strUserInput, iCaretPos + 1)
End If
strClassName = Trim(strClassName)
strAuthorName = Trim(strAuthorName)
strHeaderFileName = strClassName + ".h"
Set headerFileDoc = Application.Documents.Add("Text")
headerFileDoc.Save(strHeaderFileName)
emitDocHeader headerFileDoc, true, strClassName, strAuthorName
strIfdefMacro = emitHFileIfDef(headerFileDoc, strClassName)
defineClass headerFileDoc, strClassName
strCppFileName = strClassName +".cpp"
Set cppFileDoc = Application.Documents.Add("Text")
cppFileDoc.Save(strCppFileName)
emitDocHeader cppFileDoc, false, strClassName, strAuthorName
includeHeaderFileInCPP cppFileDoc, strIfdefMacro, strHeaderFileName
implementClass cppFileDoc, strClassName
headerFileDoc.Save
cppFileDoc.Save
headerFileDoc.Active = true
End Sub
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.