Default Value for Part Redefinitions (C++ code)
For parts (attributes and roles) it is possible to set a Default Value not only on the object itself, but also on redefinitions of the object. Where this has been done, the C++ generator will produce code which initializes the redefined part. It does this by adding various classes and constructors or modifying constructors of the classes which contain the redefined parts.
An attribute in the following example, has had a Default Value set. All other Default Value properties have been set on redefinitions.
Most parts shown in the composite structure diagram have been redefined by the setting of a Default Value. However, Class4.c3a has been redefined by the addition of m_Int which is not a member of Class3 (the type of Class4.c3a.) Similarly, Class4.c3a.c2b (typed by Class2) has been redefined by the addition of m_Long.
The approach taken by the generator is that the constructor of any class used as a part with in-context default values at some depth within it will be generated with parameters which are used in the initializer list. The constructor of any class not used as a part but which contains parts as described above will be generated without parameters and the in-context default values will be used in the initializer list. If the constructor has been modelled then it will be modified in accordance with the above. If no constructor has been modelled then one will be fabricated for this purpose. Furthermore, parts which have been redefined by the addition of parts which do not exist in the part type (e.g. Class4.c3a & Class4.c3a.c2b) will have classes fabricated which do contain the additional parts and constructors required for initialization.
So, in this example, the modelled classes will have the following constructors:
Class1::Class1(
const int Class1_m_Int,
const float Class1_m_Float
):
m_Float(Class1_m_Float), m_Int(Class1_m_Int)
{
}
Class2::Class2(
const float Class2_c1b_m_Float,
const float Class2_c1a_m_Float,
const int Class2_c1a_m_Int
const int Class2_c1b_m_Int
):

c1a(Class2_c1a_m_Float, Class2_c1a_m_Int), c1b(Class2_c1b_m_Float, Class2_c1b_m_Int)
{
}
Class3::Class3(
const float Class3_c2a_c1b_m_Float,
const float Class2_c2b_c1b_m_Float,
const float Class3_c2a_c1a_m_Float,
const float Class3_c2b_c1a_m_Float,
const int Class3_c2b_c1a_m_Int,
const int Class3_c2a_c1b_m_Int,
const int Class3_c2a_c1a_m_Int,
const int Class3_c2b_c1b_m_Int
):
c2a(Class3_c2a_c1a_m_Float, Class3_c2a_c1a_m_Int, Class3_c2a_c1b_m_Float,
Class3_c2a_c1b_m_Int), c2b(Class3_c2b_c1a_m_Float, Class3_c2b_c1a_m_Int, Class3_c2b_c1b_m_Float, Class3_c2b_c1b_m_Int)
{
}
Class4::Class4() :
m_Int(2112), c3a(1.0, 1, 2.0, 2, 3.0, 3, 4.0, 4), c3b(5.0, 5, 6.0, 6, 7.0, 7, 8.0, 0)
{
}
The fabricated classes will be:
// File : .\Class3_Class4_c3a.h
#ifndef __Class3_Class4_c3a
#define __Class3_Class4_c3a
#include "Class3.h"
#include "Class2_Class4_c3a_c2a.h"
#include "Class2_Class4_c3a_c2b.h"

#include "int.h"

class Class3_Class4_c3a : public Class3
{

public:
// Public|Package operations
Class3_Class4_c3a(
const float Class3_c2a_c1b_m_Float,
const float Class3_c2b_c1b_m_Float,
const float Class3_c2a_c1a_m_Float,
const float Class3_c2b_c1a_m_Float,
const int Class3_c2b_c1a_m_Int,
const int Class3_c2a_c1b_m_Int,
const int Class3_c2a_c1a_m_Int,
const int Class3_c2b_c1b_m_Int
);
private:
// Private attributes
int m_Int;
Class2_Class4_c3a_c2a c2a_Class4_c3a;
Class2_Class4_c3a_c2b c2b_Class4_c3a;
};
#endif
// File : .\Class3_Class4_c3a.cpp
#include "Class3_Class4_c3a.h"

// Operation implementations
Class3_Class4_c3a::Class3_Class4_c3a(
const float Class3_c2a_c1b_m_Float,
const float Class3_c2b_c1b_m_Float,
const float Class3_c2a_c1a_m_Float,
const float Class3_c2b_c1a_m_Float,
const int Class3_c2b_c1a_m_Int,
const int Class3_c2a_c1b_m_Int,
const int Class3_c2a_c1a_m_Int,
const int Class3_c2b_c1b_m_Int
):
m_Int(1970), Class3(Class3_c2a_c1b_m_Float, Class3_c2b_c1b_m_Float,
Class3_c2a_c1a_m_Float, Class3_c2b_c1a_m_Float, Class3_c2b_c1a_m_Int,
Class3_c2a_c1b_m_Int, Class3_c2a_c1a_m_Int, Class3_c2b_c1b_m_Int)
{
}
// File : .\Class2_Class4_c3a_c2b.h
#ifndef __Class2_Class4_c3a_c2b
#define __Class2_Class4_c3a_c2b

#include "Class2.h"

#include "int.h"

class Class2_Class4_c3a_c2b : public Class2
{

public:

// Public|Package operations

Class2_Class4_c3a_c2b(
const float Class2_c1b_m_Float,
const float Class2_c1a_m_Float,
const int Class2_c1a_m_Int,
const int Class2_c1b_m_Int
);

private:
// Private attributes
long m_Long;

};
#endif

// File : .\Class2_Class4_c3a_c2b.cpp
#include "Class2_Class4_c3a_c2b.h"

// Operation implementations

Class2_Class4_c3a_c2b::Class2_Class4_c3a_c2b(
const float Class2_c1b_m_Float,
const float Class2_c1a_m_Float,
const int Class2_c1a_m_Int,
const int Class2_c1b_m_Int
):
m_Long(1980), Class2(Class2_c1b_m_Float, Class2_c1a_m_Float, Class2_c1a_m_Int,
Class2_c1b_m_Int)
{
}
// File : .\Class2_Class4_c3a_c2a.h
#ifndef __Class2_Class4_c3a_c2a
#define __Class2_Class4_c3a_c2a

#include "Class2.h"

#include "int.h"

class Class2_Class4_c3a_c2a : public Class2
{

public:

// Public|Package operations

Class2_Class4_c3a_c2a(
const float Class2_c1b_m_Float,
const float Class2_c1a_m_Float,
const int Class2_c1a_m_Int,
const int Class2_c1b_m_Int
);

};
#endif

// File : .\Class2_Class4_c3a_c2a.cpp
#include "Class2_Class4_c3a_c2a.h"

// Operation implementations

Class2_Class4_c3a_c2a::Class2_Class4_c3a_c2a(
const float Class2_c1b_m_Float,
const float Class2_c1a_m_Float,
const int Class2_c1a_m_Int,
const int Class2_c1b_m_Int
):
Class2(Class2_c1b_m_Float, Class2_c1a_m_Float, Class2_c1a_m_Int, Class2_c1b_m_Int)
{

}
Was this helpful?