汽车类发生器 [英] Auto Class Generator

查看:71
本文介绍了汽车类发生器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初是在这里问这个问题的:先前的问题

I had originally asked this question here: Former Question

看来我的要求被误解了。我将尝试使之尽可能简洁明了:

It appears that what I was asking for was misunderstood. I will try to make this as clear and as brief as possible:

我正在研究一种自动解析器生成 c ++ class ,如果存在标头和cpp文件的名称,则解析器将分别写出这些文件。如果忽略它们,则解析器将不会写入任何文件,该文件将根据从文件中提取的信息自动生成一个类。

I'm working on a parser that will automatically generate a c++ class and if the names of the header and cpp files are present the parser will write out those files respectively. If they are omitted then the parser will not write any files where it will generate a class automatically based on the information that is pulled in from the file.

我不做什么我不知道该怎么做:假设我的班级标识符存储在 std :: string 中,我如何提取字符串中的文本以用作班级名称。例如:

What I don't know how to do: Let's say my class's identifier is stored in a std::string how can I extract the text in the string to use that as the class's name. For example:

{ 
    std::string className( "Foo" );

    // parser writing class in code
    class className { ....

} 

这是我什至不知道该怎么办。如我在上一个问题中所述,我宁愿远离,但不介意在需要时使用模板其他机制。

This is what I don't know how to do if it can even be done. As stated in my previous question I prefer to stay away from macros but wouldn't mind using templates if needed or some other mechanism.

结论

阅读下面的评论和提供的答案后;我最初没有提到的假设实际上是正确的。无法完成。我对此表示怀疑,但只想确认一下。因此,这的确使我不得不写出文件,以便在运行时创建所需的标头和/或源文件。

After reading the comments and the provided answer below; my initial assumption that I didn't mention was in fact proven true. It can not be done. I was suspicious of this, but only wanted to confirm. So this does leave me in having to write out to files in order to create the needed header and or source files at run time.

推荐答案

您不能。

C ++程序无法修改自身

C++ programs cannot modify themselves.

如果要自动生成C ++代码,请在构建过程中将其作为预编译步骤。

If you want to auto-generate C++ code, do it as an pre-compilation step in your build process.

我自己有一个不错的Python脚本,它生成大量的C ++类(及其随附的样板),每个类都表示由第三方定义的几种消息类型之一。很可爱。

I myself have a nice Python script generating a ton of C++ classes (and their accompanying boilerplate) each representing one of several "message types" defined by a third party. It's lovely.

这篇关于汽车类发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