All C++ stereotypes are derived from «C++Element».

Constraints described in this chapter are for information only; syntax of these constraints must be checked with the Object Constraint Language interpreter.

Invisible stereotypes «C++Class», «C++Operation», «C++Parameter», «C++Attribute», «C++LiteralValue», «C++Include», «C++Generalization», and «C++TemplateParameter» are used only to store C++ language properties. These stereotypes and their tag definitions are used by the Domain Specific Language Customization framework.

C++ Stereotypes

C++Operation

«C++Operation» is an invisible stereotype used to include language properties for any C++ operation.

NameMeta ClassConstraints

C++Operation

Operation

Function Const

 void f() const;

Constraint: Only valid for member function (member functions are operators that are declared as members of a class)

 if isQuery then
 stereotype-
>select(name=’C++Global’)->isEmpty()
Tag definitionType and default valueDescriptions
inlineboolean[1]=false

Function Inline

      inline a();
throw exceptionC++ThrowType[1]=any

Exception specification:

If operation.raisedExpression is not empty, the expression throw

is generated.

 void f() throw(int); 

If operation.raisedExpression is empty and expression throw value

is none, then a expression throw without argument is generated.

 void f() throw () 

If operation.raisedExpression is empty and expression throw value

is any, it does not generate a Keyword throw.

 void f();
virtualboolean[1]=false

Function Virtual

 virtual a(); 

Constraint: Only valid for member function and non static

 stereotype- 
>select(name=’C++Global’)
 ->isEmpty() and IsStatic =
false
volatileboolean[1]=false

Function Volatile

 void f() volatile;
funtionTryBlockboolean[1]=false

Function try block

void f() try{}

C++Operator

Stereotype «C++Operator»  is used to define a C++ operator function. This stereotype extends the stereotype «C++Operation». 

NameMeta ClassConstraints
C++OperatorOperation

Function Operator

 T& operator+(T& a);

Constraint: the name start with word operator

C++Constructor

Stereotype «C++Constructor» is used to define C++ Constructor. This stereotype extends the stereotype «C++Operation»

Name

Meta class

Constraints

C++Constructor

Operation

name = owner.name

Tag definition

Type and default value

Description

explicit

boolean[1]=false

Constructor Explicit 
 explicit a(); 

initialization list

String[0..1]

Constructor initialization:

 a() : x(1) {} 

C++Destructor

Stereotype «C++Destructor» is used to define C++ destructor. This stereotype extends Stereotype «C++Operation»

NameMeta ClassConstraints
C++DestructorOperation
name = “~”+owner.name

C++Parameter

«C++Parameter» is an invisible stereotype used to include language properties for any C++ function parameter. 

NameMeta ClassConstraints
C++ParameterParameter
Tag definitionType and default value

Description

C Type declarationboolean[1]=false

Declare parameter’s type in C style:

 void a(enum Day x); 

C++ style:

 void a(Day x);
Registerboolean[1]=false

Paramer Register

 void a(register int x);
ArrayString[0..1]

C++ Array definition

 void a(int x[2][2]);

C++ Attribute

An invisible stereotype «C++Attribute» is used to include language properties for any C++ variable.

NameMeta ClassConstraints

C++Attribute

Property

Constraint for code generation: it is valid to have a default value for any kind of attribute, but it is illegal to initialize a member variable within its definition.

 class A { int x = 1; };
 if defaultValue.size() > 0 then 
 owner.stereotype- 
 >exists(name='C++Global') or (isStatic = true and 
 typeModifiers.contains(“const”)) 
Tag definitionType and default valueDescriptions
abbreviated initializationboolean[1]=false

Initialize the attribute with the abbreviated form:

 int x(5); 

Constraint

 owner.stereotype-
>exists(name='C++Global')
bit fieldString[0..1]

Bit field

 int x:2; 

Constraint: Only valid for member function

 stereotype-
>select(name=’C++Global’) ->isEmpty() 
c type declarationboolean[1]=false

Declare attribute’s type in C style

C style:

 enum Day x; 

C++ style:

 Day x; 
containerString[0..1]

container of the attribute. $ character is replaced by the attribute type.

 vector<$> x; 
mutableboolean[1]=false

Attribute mutable modifier.

 mutable int x; 

Constraint: Only valid for member function

 stereotype->select(name=’C++Global’) 
 ->isEmpty()
arrayString[0..1]

C++ array definition

     int x[2][2]; 

C++LiteralValue

An invisible stereotype «C++LiteralValue» is used to include language properties for any C++ enum field.

NameMeta ClassConstraints

C++LiteralValue

