本文介绍了定制Eclipse CDT的include-guard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要通过使用Eclipse/CDT创建一个新的C ++类来自动生成一个include-guard,但是我找不到改变${include_guard_symbol}属性的任何方法.

I want an automatically generated include-guard by creating a new C++-class with Eclipse/CDT, but I don't find any way to change the ${include_guard_symbol} attribute.

我希望是一个包含名称空间前缀的include-guard,如下所示:

My wish is an include-guard with a namespace prefix like following:

#ifndef NAMSPACE1_NAMESPACE2_HEADER_HPP

但是如果我使用#ifndef ${namespace_name}_${include_guard_symbol},它将产生:

But if I use #ifndef ${namespace_name}_${include_guard_symbol} for this, it will produce:

namepace1::namespace2::_HEADER_HPP

我该怎么做?

推荐答案

我在CDT的源代码中摸索了一下,发现一个未记录的首选项设置,可以用来更改${include_guard_symbol}生成的首选项.也没有它的GUI,但是如果将codetemplates.includeGuardGenerationScheme设置添加到<projectpath>/.settings/org.eclipse.cdt.ui.prefs,则可以在文件名(默认),文件路径或 UUID .

I had a dig around in the source for CDT, and found an undocumented preference setting you can use to change what is generated by ${include_guard_symbol}. There's no GUI for it either, but if you add the codetemplates.includeGuardGenerationScheme setting to <projectpath>/.settings/org.eclipse.cdt.ui.prefs, you can choose between file name (the default), file path or UUID.

给出文件<projectpath>/src/include/Class.h,以下值给出这些结果:

Given the file <projectpath>/src/include/Class.h, the following values give these results:

  • 0给出一个大写的文件名,即CLASS_H_
  • 例如,
  • 1给出一个UUID. HC9ABE718_D04E_411C_B5A2_F9FE1D9F9409
  • 2给出一个大写的文件路径,即SRC_INCLUDE_CLASS_H_
  • 0 gives an upper-case filename, i.e. CLASS_H_
  • 1 gives a UUID, for example. HC9ABE718_D04E_411C_B5A2_F9FE1D9F9409
  • 2 gives an upper-case file path, that is, SRC_INCLUDE_CLASS_H_

为免生疑问,这是我们的.settings/org.eclipse.cdt.ui.prefs的内容:

To avoid any doubt, here's the contents of our .settings/org.eclipse.cdt.ui.prefs:

codetemplates.includeGuardGenerationScheme=2
eclipse.preferences.version=1
formatter_settings_version=1

这显然不是您想要的,但是我们使用2给我们一个近似的名称空间,因为通常来说,我们的名称空间遵循我们的文件夹结构.

It's obviously not exactly what you're after, but we use 2 to give us an approximation of our namespaces since, generally speaking, our namespaces follow our folder structure.

相关代码位于CDT源文件中的以下文件中:

The relevant code is in these files in the CDT source:

  • core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java表示每个选项的常量
  • core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java用于执行工作的generateIncludeGuardSymbol()方法.
  • core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/PreferenceConstants.java for the constants for each option
  • core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java for the generateIncludeGuardSymbol() method that does the work.

很高兴看到添加了一个用于使用命名空间的附加选项以及一个GUI.

It would be really nice to see an extra option added for using the namespace, and a GUI too.

这篇关于定制Eclipse CDT的include-guard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 04:32