Creating Templates for ClassCreator
In this documentation the template creation for Car4Tegra ClassCreator will be explained.
Table of Contents
Overview
A ClassCreator template can consist of these four files:
- 
    
XML Configuration
 - 
    
Header Template (optional)
 - 
    
Source Template (optional)
 - 
    
CMake Template (optional)
 
In the following sections the XML Configuration file and the available tokens for the template files will be described in detail.
XML Configuration File
The XML configuration file contains all information about the template. The parent node ist shown below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<template name="" headerfile="" sourcefile="" cmakefile="" classNameProperty="" sysPathVar=""> 
   <!-- Insert nodes here -->
   
</template>
Some of the attributes of the parent node are optional and could be omitted if not neccessary:
- 
    
name
Contains the name of the template, which is shown in the selection combo box (e.g. “Example Class”).
 - 
    
headerfile (optional)
Contains the file name of the header template file (e.g.
example_header.template). - 
    
sourcefile (optional)
Contains the file name of the source template file (e.g.
example_source.template). - 
    
cmakefile (optional)
Contains the file name of the CMake template file (e.g.
example_cmake.template). - 
    
classNameProperty
Contains the identifier of the property which contains the name of the class (e.g.
CLASS_NAME). - 
    
sysPathVar (optional)
Contains the name of the environment variable which should be used for auto detection of the output path (e.g.
CVHAB_FILE_DIR). 
There are five different node types:
Node filepath
There has to be a filepath node for each template file used (header / source / CMake). The nodes for unused template files could be omitted.
<filepath file="header" path="\header" />
<filepath file="source" path="\source" />
<filepath file="cmake"  path="\cmake" />
- 
    
file
Refers to the corresponding template file type (not the template file name itself!).
 - 
    
path
Contains the template for the output path for this file relative to the main output path. It could be written directly as shown above or by using tokens as shown below.
 
<filepath file="header" path="$HEADER_PATH$$@USE_SUB_DIR$\$SUB_DIRECTORY$$USE_SUB_DIR@$" />
Node directory
The directory node allows to create directories, also if there is no file inside.
<directory path="/templates" />
<directory path="/modules/$MODULE_NAME_L$/source" />
- 
    
path
Contains the template for the directory path relative to the main output path. It could be written directly or by using tokens.
 
Node property
The property nodes represent the settings for this template. From this nodes the tokens for template parsing are created (see token section below). There are three types of property nodes:
<property name="" identifier="" type="bool"       default=""           info="" group="" />
<property name="" identifier="" type="string"     default="" format="" info="" group="" />
<property name="" identifier="" type="stringlist" default="" values="" info="" group="" />
- 
    
name
Name of the property for visualization (e.g. “Class Name”)
 - 
    
identifier
Identifier of the property for token generation (e.g.
CLASS_NAME) - 
    
type
Type of the property
boolfor block tokenstringfor text editstringlistfor selection box
 - 
    
default
Default value for the property. Valid values depends on the property type:
- bool: 
TRUEorFALSE - string: any string
 - stringlist: 0 based index
 
 - bool: 
 - 
    
format (only string type)
Regular expression for this string type to limit input possibilities (e.g.
[A-Z].[a-zA-Z0-9_]*) - 
    
values (only stringlist type)
Values for selection in combo box, separated by
,(e.g.Value 1,Value 2,Value 3) - 
    
info
Help text which is shown at mouse over.
 - 
    
group (optional)
Name of the group the property is corresponding to (e.g. “Example Group”)
 
Node filepathproperty
The filepathproperty node is the same as the property node above but it is highlighted in green in the property browser of the GUI. It should be used for properties which only have an impact on filepath templates but not on the content of the template files.
<filepathproperty name="" identifier="" type="bool"       default=""           info="" group="" />
<filepathproperty name="" identifier="" type="string"     default="" format="" info="" group="" />
<filepathproperty name="" identifier="" type="stringlist" default="" values="" info="" group="" />
Node postprocessing
The
postprocessingnode is not tested yet!!!
Thepostprocessingnode allows to run commands after file generation. They are selectable in the property browser of the GUI (highlighted in red).
<postprocessing name="Auto CMake" command="cmake" params="param1 param2 param3" info="Runs cmake for project after generate." />
- 
    
name
Name of the post processing command, visible in the GUI (e.g. “Run Command”)
 - 
    
command
Command which should be processed (e.g.
cmd) - 
    
params
Additional parameters for the command, separated by space (e.g.
param1 param2 param3) - 
    
info
Help text which is shown at mouse over.
 
Tokens
There are two different tokens: Text tokens (string / stringlist properties) and block tokens (bool properties):
Text Tokens
Text tokens (for string / stringlist type properties) are represented by $IDENTIFIER$ as shown below:
class $CLASS_NAME$
{
   // Constructor
   $CLASS_NAME$();
   
   // Destructor
   ~$CLASS_NAME$();
}
There is also generated automatically an $IDENTIFIER_U$ for upper case and an $IDENTIFIER_L$ for lower case for each text token.
Block Tokens
A block token (for bool type properties) starts with an $\@IDENTIFIER$ token and ends with an $IDENTIFIER\@$ token. The code between this two tokens will be removed if IDENTIFIER is FALSE.
class $CLASS_NAME$
{
   // Constructor
   $CLASS_NAME$();
      
   $@HAS_DESTRUCTOR$
   // Destructor
   ~$CLASS_NAME$();
   $HAS_DESTRUCTOR@$
}
There is also generated automatically a negated pair of tokens $\@!IDENTIFIER$ and $!IDENTIFIER\@$ (note the ! sign).
Global Tokens
Beside the tokens generated by the properties specified in the XML configuration file, there are a few other global tokens which are influenced by the user settings:
- 
    
$AUTHOR$
Name of the author as specified in the user settings
 - 
    
$HEADER_FILE_NAME$
Name of the output header file (including file extension)
 - 
    
$SOURCE_FILE_NAME$
Name of the output source file (including file extension)
 - 
    
$CMAKE_FILE_NAME$
Name of the output CMake file (including file extension)
 - 
    
$IFNDEF_MACRO$
Include macro for header file (e.g.
__NAMESPACE_SUBNAMESPACE_FILENAME_HPP__) - 
    
$DATE$
Current date formated as specified in the user settings
 - 
    
$INDT$
Indent spacing is empty if there is no
HAS_NAMESPACEproperty orHAS_NAMESPACEis false otherwise it has the ident spaces as specified in the user settings - 
    
$SUB_INDT$
Indent spacing has the same value as
$INDT$if there is noHAS_SUBNAMESPACEproperty orHAS_SUBNAMESPACEis false otherwise it has twice the ident spaces as specified in the user settings 
Note:
The$IFNDEF_MACRO$/$INDT$/$SUB_INDT$tokens are searching forHAS_NAMESPACE/HAS_SUBNAMESPACE/NAMESPACE/SUB_NAMESPACEidentifiers during parsing. To use these tokens, you have to add properties with these identifiers to your configuration XML. For the$IFNDEF_MACRO$token, theHAS_NAMESPACE/HAS_SUBNAMESPACEidentifiers are optional.