Namespace Declaration
The namespace is a declaration region and can be seen as a virtual folder. Namespaces
provide a method for preventing name conflicts in large projects.
Since C++11, the inline namespace is
ignored.
A package with the stereotype “C++
Namespace” is expected to be created with the name of the namespace for any declared
namespace in the code.
The “unique namespace name”
attribute of the “C++ Namespace” stereotype of the created package must have the name of
the namespace.
Example of a namespace declaration: C++:
namespace ns1
{
namespace ns2
…
{
}
UML:
RootPackage
|-[package]ns1 [[C++ Namespace]]
|-[package]ns2 [[C++ Namespace]]
Example of a namespace declaration since C++17: C++:
namespace ns1::ns2{
…
}
UML:
RootPackage
|-[package] ns1 [[C++ Namespace]]
|-[package]ns2 [[C++ Namespace]]
If a class is defined in a
namespace, the UML class is created under the package corresponding to the namespace.
Example of a class declaration with namespace: C++:
namespace ns1 {
class MyClass{
};
}
UML:
RootPackage
|-ns1[package]
|-[class]MyClass
Class
A UML class is created for
each declared C++ class.
Example of a class declaration: C++:
class MyClass{
};
UML:
RootPackage
|-[class]MyClass
| C++ Element |
UML Element |
| Inheritance |
If a class inherit from
another class, a generalization relation is created from the class to the other
class.
The visibility of the
inheritance is used in the created generalization relation.
See: https://en.cppreference.com/book/intro/inheritance
Example of a class declaration with generalization: C++:
class B {};
class A : public B {
};
UML:

|
| Nested class |
A declaration of a class/struct or union appearing within another class is known as a
nested class. https://en.cppreference.com/w/cpp/language/nested_types
A UML class is generated
under the parent class for C++ nested class.
|
| Abstract class |
A class is abstract if one of his functions is pure virtual. See https://en.cppreference.com/w/cpp/language/abstract_class.html
|
| Friend class |
Supported.
|
| Global functions and variables |
A “global” class is created
with the name of the files and with “C++ Global” stereotype when code contains
functions, variables and macros declared outside of any class (global function,
global variables, and Macro “#define”).
“global” class is created
under the root package.
Example of global functions and variables: C++ : file.h
void globalFunction();
UML:

|
#Include Preprocessor Directive
If a file contains one or multiple
class definitions and contains #include directives to other files containing classes
definitions, a usage relation is created between UML artifacts representing files. The
usage relation has the stereotype “C++Include”.
If #include directive is declared
using a blank space “ “, the “header include” attribute is configured with the value “User
Include“.
Class Constructor
An operation with the stereotype
“C++ Constructor” is generated for any constructor declared in the code of the class.
Example of a constructor C++:
class Door{
Door();
};
UML :
[class]Door
|-[operation]Door [[C++ Constructor]]
The Initializer List of a
constructor is replicated in the “Initialization list” field of the “C++ Constructor”
stereotype applied to the operation.
Example of a constructor with Initialization list: C++:
class Door{
const int t;
Door(int t):t(t){};
};
UML :
[class]Door
|-[operation]Door [[C++ Constructor,Initialization list=t(t)]]
The “explicit” specifier of a
constructor is replicated in the “Explicit” field of the “C++ Constructor” stereotype
applied to the operation.
Example of a constructor with explicit specifier: C++:
class Door{
explicit Door(){};
};
UML :
[class]Door
|-[operation]Door [[C++ Constructor,Explicit=true]]
See Function Argument.
Class Destructor
An operation with the stereotype
“C++ Destructor” is generated for any destructor declared in the code of the class.
Example of a constructor: C++:
class Door{
~Door();
};
UML :
[class] Door
|-[operation] Door [[C++ Destructor]]
Variable (Class Member Variable and Global Variable)
Class Property
-
A property is generated in the
UML class for each member variable of the cpp class.
-
The properties created from
the reverse code analysis keep the order in which there are read.
-
The visibility of the property
is configured according to the declaration in the code for that variable.
-
The variable type is used to
configure the property type.
Example of a property: C++:
class Door{
private:
bool isLocked;
};
UML :
[class] Door
|-[property] isLocked:bool, Visibility=private
For more information on the types management, see Standard Data Types.
-
The default value of the
property is a string set, it is defined as in the code.
Example of a property: C++:
enum LockEnum {
Open,
Closed
};
class Door{
LockEnum lockStatus = Closed;
};
UML :
[class] Door
|-[property] lockedStatus:LockEnum,Default value=Closed
-
The default value of the
property is a string set as defined in the code.
Pointer and Reference Declaration
-
The Type
Modifier property attribute is set to * for a variable
declared as a pointer.
-
The Type
Modifier property attribute is set to & for a
variable declared as a reference.
-
The Type
Modifier property attribute is set to && for a
variable declared as a value reference.
-
The Type
Modifier property attribute is set to ** for a variable
declared as a double pointer.
-
The Type
Modifier property attribute is set to *& for a
variable declared as a reference to pointer.
Example of a pointer and reference: C++:
class MyClass{
chat *pointerVar;
int &referenceVar;
};
UML :
[class] MyClass
|-[property] pointerVar:char, type modifier=*
|-[property] referenceVar:int, type modifier=&
Declaration
Multiplicity attribute of property
is set to * for a variable declared as a list or a vector.
Example 1 of a List declaration: C++:
#include <list>
class MyClass{
std::list<bool> myList;
};
UML:
[class] MyClass
|-[property] myList:bool, multiplicity=*
Example 2 of a List declaration: C++:
#include <vector>
class MyClass{
std::vector<bool> myVector;
};
UML:
[class] MyClass
|-[property] myVector:bool, multiplicity=*
Array Declaration
For a variable declared as an
array, the corresponding property is created with the stereotype “C++ Attributes”, and
“Array” attribute is set with the size of the array.
Example of an array declaration: C++:
#include <array>
class MyClass{
std::array<int,2> myArray;
};
UML:
[class] MyClass
|-[property] myArray:int [[C++ Attributes:Array=2]]
Const
For a variable declared as const,
the corresponding property is created with the “Is Read Only” attribute set to true.
Example of a const declaration: C++:
class MyClass{
const int myConst;
};
UML:
[class] MyClass
|-[property] myConst:int,”Is Read Only”=true
Static
For a variable declared with the
storage class “static”, the corresponding property is created with an “Is Static”
attribute set to true.
Example of a static declaration: C++:
class MyClass{
static int myStatic;
};
UML:
[class] MyClass
|-[property] myStatic:int,”Is Static”=true
Mutable
For a variable declared with the
storage class “mutable”, the corresponding property is created with the stereotype “C++
Attributes”, and the “Mutable” attribute is set to true.
Example of a mutable declaration: C++:
class MyClass{
mutable int myMutable;
};
UML:
[class] MyClass
|-[property] myMutable:int,”Is Static”=true
Bit Field
For a variable declared using a
bit fields pattern, the corresponding property is created with the stereotype “C++
Attributes”, and the “Bit Field” attribute is set with the size of the bit field.
Example of a bit field: C++:
class MyClass{
int myVar:20;
};
UML:
[class] MyClass
|-[property] myVar:int [[C++ Attributes:”Bit Field”=20]]
Extern
For a variable declared with the
storage class “extern”, the corresponding property is created with the stereotype “C++
Extern”.
Example of an extern declaration: C++:
extern int myExtern;
UML:
[class]
|-[property] myExtern:int [[C++ Extern]]
Volatile
Function Pointer
Multiple Declarations
For a variable declared with a
complex collection of storage classes or declarations, the Type Modifier attribute is
used to register the complete declaration. The dollar “$” character replaces the type
name.
Note:
Not supported: Const on pointer const int* const.
Example of an extern declaration: C++:
class MyClass{
const int* myConstPtr;
};
UML:
[class] MyClass
|-[property] myConstPtr:type=int, Type modifier=”const$*”
Function Declaration (Class Member Function & Global
Function)
-
An operation is generated in the
UML class for each member function of the C++ class.
-
The visibility of the operation is
configured according to declaration in the code for that variable.
Example of a function: C++:
class Door{
private:
void lock();
};
UML :
[class] Door
|-[operation] lock:void, Visibility=private
| Element |
Description |
| Inline |
For a function declared as
inline, the corresponding operation is created with the stereotype “C++
Operation”, and the “Inline” attribute is set to true.
Example of inline: C++:
class Door{
private:
inline void lock();
};
UML :
[class] Door
|-[operation] lock:void[[C++ Operation, Inline=true]]
|
| Virtual |
For a function declared as
virtual, the corresponding operation is created with the stereotype “C++
Operation”, and the “Virtual” attribute is set to true.
Example of virtual: C++:
class Door{
private:
virtual void lock();
};
UML :
[class] Door
|-[operation] lock:void[[C++ Operation, Inline=true]]
|
| Volatile |
For a function declared as
volatile, the corresponding operation is created with the stereotype “C++
Operation”, and the “Volatile” attribute is set to true.
Example of volatile: C++:
class Door{
private:
void lock() volatile;
};
UML :
[class] Door
|-[operation] lock:void[[C++ Operation, Volatile=true]]
|
| Static |
For a function declared with
the storage class “static”, the corresponding operation is created with an “Is
Static” attribute set to true.
Example of a static declaration: C++:
class MyClass{
static void lock();
};
UML:
[class] MyClass
|-[operation] lock:void,”Is Static”=true
|
| Const |
For a function declared as
const, the corresponding operation is created with an “Is Query” attribute set to
true.
|
| Friend |
Not supported.
For a function declared as
friend in a class, a usage relation with “C++ Friend” stereotype is created
between the operation in the class declaring it and the current class.
|
| Operator |
For a function having the
name “operator<overloaded_operator>”, an operation is created with the C++
Operator” stereotype. <overloaded_operator> can have the following
values:

Example of an operator: C++:
class MyClass{
void operator+() const;
};
UML:
[class] MyClass
|-[operation] operator+:void[[C++ Operator]]
|
| Exception |
According to standard C++98 and C++03, an operation declares that it can throws
an exception. This declaration is deprecated since C++11.
Since C++11, an operation can declare that it does not throw any exception with
the suffix “noexcept”.
-
Not supported: For a
function declared with the suffix noexcept (since C++11), the corresponding
operation is created with the stereotype “C++ Operation” and “Throw exception”
attribute is set to “none”.
-
Not supported: For a
function declared with the suffix noexcept (<condition>) (since C++11), the
corresponding operation is created with the stereotype “C++ Operation” and
“Throw exception” attribute is set to “none” and condition is configured
somewhere.
-
Not supported:
For a function declaring an exception without any argument (C++98 and C++03
only), the corresponding operation is created with the stereotype “C++
Operation” and “Throw exception” attribute is set to “any”.
- Not supported: For a
function declaring an exception with arguments (C++98 and C++03 only), the
corresponding operation is created with the stereotype “C++ Operation”, “Throw
exception” attribute is set to “any”, and the “Raised exception” attribute is
set with the value of the exception arguments.
|
| Getter / Setter |
- Not supported: For a
function having annotation @getter prior to its declaration, the corresponding
operation is created with the stereotype “getter” and “getter/setter for
attribute” is configured with the corresponding property.
- Not supported: For a
function having annotation @setter prior to its declaration, the corresponding
operation is created with the stereotype “getter” and “getter/setter for
attribute” is configured with the corresponding property.
|
Function Argument
- For a function declaring a
returned value, a parameter is generated with a direction set as “return”.
- For each argument of a function,
a parameter is generated with a direction set as “in” or “inout”. see Const.
Example of an operation with
arguments: C++:
class MyClass{
bool myFct1(int arg);
bool myFct2(int * arg);
bool myFct3(const int * arg);
};
UML :
[class] MyClass
|-[operation] myFct1
|-[parameter] bool, direction=return
|-[parameter] arg, type=int, direction=in
|-[operation] myFct2
|-[parameter] bool, direction=return
|-[parameter] arg, type=int, modifier=*, direction=inout
|-[operation] myFct3
|-[parameter] bool, direction=return
|-[parameter] arg, type=int, modifier=*, direction=in
- The argument type is used to
configure the parameter type.
Example of an operation with
arguments: C++:
class MyClass{
bool myFct(int arg);
};
UML :
[class] MyClass
|-[operation] myFct
|-[parameter] bool, direction=return
|-[parameter] arg, type=int, direction=in
For more information on the types management, see Standard Data Types
| Element |
Description |
| Pointer and reference declaration |
- “Type Modifier” attribute
of parameter is set to “*” for an argument declared as a pointer.
- “Type Modifier” attribute
of parameter is set to “&” for an argument declared as a reference.
Example of a pointer and reference: C++:
class MyClass{
void myFct(int *pointer Arg);
void myFct2(int &referenceArg);
};
UML :
[class] MyClass
|-[operation] myFct:void
|-[parameter] : type=void, direction=return
|-[parameter] pointerArg: type=int, direction=inout, type modifier=*
|-[operation] myFct2:void
|-[parameter] : type=void, direction=return
|-[parameter] referencearg:int, direction=inout, type modifier=&
|
| List declaration |
The Multiplicity attribute
of a parameter is set to “*” for an argument declared as a list. Example of a list
declaration: C++:
#include <list>
class MyClass{
void myFct(std::list<bool> myList);
};
UML:
[class] MyClass
|-[operation] myFct:void
|-[parameter] myList: type=bool, direction=in, multiplicity=*
|
| Array declaration |
For a argument declared as
an array, the corresponding parameter is created with the stereotype “C++
Attributes”, and the “Array” attribute is set with the size of the array. Example
of an array declaration: C++:
#include <array>
class MyClass{
void myFct(std::array<int,2> myArray);
};
UML:
[class] MyClass
|-[operation] myFct:void
|-[parameter] myArray: type=int [[C++ Attributes:Array=2]]
|
| Const |
For an argument declared as
const, the corresponding parameter is created with direction set to “in”
Example of a const declaration: C++:
class MyClass{
void myFct(const int myConst);
};
UML:
[class] MyClass
|-[operation] myFct:void
|-[parameter] myConst: type=int,”direction”=”in”
|
| Variable length parameter list |
- For a variable length
function, the latest parameter is created with the name “…” without any
type.
Example of a variable parameter list: C++:
class MyClass{
void myFct(const int myConst, ...);
};
UML:
[class] MyClass
|-[operation] myFct:void
|-[parameter] myConst: type=int,”direction”=true
|-[parameter] …
- Not supported: For a
return type declared with the modifier volatile, the corresponding return
parameter is created with the stereotype “C++ Parameter”, and the “volatile”
attribute set to “true”.
|
Function Definition (Class Member Function and Global Function)
Standard Data Types
When a model element (eg: property,
parameter) references a type, the reference is mapped on standard types for the following types:
- char
- bool
- int
- double
- float
- long
- long double
- long int
- short int
- signed char
- unsigned char
- unsigned int
- unsigned long int
- unsigned short int
- wchar_t
- void
The following table describes the reference used for each type:

Structure
A UML class
with the stereotype “C++ Struct” is created for each declared struct.
A property is created for each
field of the struct.
Example of a struct definition: C++:
struct Struct{
unsigned int data1;
};
UML:
[class] Struct [[C++ Struct]]
|-[property]data1:type=C++ ANSI profile::datatypes::unsigned int
Enumeration
-
An enumeration is generated for
an enum in the code.
-
An enumeration literal with the
sterotype C++LiteralValue is generated for each field of the enum.
-
The value attribute of
C++LiteralValue is configured with the value of the field, if
any.
Example of an enum definition: C++:
enum ControlEnum{
Idle,
Open,
Close
};
UML:

-
Since C++11, an enum can be
defined using enum class. Such pattern is supported when detecting enums in code.
Example of an enum definition with enum class: C++:
Enum class ControlEnum{
Idle,
Open,
Close
};
UML:

Union
-
An UML class with the
stereotype “C++ Union” is created for each declared union.
-
A property is created for each
field of the union.
Example of a union definition: C++:
union MyUnion{
int intVal;
float realVal;
char charVal;
};
UML:
[class] MyUnion [[C++ Union]]
|-[property]data1:type=C++ ANSI profile::datatypes::int
|-[property]data1:type=C++ ANSI profile::datatypes::float
|-[property]data1:type= UML Standard Profile::MagicDraw Profile::datatypes::char
Alias (Typedef and Using)
For an alias to another type (via
typedef or using), a Data Type is generated and a generalization relation is created
between this Data Type and the Data Type source of the alias.
Example of a typedef declaration: C++:
class MyClass{
typedef int myInt;
};
UML:
[class] MyClass
|-[data type] myInt
|- [dependency] Target=”UML Standard Profile::MagicDraw Profile::datatypes::int”
Example using declaration: C++:
class MyClass{
using myInt = unsigned int;
};
UML:
[class] MyClass
|-[data type] myInt
|- [dependency] Target=” C++ ANSI profile::datatypes::unsigned int”
| Element |
Description |
| typedef of an array |
For an alias to another
type (via typedef or using) declaring an array, a Data Type is generated with
the“C++ Attributes” and “Array” attribute is set with the size of the array and a
generalization relation is created between this Data Type and the Data Type source
of alias.
Example of an array declaration: C++:
class MyClass{
typedef int array[3];
};
UML:
[class] MyClass
|-[data type] array [[C++ Attributes:Array=3]]
|- [dependency] Target=”UML Standard Profile::MagicDraw Profile::datatypes::int”
|
| typedef of a struct |
For an alias (via typedef or using) declaring a struct, a class is generated
according to Structure and applies " An UML class with the
stereotype “C++ Union” is created for each declared union".
For an alias (via typedef
or using) declaring a struct, if the struct is anonymous, the created class has
the name of the alias with the suffix “Struct”.
Example of a structure definition: C++:
typedef struct{
unsigned int data1;
} MyStructStruct ;
UML:
[data type] MyStructStruct
|-[generalization] Target=<>
|-[class] <> [[C++ Struct]]
|-[property]data1:type=C++ ANSI profile::datatypes::unsigned int
|
| typedef of an enum |
For an alias (via typedef or using) declaring an enum, a class is generated
according to Enumeration and applies " An UML class with the
stereotype “C++ Union” is created for each declared union".
For an alias (via typedef
or using) declaring an enum, if the enum is anonymous, the created enumeration has
the name of the alias with the suffix “Enum”.
Example of an enum definition: C++:
typedef enum {
Idle,
Open,
Close
} Control;
UML:

|
| typedef of a union |
For an alias (via typedef or using) declaring a union, a class is generated
according to Union and applies " An UML class with the
stereotype “C++ Union” is created for each declared union".
For an alias (via typedef
or using) declaring an union, if the union enum is anonymous, the created class
has the name of the alias with the suffix “Union”.
Example of an union definition: C++:
typedef union {
int intVal;
float realVal;
char charVal;
} MyUnion;
UML:
[data type] MyUnion
|-[generalization] Target=<>
|-[class] <>[[C++ Union]]
|-[property]data1:type=C++ ANSI profile::datatypes::int
|-[property]data1:type=C++ ANSI profile::datatypes::float
|-[property]data1:type= UML Standard Profile::MagicDraw Profile::datatypes::char
|
#define preprocessor directive
A property is created extended with
the stereotype “C++Macro”. The property has the name of the macro, the expansion of the
macro is set in the default value of the property. The property is added to the Global
class representing the file. C++: file.h
#define VAL 1
UML:
[class] file.h [[C++Global]]
|-[property] VAL defaultValue=1
Template
Not
supported.
|