gpt4 book ai didi

c++ - 使用 Atomineer 时,每个文件类型都有单独的模板

转载 作者:行者123 更新时间:2023-11-30 05:46:05 28 4
gpt4 key购买 nike

我正在使用 Atomineer 7.31 来格式化我的 C++ 文件,但我无法为不同的文件类型创建单独的行为。例如,我想用某些信息填充我的 .cpp 文件,例如包括与该文件同名的 .h 文件,并包括我的内存跟踪器,我希望 .h 文件有一个定义守卫和类的基础知识。

我想要的 .h 文件示例:

//! \file  ExampleFile.h
//! \brief Declares an ExampleFile
//! Company legal information etc.

#ifndef EXAMPLEFILE_H
#define EXAMPLEFILE_H

class ExampleFile
{
};

#endif // EXAMPLEFILE_H

还有一个我想要的 .cpp 文件的例子:

//! \file  ExampleFile.cpp
//! \brief Implements ExampleFile
//! Company legal information etc.

#include <ExampleFile.h>

// Memory tracking. Do not include anything beneath this!
#include <debug_new.h>

我希望在空白文件的顶部插入 3 个正斜杠时(我相信这是默认的 Atomineer 行为)出现上述每个行为(基于正在使用的文件类型)。我已经看过 http://www.atomineerutils.com/rulesguide.php ,以及 Atomineer 附带的 .xml 文件(File.xml、Namespace.xml、DoxygenTemplates.xml、UserVariables.xml 等),但我找不到任何迹象表明我是否可以做我需要的。

File.xml 中有一个小示例,文件顶部的注释中使用了不同的信息(例如,头文件将显示“声明类 xxx”,而 .cpp/.c 文件将显示“实现类 xxx” ");但我无法模仿这种行为。

我知道可以使用 %extension% 变量和 < If/> 命令,但我似乎无法获得我想要的东西。我还尝试过以与 File.xml 类似的方式使用 Namespace.xml 文件(File.xml 声明要使用的 %fileDescription% 变量,这是处理文件是“声明类 xxx”还是“实现类 xxx"),但我无法让 Namespace.xml 显示任何内容。

File.xml 示例:

<File>
<!-- Rules for generating auto-documentation for file header comments. The results of executing this rule are placed in %fileDescription% when adding file comments. -->
<If extension=".c" desc="" />
<If sNameRaw="I #" desc="Declares the %name% interface" />
<If extension=".h,.hpp" continue="y" desc="Declares the " />
<If extension=".cs,.cpp,.java" continue="y" desc="Implements the " />
<If sName="# dialog,# dialogue" desc="%match:noPrefix:LCase% Dialog" />
<If sName="# form,# window" desc="%match:noPrefix:LCase% Windows Form" />
<Set desc="%sname:noPrefix:LCase% class" />
</File>

然后在 DoxygenTemplates.xml 中使用该信息:

<file>
//! \file %projectpathname%
//! \brief %fileDescription%
//!
//----------------------------------------------------------------------------------------------------------------------
// (c) Copyright 2015 by %company%
//----------------------------------------------------------------------------------------------------------------------

%ip%
</file>

我尝试在 %ip%(输入位置:鼠标光标出现的位置)上方插入几项内容,但无济于事。我觉得也许部分问题是我无法让 Namespace.xml 显示任何内容。例如,在 %ip% 上方我放置了 %namespaceDescription% 并且我在 Namespace.xml 中有一个简单的 < Set desc="Hi"/>,但它没有显示。如果能帮我解决这个问题,我将不胜感激!

最佳答案

是的,Atomineer 可以做到这一点! 适当的功能已添加到我将要讨论的更高版本中,但要回答您的问题,您可以将 DoxygenTemplate.xml 更改为:

<file>
%fileDescription%
</file>

然后将所有内容添加到您的 File.xml 中,如下所示:

<File>
<!-- Filename/path -->
<Set desc="//! \file %projectpathname%
//! \brief "
continue="y"
/>
<!-- \brief about the class -->
<!-- Header files -->
<If extension=".h" continue="y" desc="Declares the " />
<!-- Source files -->
<If extension=".cpp" continue="y" desc="Implements the " />
<Set desc="%sname:noPrefix:LCase% class" continue="y"/>
<!-- Company legal -->
<Set desc="
//! Company legal information etc.
" continue ="y" />

<!-- Include guard for header files -->
<If extension=".h" continue="y">
<Set desc="
#ifndef %leafname:UCase%_H
#define %leafname:UCase%_H

class %leafname%
{
};" continue ="y" />
</If>

<!-- Include header.h and memory tracker in source files -->
<If extension=".cpp" desc="
#include &lt;%leafname%.h&gt;

// Memory tracking. Do not include anything beneath this!
#include &lt;debug_new.h&gt;" continue="y" />

<!-- Include guard for header files -->
<If extension=".h">
<Set desc="

#endif // %leafname:UCase%_H" />
</If>

<!-- For non header files, end with nothing -->
<Set desc="" />

</File>

也就是说,proper support was added用于 Atomineer 7.36 中的此类功能。

7.36

  • File and File-footer comments can now be targetted to specific file extensions, to allow different headers to be added to (for example)
    .cpp and .h files, and adding a file header can optionally add a file footer at the same time. The default templates now contain an example that can be used to add a #ifndef ... #endif 'include once' mechanism to header files using these features.

实现此目标所需的信息在 documentation 中:

Further control of file header/footer comments can be achieved using
the following attributes:

_filetypes=".h.hpp": Target a template to specific set of file extensions, so you can use a different header style in .h and .cpp files, for example. The first template that matches the filetype will be used, so this must precede any file template that doesn't specify any specific filetypes.

如果你有 Atomineer 7.36 或更高版本,你可以在你的 DoxygenTemplates.xml 文件中编写以下内容(如果你有 Atomineer 7.36 或更高版本,它看起来好像默认模板带有一个包含保护的示例):

对于头文件:

<file _filetypes=".h">
#ifndef %leafname:UCase%_H
#define %leafname:UCase%_H
class %leafname%
{
};
#endif // %leafname%_H
</file>

对于 cpp 文件:

<file _filetypes=".cpp">
#include &lt;%leafname%.h&gt;
#include &lt;debug_new.h&gt;
</file>

确保它们都出现在任何泛型之上

<file>
</file>

因为 Atomineer 文档指出

The first template that matches the filetype will be used, so this must precede any file template that doesn't specify any specific filetypes.

关于 Namespace.xml 和 %namespaceDescription% 不工作的问题,你把它放在了错误的地方。 File.xml 包含 :一种创建模板的方法,供 Atomineer 在 添加文件评论(即在文件顶部创建的评论)时使用。 Namespace.xml 包含 < Namespace >,它是 Atomineer 在 添加命名空间注释(即命名空间上方的注释)时使用的模板。

关于c++ - 使用 Atomineer 时,每个文件类型都有单独的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29111206/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com