Book a Demo

Author Topic: Code Generation and Collection Classes  (Read 3607 times)

Andreas_G

  • EA User
  • **
  • Posts: 125
  • Karma: +0/-0
  • And that's the way the cookie crumbles.
    • View Profile
Code Generation and Collection Classes
« on: September 22, 2005, 01:35:15 am »
Hi all,

I've defined std::vector<#TYPE#> as my Collection Class for Ordered Multiplicity.

When I generate code for such an association it generates something like

Code: [Select]
std::vector<MyType>* m_theMyType;
instead of
Code: [Select]
std::vector<MyType*> m_theMyType;
I tried to solve this problem by adding an additional attribute with the same name (m_theMyType) and a multiplicity from 0..*.

But it seems that the collection class is only used for "real" assiciations and not for attributes.

And when I try to set the container type by hand at the attribute the code generation produces me

Code: [Select]
MyType m_theMyTypestd::vector<#TYPE#>
Did somebody know where is my bug?
bye
Andreas

Andreas_G

  • EA User
  • **
  • Posts: 125
  • Karma: +0/-0
  • And that's the way the cookie crumbles.
    • View Profile
Re: Code Generation and Collection Classes
« Reply #1 on: September 22, 2005, 02:02:03 am »
After I changed the "Attribute Declaration" template it seems to work.

Here is the changed template (the red parts are changed)

[size=16]%if classStereotype == "enumeration"%
%PI=""%
%attName%
%attInitial ? " = " value%
%endTemplate%

%PI=" "%
%attStatic=="T" ? "static" : ""%
%attConst=="T" ? "const" : ""%
%attVolatile=="T" ? "volatile" : ""%
%attTag:"mutable"=="true" ? "mutable" : ""%
%attStereotype=="struct" ? "struct" : ""%
$type=%attQualType? value : "int"%
$type=%REPLACE($type,".","::")%
$qualType=%packagePath% + "::" + %attType%
%if genOptCPPGenNamespace == "T" and $type == $qualType%
$type=%attType%
%endIf%
$type += %attContainment=="By Reference" ? "*" : ""%
%PI=" "%
%if attCollection == "T" and attContainerType != ""%
$container = %REPLACE(attContainerType, "#TYPE#", $type)%
$type = $container
%endIf%
$type
%attName%;
[/size]

I did not know if this is the only/correct/best solution to solve my problem. But it seems to work.

If somebody knows an other solution, and how it works without adding an special attribute but with an association, I'll be happy.
bye
Andreas