# C++ Generator

The C++ code generator is a plug-out directly written in C++ (the C++ code generator does not generate itself !).

The generated sources follows the definition made in BOUML at the artifact / class / operation / relation / attribute / extra member levels.

When the code generation is applied on a artifact associated to several classes, the code generation is made for all these classes. Nevertheless the the C++ code generator produce first the code in memory and update the appropriate files only when it is necessary, to not change the last write date of the files for nothing.

The C++ code generator plug-out may be called on :

- a class : in this case the code generation is in fact applied on the class's artifact, then on all the classes associated to this artifact

- a artifact : in this case the code generation is in fact applied on all the classes associated to the artifact

- a class view : the code generation will be applied on all the sub classes, then on all the artifacts associated to these classes

- a deployment view : the code generation is applied on all the sub artifacts

- a package (may be the project itself) : the code generation will be applied on all the sub class views and deployment views, then on all their sub classes and artifacts.

When the C++ code generator is ask through the Tools menu, it is applied on the project, then on all the artifacts.

The name of the generated files depend on the artifact name, the extension depend on the language and is fixed for each by the generations settings (see below), the directory where the files are generated may be set in each package containing directly or indirectly the artifact (see generation directory).

## artifact

The C++ definition of a artifact is set through the C++ header and C++ source tabs of the artifact dialog.

### artifact header C++

The generated file name is the artifact's name with the extension specified in the first C++ tab of the generations settings :

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${NAME} produce the artifact name capitalized, ${Name} produce the artifact name with the first letter capitalized, at least ${name} produce the artifact name without modification.

- ${comment} is replaced by the artifact description

- ${includes} is replaced by the automatically generated #include and using forms, it is also a good place to add your #include and using forms, when the ones produced by the code generator are not sufficient. To limit the included files number and to not produce circular #include, the C++ code generator does not produce an #include to define a type only used by pointer (*) or reference (&) or place between <> in a template form. The C++ code generator does not look at in the operations body, only the operation's profiles, relations and attributes, classes inheritances etc ... are used to compute the needed #include list.

- ${declarations} is replaced by the class declarations when the #include form is not produced, it is also a good place to add your declarations, when the ones produced by the code generator are not sufficient.

- ${namespace_start} is replaced by the namespace xx { forms, dependent on the namespace specifications associated to the package containing the artifact view where the artifact is defined.

- ${definition} is replaced by the definition of the classes associated to the artifact.

- ${namespace_start} is replaced by the } forms, dependent on the namespace specifications associated to the package containing the artifact view where the artifact is defined.

### artifact source C++

The generated file name is the artifact's name with the extension specified in the first C++ tab of the generations settings .

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${comment} is replaced by the description of the artifact

- ${includes} is replaced by the automatically generated #include and using forms, corresponding to the declaration generated in the header file. It is also a good place to add your #include and using forms.

- ${namespace_start} is replaced by the namespace xx { forms, dependent on the namespace specifications associated to the package containing the artifact view where the artifact is defined.

- ${members} is replaced by the non inline members of the classes associated to the artifact.

- ${namespace_start} is replaced by the } forms, dependent on the namespace specifications associated to the package containing the artifact view where the artifact is defined.

## Class

The C++ definition of a class is set through the Uml, Parametrized, Instantiate and C++ tabs of the class dialog.

A C++ type definition may be a class, a struct, an union, an enum or a typedef, depending on the stereotype and its translation in C++ (see generation settings).

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${comment} is replaced by the description of the class

- ${template} produce a template declaration in case the class is a template class

- ${name} is replaced by the class's name

- ${inherit} is replaced by the class inheritance

- ${members} is replaced by the code generated for all the class's members (relations, attributes, operations and extra members) following the browser order.

- ${items} only for the enums, is replaced by the enum's items

## Operation

The C++ definition of an operation is set through the Uml and C++ tabs of the operation dialog.

