Click here to Skip to main content
Click here to Skip to main content
Go to top

A simple C++ code generator (Sample Usage of my XML Wrapper class)

, 14 May 2003
Rate this:
Please Sign up or sign in to vote.
Generate C++ classes using XML & XSL

Sample Image - result.jpg

Introduction

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.

theory

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 Generate of 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.

UML diagram

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.

About XSL

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.

Acknowledgements

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 .Smile | :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Johnson Zhou
Software Developer (Senior)
China China
I'm write program from 1990. My research field is CAG,CAD and Image processing. I select C/C++, ASP, Java, XML as my usaully developing tools. Occasional , write code in Delphi and VB. I'm using Visual C++ from 1996. If you have anything unclear, e-mail to :zhou_cn123@sina.com Software Engineering and CAD is my mainly research program.
 
You also can reach me on msn: zhoujohnson@hotmail.com

Comments and Discussions

 
GeneralI wrote a similar c++ code generator, but it's for command line. Pinmemberjfwan15-Jan-07 19:40 
GeneralRe: I wrote a similar c++ code generator, but it's for command line. Pinmemberxszxcvbnm15-Jul-09 1:52 
Generalthe xml.lib PinmemberPascal Levieux19-May-04 3:05 
GeneralRe: the xml.lib Pinmembersurojitmukerji29-Jan-06 0:30 
GeneralRe: the xml.lib PinmemberRachana Agrawal20-Aug-06 21:14 
Generalsuggestion PinmemberYDLU5-Feb-04 6:35 
GeneralRe: suggestion PinmemberYDLU5-Feb-04 9:37 
QuestionWhere is the project file? Pinmemberstempsoft30-Nov-03 13:37 
GeneralWhere is 'xml_inc.h' PinmemberWolfgang Kleinschmit20-May-03 21:40 
GeneralRe: Where is 'xml_inc.h' PinmemberJohnson Zhou21-May-03 2:08 
GeneralRe: Where is 'mis_xml_inc.h' ? Pinmemberhaipengl2-Jun-04 6:51 
GeneralSmall suggestions PinmemberJonathan de Halleux15-May-03 21:25 
GeneralRe: Small suggestions PinmemberSaurweinAndreas16-May-03 5:47 
GeneralRe: Small suggestions PinmemberShmulik Flint19-May-03 18:20 
GeneralRe: Small suggestions PinmemberJohnson Zhou16-May-03 20:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 15 May 2003
Article Copyright 2003 by Johnson Zhou
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid