This is a small code generator. The user of this program is a programmer who writes his class in a similar structure time after time. This program is also an example for how to use the code of my article Wrapper class for DOM interface of windows SDK the title of which may be updated later, for its an ambiguous title.
How to compile the project using my wrapper of MS XML parser (IXMLDOMDocument )3.xxx for VC6.0 user
If you want to compile the classes for MS XML 3.x wrapper classes successfully under VC 6, you need the latest version of Microsoft Platform SDK, which can be downloaded from Microsoft’s website. After installing the Platform SDK downloaded from Microsoft, you shall use [tools|options…] to add your include path of Platform SDK in the directory list of VC++. Service pack 5 for Visual C++ is better.
How to generate code
VC++ 6.0 provides a serial class wizard which helps developers to generate the architecture code of MFC, ATL and so on. Microsoft Visual Studio also provides a standard way to write a new class wizard. Here, we demonstrate to implement such a function in XML/XSL. The principle to implement this function is very simple.
The user will input class name, the file name for header and source in the code generation dialog which is the main window of this project. If all information for your new class is inputted, you can push generate button in the dialog. The dialog collects all information of your new class into an XML tree in the memory. And then, calls the method
CCodeGenerater, the new class is generated and saved to files with file names as given by the user.
The key feature of this program is the using of XML/XSL features in MS XML 3.x or 4.0. The principle is in the figure .The parameters can be given from
CGetItemDlg by user. All parameters are packed into an XML tree in memory say
CXMLParameterResult. As you know, the XML is loaded from disk file or string is stored in
IXMLDOMDocument which is wrapped in
CXMLFile. The format of CPP and header files used to generate new classes is located in 2 XSL files.
CcodeGenerater loads all XSL files into memory and calls
TransformNode method of
IXMLDOMDocument to generate new class’ source code which is a string returned by
TransformNode. And then, the
CCodeGenerater writes the result to files according to user specific files.
The UML figure is the basic structure for this program. In the diagram, I omitted the
CWinApp derived files and some utility files.
Note that the source code generated by this tool is an item class for template class
CGroupItems, which is a special version of
CArray with additional features that are used heavily in my program. Most functions in
CGroupItems has the same form of functions in order to accomplish task.
XSL is Extensible Stylesheet Language to interpret XML data. More detail information of XSL can be found in MSDN and www.w3c.org.
Using XML and XSL together, you can find enormous interesting usages. This program is just a small demonstration.
Thanks for a lot of people who have given me suggestions on writing articles in English. I’m not a native speaker and am eager to share my ideas. After I posted several articles to Code Project, some people figured out that my expression was not clear. I have tried to take more time to write good English.
Special thanks to Anthony, he is very kind to render my article, and articulate grammar and technical errors in my article. Thanks .:)