The indentation of the first line of the declaration/definition give the indentation added to the visibility specification in the class definition for all the operation declaration/definition (except for the pre-processor forms beginning by # whose are placed at the beginning of the line).

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${comment} is replaced by the description of the operation

- ${static} produce static when the operation is a class operation (see the UML tab)

- ${const} produce const when the operation is const

- ${volatile} produce volatile when the operation is volatile

- ${friend} produce friend when the operation is friend

- ${virtual} produce virtual when the oprration is virtual

- ${inline} produce inline when the operation is inline

- ${type} is replaced by the returned value type (see the UML tab)

- ${name} is replaced by the operation's name

- ${class} is replaced by the name of the class containing the operation.

- ${(} and ${)} produce ( and ), but there are also a mark for BOUML to find the parameters list

- ${abstract} produce the string = 0 when the operation is abstract (see the UML tab)

- ${staticnl} produce a line break when the operation is static, else an empty string.

- ${t<n>} and ${p<n>} produce the type and the name of each parameter (count from 0), this allows you to remove a parameter, add type modifiers etc ...

- ${throw} is replaced by the form throw (...) when at least an exception is defined in the UML tab. It is also possible to produce throw() when there is no exception depending on the generation settings.

- ${body} is replaced by the body of the operation, this macro may also be replaced by the body itself (BOUML use this way for the get and set operations associated to a relation/attribute). The usage of ${body} has a great advantage : when you hit Default definition or From declaration the body is not cleared ! At least BOUML share the declaration and definition forms of the operations (and other objects) to minimize the needed memory size, ${body} help for this !

## Attribute

The C++ definition of an attribute is set through the Uml and C++ tabs of the attribute dialog.

The indentation of the first line of the definition give the indentation added to the the visibility specification in the class definition for all the attribute definition (except for the pre-processor commands beginning by # whose are placed at the beginning of the line).

An attribute may be a standard attribute or the item of an enumeration.

### standard attribute

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${comment} is replaced by the description of the attribute

- ${static} produce static when the attribute is a class attribute (see the UML tab)

- ${mutable} produce mutable when the attribute is mutable

- ${volatile} produce volatile when the attribute is volatile

- ${const} produce const when the attribute is const (see the UML tab)

- ${type} is replaced by the type of the attribute (see the UML tab)

- ${name} is replaced by the attribute's name (see the UML tab)

- ${value} is replaced by the initial value of the attribute (see the UML tab)

### enumeration item

The macros known by the C++ code generator are :

- ${comment} is replaced by the description of the item

- ${name} is replaced by the item's name (see the UML tab)

- ${value} is replaced by the value of the item (see the UML tab)

## Relation

The C++ definition of a relation is set through the Uml and C++ tabs of the relation dialog.

The indentation of the first line of the definition give the indentation added to the the visibility specification in the class definition for all the relation definition (except for the pre-processor commands beginning by # whose are placed at the beginning of the line).

### Relation equivalent to an attribute

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the C++ code generator are :

- ${comment} is replaced by the description of the relation

- ${static} produce static when the relation is a class relation (see the UML tab)

- ${const} produce const when the relation is read-only (see the UML tab)

- ${type} is replaced by the class pointed by the relation (see the UML tab)

- ${name} is replaced by the relation's role name (see the UML tab)

- ${value} is replaced by the initial value of the relation (see the UML tab)

- ${mutable} produce mutable when the relation is mutable

- ${volatile} produce volatile when the relation is volatile

- ${stereotype} is replaced by the translation in C++ of the relation's stereotype (see the UML tab)

- ${multiplicity} is replaced by the multiplicity of the relation (see the UML tab), must be used in case the multiplicity is a vector or array dimensioning ([ and ] are added when they are not present).

### Dependency

A dependency having the stereotype friend produce a C++ friend declaration of the pointed class.

### Inheritance

The class inheritance are managed at the class level.

## Extra member

The C++ definition of an extra member is set through the C++ tabs of the extra member dialog.

No macros.

Previous : deployment diagram

Next : C++ reverse