Type definition syntax

 

General structure and interpretation rules

An ACT type definition consists of the <type> XML element, which has a number of attributes containing important metainformation about the type, and which contains a <template> element defining the template for type declaration.

 

An ACT type definition may also contain one or more <include> elements, containing information about #include directives that may be required in order to use this type in generated code.

 

When Objecteering C++ Developer generates code for a UML attribute, parameter or association end,  it considers the type definitions available in the current library path, and matches them against the name of the UML element designated as being the type of the attribute/parameter/association end being generated, as well as other decorations (for example, {Cxx.Container} tagged values, …).

 

You can generate the type of your choice by modifying the Cxx2Core.types.act file.  When a personalized type is added to an element, the {Cxx.BasicType} tagged value is added to the element in question, with the chosen type as parameter.

 

 

Example

The following is an example of "attribute" and "container" type definitions.

 

<type id="string" name="std::string" kind="attribute">

   <include path="string"/>

   <template id="tpl_string_decl">

        <body>std::string</body>

   </template>

</type>

<type id="vector" name="std::vector" kind="container" container-kind="OrderedCollection" decoration-hint="coll" class-storage="by-pointer">

   <include path="vector"/>

   <template id="tpl_vector_decl">

        <body>$containerTypeName&lt;$valueTypeName&gt;</body>

        <define id="containerTypeName" expr="typeDef.getAttribute(&quot;name&quot;)"/>

        <define id="valueTypeName" expr="containedType"/>

   </template>

</type>

 

 

<type> element

As described above, this element contains a <template> element for a type declaration (see "Template syntax"), and zero or more <include> elements, described below. It also contains the following attributes:

·         id: This contains a string identifier of the type, which should be unique within a type library (but can be overridden in a different library).  This attribute is used when searching for a type definition by UML type/classifier name, referencing a type, ….

·         name: This contains a string with the name of the type in the target language.  For example, for the STL string type, the <type> element could contain id="string", name="std::string".

·         kind: This specifies the "kind" of the type being defined (either "attribute" or "container").  This indication is used in the automatic decoration process, and is also used to present different type kinds in different lists in the GUI.

·         container-kind: This is another indicator allowing the automatic decorator to automatically find the best match among the types available to the UML model.  Using multiplicity, IsClass, other standard UML attributes and custom UML decorations, Objecteering C++ Developer determines the "ideal" container kind to represent the UML feature being generated (i.e. "OrderedMap").  It then tries to find a type with a matching container-type attribute among the available types. If no such type is found, it tries to find a "next to ideal" container kind.  The order in which "less ideal" container types are considered is defined in the Cxx2ContainerDegradation map.

·         decoration-hint: This is yet another auxiliary type classifier, helping to identify whether the type is a collection ("coll") or an associative container ("map").

·         class-storage: This designates if the members of the type should be stored as pointers ("by-pointer") or as parts of the class ("by-value").

·         storage-proc: This can be used as an alternative to class-storage.  It contains the name of the J method that is expected to return the previously described values, after run-time analysis of the UML model and type definition.

 

 

<include> element

The <include> element contained within the type element defines that an #include directive should be added to the file where this type is used. The element contains the following attributes:

·         path: This is the path to the file to include, as used with the #include directive.