Types

In order to guarantee portability in any of the supported operating systems and architectures, the MARTe2 basic types shall always be used.

Basic types

Type

Meaning

uint8

8 bit unsigned integer.

uint16

16 bit unsigned integer.

uint32

32 bit unsigned integer.

uint64

64 bit unsigned integer.

int8

8 bit signed integer.

int16

16 bit signed integer.

int32

32 bit signed integer.

int64

64 bit signed integer.

char8

8 character.

bool

Boolean (size depends on the architecture).

float32

IEEE 754 single precision float.

float64

IEEE 754 double precision float.

uintp

Sufficiently large to hold a pointer address in the target architecture.

CString

A C string.

CCString

A C constant string.

TypeDescriptor

The TypeDescriptor is used to describe any of the MARTe basic types. In particular it can be used to describe a type using a string (e.g. “uint32” => UnsignedInteger32). It is also a core component of the AnyType described here below.

AnyType

The AnyType allows to encapsulate the value and to describe any of the MARTe2 variables. The AnyType is capable of constructing itself from any of the BasicTypes and can be used as a generic interface to a given function.

Warning

The AnyType has no internal memory! The instances of AnyType do not hold a copy of the actual value, but a pointer to it, so the value must be accessible during the life of the AnyType instance (be particularly careful when returning AnyTypes that represent automatic variables or variables that get out of scope!

void PrintType(const MARTe::AnyType &input) {
   using namespace MARTe;
   //Get the TypeDescriptor
   TypeDescriptor td = input.GetTypeDescriptor();
   uint32 numberOfBits = td.numberOfBits;
   //Automatically retrieve the name
   const char8 *const typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(td);
   //The logging mechanism will automatically print the value (note the %!) based on the TypeDescriptor.
   REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "Type: %s; NumberOfBits: %d; Constant? :%d, "
       "Value: %!", typeName, numberOfBits, isConstant, input);
}

...

uint16 anUInt16 = 116;
//Note that the AnyType is automatically constructed.
PrintType(anUInt16);
PrintType(32.0);

The AnyType is a key design element on all the components that accept many types and also require type interpretation (i.e. need to adapt their behaviour based on the type). Examples are the StructuredDataI Read and Write functions and the IOBuffer Printf.

Other types

Type

Meaning

BitBoolean

When used in an union allows to have the same effect of a struct with a 1 bit boolean (e.g. TypeDescriptor).

BitRange

When used in an union allows to have the same effect of a struct with bit fielded attributes (e.g. TypeDescriptor).

FractionalInteger

An helper class that is used to define integer types with non-standard bit sizes, such as uint3 or uint63.

Matrix

Fixed size matrix of values.

Vector

Fixed size array of values.

ZeroTerminatedArray

Describes a zero terminated array.

Lists

Type

Meaning

LinkedListable

Singly linked list.

StaticList

Templated version of the StaticListHolder.

StaticListHolder

Abstract Data Type (ADT) for an unbounded list.

CircularStaticList

Circular buffer implementation of the StaticList.

Example

The following example highlights the usage of the AnyType and of the TypeDescriptor.

AnyType example (TypesExample1)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 * @file TypesExample1.cpp
 * @brief Source file for class TypesExample1
 * @date 14/03/2018
 * @author Andre' Neto
 *
 * @copyright Copyright 2015 F4E | European Joint Undertaking for ITER and
 * the Development of Fusion Energy ('Fusion for Energy').
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved
 * by the European Commission - subsequent versions of the EUPL (the "Licence")
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
 *
 * @warning Unless required by applicable law or agreed to in writing, 
 * software distributed under the Licence is distributed on an "AS IS"
 * basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the Licence permissions and limitations under the Licence.

 * @details This source file contains the definition of all the methods for
 * the class TypesExample1 (public, protected, and private). Be aware that some
 * methods, such as those inline could be defined on the header file, instead.
 */

#define DLL_API

/*---------------------------------------------------------------------------*/
/*                         Standard header includes                          */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*                         Project header includes                           */
/*---------------------------------------------------------------------------*/
#include "AdvancedErrorManagement.h"
#include "ClassRegistryDatabase.h"
#include "ConfigurationDatabase.h"
#include "ErrorLoggerExample.h"
#include "Matrix.h"
#include "Object.h"
#include "Reference.h"
#include "ReferenceT.h"
#include "StreamString.h"
#include "Vector.h"

/*---------------------------------------------------------------------------*/
/*                           Static definitions                              */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*                           Method definitions                              */
/*---------------------------------------------------------------------------*/
namespace MARTe2Tutorial {
/**
 * @brief Print the input variable value, together with its characteristics.
 * @input[in] input the variable to print.
 */
void PrintType(const MARTe::AnyType &input) {
    using namespace MARTe;
    //Get the TypeDescriptor
    TypeDescriptor td = input.GetTypeDescriptor();
    bool isConstant = td.isConstant;
    uint32 numberOfBits = td.numberOfBits;
    //Automatically retrieve the name
    const char8 *const typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(td);
    //The logging mechanism will automatically print the value (note the %!) based on the TypeDescriptor.
    REPORT_ERROR_STATIC(MARTe::ErrorManagement::Information, "Type: %s; NumberOfBits: %d; Constant? :%d, "
            "Value: %!", typeName, numberOfBits, isConstant, input);
}

/**
 * @brief The instances of AnyType do not hold a copy of the actual value, but a pointer to it, so the value
 *  must be accessible during the life of the AnyType instance!
 */
MARTe::AnyType DoNotDoThisEver() {
    MARTe::uint16 aValue = 3;
    return aValue;
}

}

int main(int argc, char **argv) {
    using namespace MARTe;
    using namespace MARTe2Tutorial;
    SetErrorProcessFunction(&ErrorProcessExampleFunction);

    uint8 anUInt8 = 18;
    uint16 anUInt16 = 116;
    //Note that the AnyType is automatically constructed.
    PrintType(anUInt8);
    PrintType(anUInt16);
    PrintType(32.0);
    bool aBoolean = true;
    PrintType(aBoolean);
    //An AnyType can also be manually constructed (but this is not the main use case)
    AnyType at(UnsignedInteger16Bit, 0u, &anUInt16);
    PrintType(at);

    (void) DoNotDoThisEver();
    return 0;
}

Instructions on how to compile and execute the example can be found here.