Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > C++ code > Generating C++ code > Generating C++ code > Mapping Information > Mapping information for state diagrams > Template class derivation mapping for C++ (C++ code)
  
Template class derivation mapping for C++ (C++ code)
Two examples are provided, which demonstrate how Template Class derivations are generated and reverse engineered. For procedural information about setting up Template Class derivations, see Setting up template class derivations for generating C++ code (C++ code).
Generation example
The following example demonstrates how code is generated for a Template Class derivation.
This example uses three classes:
list is a base Template Class and it has a Formal Template Parameter named typename T.
list<char*> instantiates the list Template Class for use with char pointers. The list<char*> Class is set up as a Template Specialization with its Template Specialization Parameters set to char*. Note that no code files are generated for the list<char*> class.
stringlist is a regular class that can hold collections of char pointers. It derives from the list template class using an actual parameter named 'char*'.
If you generate list, the header file contains the following text:
template<typename T>
class list
{
};
If you generate stringlist, the header file contains the following text:
#include "list.h"
class stringlist : public list<char*>
{
};
Notice that even though the stringlist class derives from the list instantiation template specialization, the list instantiation template specialization is just a specialization of the list template class with actual parameters specified. Therefore, in the code we can see that the stringlist class actually derives from the list template class and supplies the actual parameters specified in the list instantiation template specialization.
Reverse engineering example
The following example demonstrates how Template Class derivations are reverse engineered into Modeler by the C++ Code Reverser. The diagram that follows shows the result of reverse engineering the following code.
// File.h
template<class T> class foobar
{
};

// File.cpp
#include "File.h"
class freddave : public foobar<float>
{
foobar<int> m_foobar;
};
The following items have been created in Modeler.
foobar is a Template Class (the Template Class check box is selected on the Options tab of the Class' Property Pages).
freddave is a standard Class.
A Generalization between the foobar Template Class and the freddave Class.
<float> is reverse engineered as the tagged value of the C++ Actual Template Parameters tag definition that is applied to the Generalization through the «C++ Specialization» stereotype.
The foobar<int> instantiation is reverse engineered as the m_foobar attribute of the freddave Class. <Int> is reverse engineered as the tagged value of the C++ Actual Template Parameters tag definition, which is applied to the m_foobar attribute through the «C++ Attribute» stereotype.