# C++ roundtrip

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

The C++ code roundtrip updates from sources the classes of the model, add missing ones and remove useless classes (after confirmation). If you use Bouml to generate C++ code it is not recommended to also use the C++ roundtrip because you will loose preprocessing forms and C functions and other forms not representable in UML. The roundtrip is mainly dedicated to update a model used for documentation purpose.

The behavior of the C++ code roundtrip plug-out depends on the kind of the element it is applied :

- applied on a class it updates this classes and nested classes, the other classes may be defined in the same file (having the same associated artifact) are not updated nor the artifact. The plug-out can't be applied on a nested class

- applied on an artifact it updates the artifact and all the associated classes, and add classes newly defined in the associated source file

- applied on a class view it updates all the classes of the view and their nested classes, the other classes may be defined in the corresponding files (associated to the same artifacts) are not updated nor the artifacts

- applied on a deployment view it updates all the artifacts in the view and their associated classes, and add classes newly defined in the associated source files

- applied on a package it updates all the artifacts and classes defined under this packages and sub packages, and all the classes associated to the artifacts defined in the package and sub packages. Furthermore a reverse is performed in files placed in the directories corresponding to the package and sub packages and their sub directories. To apply the roundtrip at the project level update all the project and create classes not yet part of the model and defined in the referenced directories and their sub directories.

The sources read by the C++ code roundtrip are the ones having the extension specified in the generation settings. The tree formed by the directories and sub-directories produce an equivalent tree of sub-packages, on whose the needed class view and artifact view are made to support the classes and artifacts. The preprocessing phase is not made by the C++ code roundtrip whose ignore all the preprocessor forms, but some substitutions may be asked, see at the end of this chapter.

The reverse/roundtrip setting dialog of the modeler allows to specify through regular expression the files and / or directories whose must not be taken into account during a reverse and roundtrip, for instance to bypass test programs.

Obviously the C++ code roundtrip tries to produce the definitions made in BOUML at the artifact / class / operation / relation / attribute levels. When it is possible it creates a relation rather than an attribute.

Except for the special case of the templates class definition like vector<bool>, a artifact is created for each type definition, then a future C++ code generation may not produce a list of files similar to the reversed ones.

A C function cannot be specified in UML, the C++ code roundtrip loses them (generating a warning) except the ones declared friend in a class.

The C++ code roundtrip works in four steps, during the first step all the project is upload, in the second step the elements to roundtrip are prepared, in the third step it scans all the files to establish the list of defined types, then the last step may roundtrip/reverse the files. The third phase tries to replace the missing #include management, but it is not enough because the files whose are not under the selected directory (for instance the standard headers files !) are never taken into account and the synonym types are confusing.

The trace window is used to indicate the steps, the updated classes and possible problems for instance when it reads a C function definition it produces a warning in the trace window. The trace window is automatically opened by BOUML, it may also be manually opened through the Tools menu.

To do simple substitution on the read files : edit the project (top level package) to add a user property (through the tab 'Properties') with the key #file and the value must be the absolute pathname of a file. Each line of the specified file must contain :

- just an identifier : in this case this identifier will be ignored during roundtrip. This is like #define identifier

- a form identifier=value : in this case the identifier will replaced by the value during roundtrip. The value must a token, for instance an other identifier, a float, a string etc. This is like #define identifier value.

Warning : the lines must not contains spaces or tabs.

Previous : C++ reverse

Next : Java generator