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

Separate templates per file type when using Atomineer

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

的基础知识

我想要的 .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 中有一个小示例,其中在文件顶部的注释中使用了不同的信息(例如,头文件将显示 "Declares class xxx" 而 .cpp/.c 文件将显示"Implements class xxx");但我无法模仿这种行为。

我知道可以使用 %extension% 变量和 < If /> 命令,但我似乎无法获得我想要的东西。我还尝试以与 File.xml 类似的方式使用 Namespace.xml 文件(File.xml 声明要使用的 %fileDescription% 变量,这是处理文件是否显示 "Declares class xxx" 或 "Implements class 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 中有一个简单的 但它不显示。如果能帮我解决这个问题,我将不胜感激!

是的,可以用 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 包含 < File >: 一种创建模板供 Atomineer 在 添加文件评论 (即在文件顶部创建的评论)时使用的方法。 Namespace.xml 包含 < Namespace >,它是 Atomineer 在 添加命名空间注释 (即命名空间上方的注释)时使用的模板。