By default, Modelio C++ Designer translates each UML package into a C++ namespace and generates a directory such that the hierarchy of namespaces and directories corresponds to the package hierarchy. However, it may be unnecessary at generated code level to have the granularity introduced at model level. Modelio C++ Designer lets you avoid namespace and/or directory generation for arbitrary chosen packages.
To avoid namespace generation, simply select a UML package and switch off the “Is a namespace” flag in the “C++” property view.
The “Is a namespace” option in the “C++” property view
After the “Is a namespace” option has been switched off, Modelio C++ Designer puts all the classes, interfaces, datatypes, enumerations and sub-packages defined in the package into the namespace of the owner package. If the owner package does not produce a namespace either, these entities are generated in the owner of the owner package, and so on. The root package always corresponds to the global namespace.
For example, let’s imagine we want to put all the classes defined in our application model into the “MyPlanner” namespace, which corresponds to the “MyPlanner” package. For this, we switch off the “Is a namespace” flag for the “TaskManagement”, “GUI” and “Windows” packages.
As a result, Modelio C++ Designer produces the following code, where all the classes represented in the model are defined in the “MyPlanner” namespace, for example, the “TaskWindow” class.
1//includes for used library types
2#include <cstringt.h>
3#include <afxwin.h>
4#include <afxtempl.h>
5#include <afxcoll.h>
6
7//automatic includes (friends, associated classes, etc)
8#include "MyPlanner/GUI/Windows/CWnd.h"
9#include "MyPlanner/GUI/ITaskView.h"
10#include "MyPlanner/TaskManagement/Task.h"
11
12namespace MyPlanner
13{
14 class TaskWindow : public CWnd, public ITaskView
15 {
16 //...
17 private:
18 CString displayTitle;
19
20 public:
21 CDC dc;
22
23 //associations
24
25 public:
26 Task* task;
27 CMap<CString,CString&,CBrush,CBrush&> brushResource;
28
29 //operations
30
31 public:
32 TaskWindow();
33 TaskWindow(const TaskWindow& value);
34 TaskWindow& operator =(const TaskWindow& value);
35 ~TaskWindow();
36 void formatDisplayTitle(std::string& FormatStr);
37 CDC getDc();
38 afx_msg int OnCreate(CREATESTRUCT* lpCreateStruct);
39
40 //non-modeled members
41
42 protected:
43 //modifiable zone @16224@30671900:2404@T
44 DECLARE_MESSAGE_MAP()
45 //modifiable zone @16224@30671900:2404@E
46 };
47}
To avoid directory generation, simply select a UML package and switch on the “No directory flag” in the “C++” property view. This will result in Modelio C++ Designer putting all the files produced for the package (the header and body files of its classes, interfaces and sub-packages) into the directory of the owner package. If the owner package does not produce a directory, the files are created in the directory of the owner of the owner package, and so on. The root package corresponds to the directory specified in the active generation target output path.
For example, let’s imagine that we want to put all the files generated for our application model into the “MyPlanner” directory, which is produced for the “MyPlanner” package. To do this, we simply switch on the “No directory” flag for the “TaskManagement”, “GUI” and “Windows” packages.
As a result, Modelio C++ Designer puts all the produced files into the “MyPlanner” directory.
All the produced files have been put into the “MyPlanner” directory