By default, Modelio Cxx Designer translates each UML package into a Cxx 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 Cxx 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 "Cxx" property view.

image
The "Is a namespace" option in the "Cxx" property view

After the "Is a namespace" option has been switched off, Modelio Cxx 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 Cxx 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//includes for used library types
#include <cstringt.h>
#include <afxwin.h>
#include <afxtempl.h>
#include <afxcoll.h>

//automatic includes (friends, associated classes, etc)
#include "MyPlanner/GUI/Windows/CWnd.h"
#include "MyPlanner/GUI/ITaskView.h"
#include "MyPlanner/TaskManagement/Task.h"

namespace MyPlanner
{
        class TaskWindow : public CWnd, public ITaskView
        {
        //...
        private:
                CString displayTitle;

        public:
                CDC dc;

        //associations

        public:
                Task* task;
                CMap<CString,CString&,CBrush,CBrush&> brushResource;

        //operations

        public:
                TaskWindow();
                TaskWindow(const TaskWindow& value);
                TaskWindow& operator =(const TaskWindow& value);
                ~TaskWindow();
                void formatDisplayTitle(std::string& FormatStr);
                CDC getDc();
                afx_msg int OnCreate(CREATESTRUCT* lpCreateStruct);

        //non-modeled members

        protected:
                //modifiable zone @16224@30671900:2404@T
                DECLARE_MESSAGE_MAP()
                //modifiable zone @16224@30671900:2404@E
        };
}

To avoid directory generation, simply select a UML package and switch on the "No directory flag" in the "Cxx" property view. This will result in Modelio Cxx 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 Cxx Designer puts all the produced files into the "MyPlanner" directory.

image
All the produced files have been put into the "MyPlanner" directory