Entering implementation code
Introduction
To implement an application, application behaviour has to be described and implemented by attaching C++ code notes to UML operations.
Entering operations code
Objecteering C++ Developer conveniently lets you input С++ code for UML operations directly in the operation edition dialog box. You simply enter your C++ code in the "Code" field of the "Code" tab of the operation edition box. Objecteering C++ Developer injects code entered in this field into the operation definition and generates the markers required to retrieve the code back into the model, if it is modified in the external editor.
As an example, we want to implement the assignment operator for the "Task" class in our application. For this, we open the C++ edition dialog box for the respective UML operation and input the operator code in the "Code" field (Figure 49).

Figure 49. Inputting the operator code in the "Code" field
The entered code is injected into the definition of the assignment operator in the body of the "Task" class.
//class header file
#include "MyPlanner/TaskManagement/Task.h"
namespace MyPlanner
{
namespace TaskManagement
{
Task::Task()
{
//modifiable
zone @12366@30671900:196@T
//modifiable
zone @12366@30671900:196@E
}
Task::Task(const Task& value)
{
//modifiable
zone @12378@30671900:208@T
//TODO: write copy constructor code
//modifiable
zone @12378@30671900:208@E
}
Task&
Task::operator =(const
Task& value)
{
//modifiable
zone @12396@30671900:226@T
//TODO: write assignment operator
code
std::copy(value.getSubTask().begin(),
value.getSubTask().end(), std::inserter(this.subTask, this.subTask.begin()));
std::copy(value.getResource().begin(),
value.getResource().end(), std::inserter(this.resource,
this.resource.begin()));
this.owner = value.getOwner();
this.name = value.getName();
this.wbsCode = value.getWbsCode();
//modifiable
zone @12396@30671900:226@E
//modifiable
zone @12397@30671900:227@T
return *this;
//modifiable
zone @12397@30671900:227@E
}
//...
}
}
Note: To ensure efficient code retrieval, Objecteering C++ Developer does not automatically indent code notes. As a result, the injected code notes start from the zero columns. Only user indentation is taken into account.
You can use the code preview function to immediately examine how the code you have entered will be generated (Figure 50).

Figure 50. Previewing how the code you have entered will be generated
The "Return expression" field is used to input a return expression, which is always generated for the function independently of the function code. In our example, the standard return expression for assignment operators is input here (Figure 51). This note is generated automatically by the model-level creation operation pattern.

Figure 51. Inputting a return expression
The "Base Constructor Code" field is used to input base construction clauses. Objecteering C++ Developer automatically activates this field if the operation is detected as being a constructor (as a result of its name matching the owner class name or of the attached <<create>> stereotype).
Entering class code and non-modeled class members
Objecteering C++ Developer lets you input С++ code to be injected into the class header and body files directly in the class C++ edition dialog box. This can be useful to initialize global variables and implement utility functions used by the class and class members, which are not relevant to the model but which need to be provided.
To enter class-level C++ code, you simply enter it in the "Code" tab of the class C++ edition dialog box (Figure 52).

Figure 52. The "Code" tab of the C++ edition dialog box for a class
The "Placement" hierarchy defines where the input code will be injected:
· "Header" to "Top (before Class)": The class header file right before the class definition.
· "Header" to "Class (Class Members)" to "Public": A class public member.
· "Header" to "Class (Class Members)" to "Protected": A class protected member.
· "Header" to "Class (Class Members)" to "Private": A class private member.
· "Header" to "Bottom (after Class)": The class header file right after the class definition.
· "Body" to "Top (before Class)": The class body file (*.cpp file) right before definition of class members.
· "Body" to "Bottom (after Class)": The class body file (*.cpp file) right after definition of class members
Therefore, to input C++ code in the intended position in the class header or body file, you simply select the respective node in the "Placement" hierarchy and then type the code in the "C++" field. You can immediately examine how the input code will be generated using the code preview function.
For example, we want to inject the standard MFC macro "DECLARE_MESSAGE_MAP" into the header of the "TaskWindow" class, because this class represents the specific window (and is therefore inherited from the "CWnd" class) and should intercept window messages. The macro should be injected as a protected "member" of the class.
We open the "Code" tab of the class C++ edition dialog box, select the "Header -> Class [Class Members] -> Protected" node of the "Placement" hierarchy and type the intended code (Figure 53).

