Using templates to create a Class.h file and a ClassTest.cpp file?

Hi,

I have a very class creation pattern that is very common to me.

1) I create a MyClass.h file. I almost always code exclusively in .h files. There's a few things that is always the same for that file:

#pragma once

//Legal comment

A class inside a namespace

2) I create MyClassTest.cpp file. The same applies to this file as for the above almost, except it also includes a couple of boiler plate unit test includes.

3) There is a pattern to where these two files are located from each other, but I'm fine with the .h file being created in the Test folder. Even if I have to move it manually it still saves me a lot of time.

My question is if there is a way that I can create a template to help me with this?

1 comment

Hi Olof.

It hasn't been implemented yet.

For now you can:
- Change "C header file" and "C source file" file templates (note the "C file header" helper) according to you needs (e.g. place license text here)
- Create a C/C++ live template like this:

namespace $NAMESPACE$ {
class $CLASS$ {
$END$
};
}

It will allow you to insert the template and jump between the placeholders with tab/shift-tab. Also you can provide some default values via "Edit variables" buttons. Please find out more via https://www.jetbrains.com/help/clion/2016.1/live-templates.html and https://www.jetbrains.com/help/clion/2016.1/live-templates-2.html

If it is inconvenient for you, please file a feature request in our tracker describing your situation: https://youtrack.jetbrains.com/issues/CPP

0

Please sign in to leave a comment.