LiK*_*Kao 6 eclipse eclipse-cdt
我需要为一个项目编写的代码来匹配一些样式指南.但是,CDT附带的标准模板与此样式不匹配.特别是头部防护装置的布局不是应该的方式.我查看了模板,对于我的Eclipse,它看起来像这样:
${filecomment}
#ifndef ${include_guard_symbol}
#define ${include_guard_symbol}
${typecomment}
${declarations}
#endif /* ${include_guard_symbol} */
Run Code Online (Sandbox Code Playgroud)
所以我猜这个变量${include_guard_symbol}是在CDT的某个地方设置的,但是有可能在不需要修改CDT本身的情况下改变这个设置吗?
稍微不同但相关的说明:是否可以添加自己的模板,因此您可以使用项目的常规新对话框添加其他类型的新文件(测试用例,专用类等)?
我们在项目上遇到了类似的困难.一种解决方案是将$ {include_guard_symbol}全部丢弃在模板中,并自己定义,可能使用其他一些预定义变量.像这样的东西:
${filecomment}
#ifndef MyProject_${file_base}_h
#define MyProject_${file_base}_h
${typecomment}
${declarations}
#endif /* MyProject_${file_base}_h */
Run Code Online (Sandbox Code Playgroud)
因此对于名为inc/Foo.h的头文件,include guard会像这样插入:
#ifndef MyProject_Foo_h
#define MyProject_Foo_h
Run Code Online (Sandbox Code Playgroud)
不幸的是,除此之外似乎还没有一种方法可以进行定制.例如,如果我定义了嵌套在a中的类namespace,我可能希望将命名空间作为include guard的一部分.目前,我无法在eclipse中找到办法.
小智 6
因此,在C/C++ - >代码样式 - >代码模板下的首选项对话框中,您可以将模板修改为更接近您需要的模板,例如,如果您需要保护中的命名空间,您可以执行类似的操作.
${filecomment}
#ifndef ${namespace_name}_${include_guard_symbol}
#define ${namespace_name}_${include_guard_symbol}
${includes}
${namespace_begin}
${declarations}
${namespace_end}
#endif /* ${namespace_name}_${include_guard_symbol} */
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6582 次 |
| 最近记录: |