Figure 53. Selecting the placement and entering the code
Objecteering C++ Developer produces the following code for the "TaskWindow" class. The code entered for the "Header -> Class [Class Members] -> Protected" node of the "Placement" tree is injected into the protected part of the 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
{
namespace GUI
{
namespace Windows
{
class TaskWindow : public CWnd, public
GUI::ITaskView
{
//...
private:
CString
displayTitle;
public:
CDC
dc;
//associations
public:
TaskManagement::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);
const CArray<CDC,const CDC&>& getAttr1() const;
//non-modeled
members
protected:
//modifiable
zone @16224@30671900:2404@T
DECLARE_MESSAGE_MAP()
//modifiable
zone @16224@30671900:2404@E
};
}
}
}
Editing code in an external editor
You may prefer to input implementation code in an external editor that you can specify via the "External editor" Objecteering C++ Developer parameter.
To edit C++ code in an external
editor, you simply select a model element and click on the
"Edit header" or
"Edit body" buttons in the "C++"
tab of the auxiliary window (Figure 54).

Figure 54. The "Edit header" and "Edit body" buttons
The external editor containing the header or the body file contents is then opened. You can write implementation code in the editor. Once the editor is closed, the input code is transferred back into the model.
Note: Only the code entered between markers generated by Objecteering C++ Developer can be transferred back into the model. Any code input outside these markers is ignored!
The
"Edit header" and
"Edit body" buttons are available
for packages, classes, interfaces and operations.
For operations, the "Edit header" button opens the header of the owner class, and the "Edit body" button opens the body file of the owner file.
The "Edit body" button is not available for inline operations. The "Edit header" and "Edit body" buttons are not available for abstract operations, which do not have C++ code notes attached to them.
Updating externally modified code
You can modify the application code outside the Objecteering environment, for example, by editing it in your favorite IDE. Objecteering C++ Developer lets you update the code notes belonging to model elements from externally modified code.
To update the code notes attached to a
model element, just click on the
"Update" button in the
"C++" tab of the auxiliary window (Figure 55).

Figure 55. The "Update" button in the "C++" tab of the auxiliary window
Objecteering C++ Developer reads the file (where the element's code "lives") and transfers the code between markers back into the respective notes.
For example, as a result of a debug session, we have changed (directly in our IDE) the implementation of the assignment operator for the "Task" class to delete "to do" comments and clear containers, which store multiple instances of the "subTask" and "resource" association ends, before copying new values.
Task& Task::operator
=(const Task& value)
{
//modifiable zone @12396@30671900:226@T
//clear old values before copying new
ones !
subTasks.clear();
resource.clear();
std::copy(value.getSubTask().begin(),
value.getSubTask().end(), std::inserter(this.subTask,
this.subTask.begin()));
std::copy(value.getResource().begin(),
value.getResource().end(), std::inserter(this.resource,
this.resource.begin()));
this.owner =
value.getOwner();
this.name =
value.getName();
this.wbsCode =
value.getWbsCode();
//modifiable zone @12396@30671900:226@E
//modifiable zone @12397@30671900:227@T
return *this;
//modifiable zone @12397@30671900:227@E
}
Now select the assignment operator
and click on the
"Update" button in the "C++"
tab of the auxiliary window. Objecteering
C++ Developer then transfers our modified code back into the model. By using the "Code" tab of the
operation C++ edition dialog box, we can easily check that the code has indeed been
updated (Figure 56).

Figure 56. Checking that the code has been updated