Code templates

The Code Templates preference panel lets you configure the format of newly generated code stubs, comments and files.

Code Templates Preferences Window

The code templates page contains templates that are used by actions that generate code and/or source files. E.g. the New Class wizard uses source and header file templates to create new files and code templates to insert generated method stubs. Templates contain variables that are substituted when the template is applied. Some variables are available in all templates, some are specific to templates.

Options Description
New...

Opens the Code Template dialog to create a new file template.

Edit...

Opens the Code Template dialog to edit the currently selected code template.

Remove

Removes a user added file template. Predefined templates cannot be removed.

Import...

Imports templates from the file system.

Export...

Exports all selected templates to the file system.

Export All...

Exports all templates to the file system.

Comment Templates

Template Name Specifies
Files

Header comment for new source or header files.

Note that this template can be referenced in source and header file templates with ${filecomment}.

Types

The comment for new types.

Note that this template can be referenced in source and header file templates with ${typecomment}.

Fields

The comment for new fields.

Constructors

The comment for new constructors.

Destructors

The comment for new destructors.

Methods

The comment for new methods.

Code Templates


Template Name Description
Method body

The 'Method body' templates are used when new method is created.

Constructor body

The 'Constructor body' templates are used when a constructor is created.

Destructor body

The 'Destructor body' templates are used when the destructor is created.

File Templates

File templates can not only be defined and modified for C/C++ files, but also for other content types, like Assembly files or plain text files. The New File from Template wizard can be used to create new files based on one of the templates defined in this page.
Template Name Description
Default C++ source template

Used by the New Class wizard and the New Source File wizard when a new C++ source file is created.

The template can specify where comments are added. Note that the template can contain the variable ${typecomment} and ${filecomment} that will be substituted by the evaluation of the Types respectively Files comment template.

Default C++ header template

Used by the New Class wizard and the New Header File wizard when a new C++ header file is created.

The template can specify where comments are added. Note that the template can contain the variable ${typecomment} and ${filecomment} that will be substituted by the evaluation of the Types respectively Files comment template.

Default C source template

Used by the New Source File wizard when a new C source file is created.

The template can specify where comments are added. Note that the template can contain the variable ${typecomment} and ${filecomment} that will be substituted by the evaluation of the Types respectively Files comment template.

Default C header template

Used by the New Header File wizard when a new C source file is created.

The template can specify where comments are added. Note that the template can contain the variable ${typecomment} and ${filecomment} that will be substituted by the evaluation of the Types respectively Files comment template.

Other file templates

File templates can be defined for other content types, e.g. Assembly or plain text.

Edit Template dialog

Edit Template Dialog Box

The following fields and buttons appear in the dialog:

Options

Description

Name

The name of the template. Only available for file templates.

Type

The file type (content type) of the template. Only available for file templates.

Description

A description of the template

Pattern

The template pattern.

Insert Variables...

Displays a list of pre-defined template specific variables.

Related concepts
Coding aids

Related reference
C/C++ editor preferences

IBM Copyright Statement