如何自定义eclipse CDT代码模板 [英] How to customize eclipse CDT code templates

查看:738
本文介绍了如何自定义eclipse CDT代码模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我为一个项目编写的代码来匹配一些样式指南。但CDT包含的标准模板与此风格不符。特别是标题栏的布局不是应该的方式。我看过这个模板,对于Eclipse来说,它看起来像这样:

I need the code I am writing for a project to match some style guidelines. However the standard templates included with CDT don't match this style. Especially the layout of the header guards is not the way it should be. I had a look at the template and for my Eclipse it looks like this:

${filecomment}

#ifndef ${include_guard_symbol}
#define ${include_guard_symbol}

${typecomment}
${declarations}

#endif /* ${include_guard_symbol} */

所以我猜这个变量 $ {include_guard_symbol } 设置在CDT的某个地方,但是可以更改此设置,而无需修改CDT本身?

So I am guessing the variable ${include_guard_symbol} is set somewhere in the CDT, but is it possible to change this setting without needing to modify the CDT itself?

略有不同,但相关注释:
是否可以添加自己的模板,因此您可以使用项目的正常新对话框添加其他类型的新文件(测试用例,专门类等)?

On a slightly different, but related note: Is it possible to add your own templates, so you just could add new files of other types (test-cases, specialized classes etc) using the normal new dialog for the project?

推荐答案

我们在我们的项目中也有类似的斗争。一个解决方案是在模板中一起抛出$ {include_guard_symbol},并自己定义,可能使用一些其他预定义的变量。如下所示:

We've had a similar struggle on our project. One solution is to throw out ${include_guard_symbol} in the template all together, and define it yourself, possibly using some of the other predefined variables. Something like this:

${filecomment}

#ifndef MyProject_${file_base}_h
#define MyProject_${file_base}_h

${typecomment}
${declarations}

#endif /* MyProject_${file_base}_h */

所以对于名为inc / Foo.h的头文件,include guard将被插入:

So for a header file named inc/Foo.h, the include guard would be inserted like this:

#ifndef MyProject_Foo_h
#define MyProject_Foo_h

不幸的是,似乎没有一种可以自定义的方式。例如,如果我定义了嵌套在命名空间中的类,那么我可能希望将命名空间作为include guard的一部分。目前,我没有办法在日食中做到这一点。

Unfortunately, there doesn't seem to be a way to customize much beyond that. For example, if I defined a class nested in a namespace, I might want to put the namespace as part of the include guard. I can't find a way to do that in eclipse, currently.

这篇关于如何自定义eclipse CDT代码模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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