C Generator

The C code generator is a plug-out directly written in C++.

The generated sources follows the definition made in BOUML at the artifact / class / operation / relation / attribute levels, reusing the parts specific to the C++ language with adapted values.

The best way to get the right generation settings is to load the project C part of the distribution, or to import its settings.

When the code generation is applied on a artifact associated to several classes, the code generation is made for all these classes. Nevertheless 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. Depending on the toggle verbose code generation of the global menu Languages the code generator is verbose or not.

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

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.

The code generation depend on the stereotype of the artifact :

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 :

Note : the generation settings allows to choose between four ways to produce #include :

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 :

Class

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

The generated C type depends on the translation in C++ of its stereotype (see generation settings), a c_enum will produce an enum, c_struct a struct, a c_union an union and a c_typedef a typedef, and a c_module will produce its members (including operations as functions), in the other cases nothing is produced.

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

In the special case where the class is declared external, its C++ type declaration must contains at least one line indicating how the name of the class is generated, the other lines will be added in the header file of the components referencing the class. By default the first line only contain ${name} meaning that the name is produced unchanged, the only allowed keywords are ${name}, ${Name} and ${NAME}. Remember in C you have to add the kind of the type like struct.

Operation

The C++ definition of an operation is set through the Uml and C++ tabs of the operation dialog. In C an operation produces a function, and this is done only for classes stereotyped c_module.

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

If the toggle preserve operations's body is set through the Languages menu, the generators do not modify the body of the operations protected by dedicated delimiters. This means that for them the body definition set through BOUML is not used. The first time you generate the code with the toggle set, because the delimiters are not yet present in the generated code, the operation's body will be updated depending on their definition under BOUML. After, while the toggle is set and the delimiters present, the bodies will not change, allowing you to modify them out of BOUML.

Notes :

Attribute

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

An attribute may be a C variable 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 :

enumeration item

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

Relation

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

Relation equivalent to a C variable

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

Dependency

The dependency may produce an #include of the artifact associated to the target class, and you can choose to place this #include in the header or source file by editing the dependency using the tab C++.



Previous : C++ roundtrip

Next : Java generator