[译]一个简单的C ++代码生成器(我的XML Wrapper类的示例用法)
By robot-v1.0
本文链接 https://www.kyfws.com/applications/a-simple-c-code-generator-sample-usage-of-my-xml-w-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2071 个词 阅读量 0[译]一个简单的C ++代码生成器(我的XML Wrapper类的示例用法)
原文地址:https://www.codeproject.com/Articles/4136/A-simple-C-code-generator-Sample-Usage-of-my-XML-W
原文作者:Johnson Zhou
译文由本站 robot-v1.0 翻译
前言
Generate C++ classes using XML & XSL
使用XML和XSL生成C ++类
介绍(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) Windows SDK DOM接口的包装器类(Wrapper class for DOM interface of windows SDK) 标题可能会稍后更新,因为其标题含糊不清.(the title of which may be updated later, for its an ambiguous title.)
如何为VC6.0用户使用我的MS XML解析器包装(IXMLDOMDocument)3.xxx编译项目(How to compile the project using my wrapper of MS XML parser (IXMLDOMDocument )3.xxx for VC6.0 user)
如果要在VC 6下成功编译MS XML 3.x包装器类的类,则需要可从Microsoft网站下载的最新版本的Microsoft Platform SDK.安装从Microsoft下载的Platform SDK后,您应使用[(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)…]在VC ++的目录列表中添加Platform SDK的包含路径. Visual C ++的Service Pack 5更好.(…] 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提供了一个串行类向导,可帮助开发人员生成MFC,ATL等的体系结构代码. Microsoft Visual Studio还提供了编写新类向导的标准方法.在这里,我们演示了如何在XML/XSL中实现这样的功能.实现此功能的原理非常简单.(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.)
用户将在该项目的主窗口代码生成对话框中输入类名称,标头和源文件名.如果输入了新班级的所有信息,则可以在对话框中按"生成"按钮.该对话框将新类的所有信息收集到内存中的XML树中.然后,调用方法(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.)
该程序的关键功能是在MS XML 3.x或4.0中使用XML/XSL功能.原理如图所示,参数可以从(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
按用户.所有参数都打包到内存中的XML树中,例如(by user. All parameters are packed into an XML tree in memory say) CXMLParameterResult
.如您所知,XML是从磁盘文件加载的,或者字符串存储在(. As you know, the XML is loaded from disk file or string is stored in) IXMLDOMDocument
包裹在(which is wrapped in) CXMLFile
.用于生成新类的CPP和头文件的格式位于2个XSL文件中.(. The format of CPP and header files used to generate new classes is located in 2 XSL files.) CcodeGenerater
将所有XSL文件加载到内存并调用(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图是该程序的基本结构.在图中,我省略了(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(About XSL)
XSL是可扩展样式表语言,用于解释XML数据.有关XSL的更多详细信息,请参见MSDN和(XSL is Extensible Stylesheet Language to interpret XML data. More detail information of XSL can be found in MSDN and) www.w3c.org(www.w3c.org) .(.)
一起使用XML和XSL,您会发现很多有趣的用法.该程序只是一个小示范.(Using XML and XSL together, you can find enormous interesting usages. This program is just a small demonstration.)
致谢(Acknowledgements)
感谢许多为我提供英文写作文章建议的人.我不是母语人士,渴望分享我的想法.在我向Code Project发布几篇文章之后,有人发现我的表达不清楚.我试图花更多时间写好英语.(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 .:))
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 C++ VC6 WinXP Windows Win2K MFC Visual-Studio Dev 新闻 翻译