Generating namespaces and directories

 

By default, Objecteering C++ Developer 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. Objecteering C++ Developer lets you avoid namespace and/or directory generation for arbitrary chosen packages.

 

To avoid namespace generation, simply select a UML package and switches off the "Is a namespace" flag in the "C++" tab of the auxiliary window (Figure 59).

 

Figure 59. The "Is a namespace" option in the "C++" tab of the auxiliary window

 

After the "Is a namespace" option has been switched off, Objecteerinng C++ Developer 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 also does not produce a namespace, 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, Objecteering C++ Developer produces the following code, where all the classes represented in the model are defined in the "MyPlanner" namespace, for example, the "TaskWindow" class.

 

//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 "C++" tab of the auxiliary window.  As a result, Objecteering C++ Developer puts 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.

 

Figure 60. The "No directory" option in the "C++" tab of the auxiliary window

 

 

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, Objecteering C++ Developer puts all the produced files into the "MyPlanner" directory (Figure 61).

 

Figure 61. All the produced files have been put into the "MyPlanner" directory