Separate templates per file type when using Atomineer

214 Views Asked by At

I am using Atomineer 7.31 to format my C++ files, but I'm having trouble creating separate behaviour for different file types. As an example, I'd like to populate my .cpp files with certain information such as including the .h file with the same name as this file, and including my memory tracker, and I'd like the .h file to have a define guard and the basics of a class.

Example of .h file I desire:

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

#ifndef EXAMPLEFILE_H
#define EXAMPLEFILE_H

class ExampleFile
{
};

#endif // EXAMPLEFILE_H

And an example of a .cpp file I desire:

//! \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>

I'd like each of the above behaviours to appear (based on the file-type being used) when at the top of a blank file 3 forward-slashes are inserted (I believe this is default Atomineer behaviour). I've looked through http://www.atomineerutils.com/rulesguide.php, as well as the .xml files included with Atomineer (File.xml, Namespace.xml, DoxygenTemplates.xml, UserVariables.xml etc.), but I can't find any indication of whether I can do what I need.

There is a small example in File.xml where different information is used in the comments at the top of the file (e.g. header files will say "Declares class xxx" whereas .cpp/.c files will say "Implements class xxx"); but I'm unable to mimic that behaviour.

I'm aware of the %extension% variable that can be used, and the < If /> command, but I don't seem to be able to get what I desire. I've also tried using the Namespace.xml file in a similar way to the File.xml (File.xml declares the %fileDescription% variable to use, which is the one which handles whether the file says "Declares class xxx" or "Implements class xxx"), but I'm unable to get Namespace.xml to display anything at all.

Example of 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>

That information is then used in DoxygenTemplates.xml:

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

    %ip%
</file>

I've tried inserting several things above the %ip% (input position: where the mouse cursor will appear) but to no avail. I feel that perhaps part of the problem is that I can't get Namespace.xml to display anything. For instance, above the %ip% I've put %namespaceDescription% and I have a simple < Set desc="Hi" /> in Namespace.xml, but it doesn't display. I'd appreciate any help in solving this, thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, it is possible to do this with Atomineer! Proper functionality was added in a later version which I'll talk about, but to answer your question, you could change your DoxygenTemplate.xml to:

<file>
%fileDescription%
</file>

And then add everything in your File.xml, like so:

<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>

That being said, proper support was added for this kind of functionality in 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.

The information necessary to achieve this is in the 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.

If you have Atomineer 7.36 or higher, in your DoxygenTemplates.xml file you can write the following (If you have Atomineer 7.36 or higher it looks as if the default template comes with an example for an include guard):

For the header files:

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

For the cpp files:

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

Ensure that they both appear above any generic

<file>
</file>

because the Atomineer documentation states that

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

Regarding your problem with Namespace.xml and %namespaceDescription% not working, you were putting it in the wrong place. File.xml contains < File >: a means of creating a template for Atomineer to use when adding a file comment (that is, a comment created at the top of a file). Namespace.xml contains < Namespace > which is a template for Atomineer to use when adding a namespace comment (that is, a comment above a namespace).