EnumerationLiteral


Tag definitionType and default valueDescriptions
valueString[0..1]

Value definition of an enum field:

(A valid C++ expression)

enum Day {Mon = 2};

C++Friend

 Stereotype «C++Friend» is used to define C++ friend relationship.  

NameMeta ClassConstraints
C++FriendDependency

Client is Class or Operation and supplier is Class

(client.oclIsTypeOf(Class) or 
client.oclIsTypeOf(Operation)) and
supplier.oclIsTypeOf(Class)

C++Struct

Stereotype «C++Struct» is used to define C++ struct. 

NameMeta Class

C++Struct

Class

C++Typedef

Stereotype «C++Typedef» is used to define C++ typedef. 

NameMeta ClassConstraints

C++Typedef

Class

A typedef does not contain an operation and attribute

 feature->isEmpty() 

A «C++BaseType» dependency is defined

C++Union

Stereotype «C++Union» is used to define C++ union. 

NameMeta Class

C++Union

Class

C++Global

Stereotype «C++Global» is used to define global functions and variables (functions and variables outside a class/struct/union declaration). 

NameMeta ClassConstraints

C++Global

Class

Only one «C++Global» class into a package

     owner.ownedElement->select(
         stereotype->select(name=’C++Global’)).size()=1 

All operations and attributes are public

     feature->forAll(visibility = #public)

C++Namespace

Stereotype «C++Namespace» is used to define a C++ namespace. 

Name

Meta class


C++Namespace

Package


Tag definitionType and default value

Description

unique namespace name

String[0..1]

Unnamed namespace

namespace {} 

C++Extern

Stereotype «C++Extern» is used to define C++ extern variable. 

Name

Meta class

Constraints

C++Extern

Operation, Property

owner.stereotype->exists(name=’C++Global’) 
Tag definitionType and default value

Description

linkage

String[0..1]

Specification Linkage:

extern “C” 

C++FunctionPtr

Stereotype «C++FunctionPtr» is used to define C++ function pointer. 

Name

Meta class


C++FunctionPtr

Parameter, Property


Tag definitionType and default value

Description

signature

Operation

The signature of the function (C++ function pointer definition without the operation name)

member class

Class

The class used for pointer to member function.

C++FunctionSignature

Stereotype «C++FunctionSignature» is used as a container to model C++ function pointer. 

Name

Meta class

Constraints

C++FunctionSignature

Class

The class cannot have properties.

 properties->isEmpty() 

C++Class

Stereotype «C++Class» is an invisible stereotype used to include language properties for any C++ variable. 

Name

Meta class

C++Class

Class

C++BaseType

Stereotype «C++BaseType» is used to link base type of a typedef. 

Name

Meta class

Constraints

C++BaseType

Dependency

Client is type of Class with stereotype «C++Typedef».

Tag definitionType and default value

Description

type modifiers

String[0..1]

Type modifiers of the typedef or function pointer.

member class

Class[0..1]

Memberclass of typedef or function pointer.

array

String[0..1]

Array definition.

C++Include

Stereotype «C++Include» is used to keep information about the include type, for generating include and forward class declaration. 

NameMeta ClassConstraints

C++Include 

Association, Dependency, Generalization, Parameter, Property, TemplateBinding, TemplateParameter

Client is type of Component 

Tag definitionType and default valueDescription

header include

String

The value of the tag can be one of the following

  • None
  • User Include
  • System Include
  • Class Forward

implementation include

String

The value of the tag can be one of the following

  • None
  • User Include
  • System Include
  • Class Forward

The header include tag is used when the client component has header file extension, “*.h”; otherwise, the tag implementation include will be used.

The User Include tag value is used for generating user include, such as #include “test.h”.

The System Include tag value is used for generating system include, such as #include <string.h>

The Class Forward tag value is used for generating forward class declaration. 

C++TemplateParameter

Stereotype «C++Template Parameter» is used to keep type keyword between class and typename for template parameter declaration. 

NameMeta Class
C++TemplateParameterTemplateParameter
Tag definitionType and default valueDescription
type keyword

C++TemplateTypeKeyword=class

The value of tag is one of the following

  • class
  • typename

C++Generalization

Stereotype «C++Generalization» is used for information related to generalization and interface realization.

NameMeta Class
C++Generalization

Generalization, InterfaceRealization


Tag definitionType and default valueDescription
Inheritance Visibility

C++GeneralizationVisibility[1] = none 

The value of tag can be one of the following

  • None
  • public
  • protected
  • private

Example: class A : private B {};

Virtual Inheritance

boolean[1]=false