Book a Demo

Author Topic: generate code for attribute default values?  (Read 5516 times)

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
generate code for attribute default values?
« on: May 20, 2005, 02:01:21 am »
Hello everybody,

One more question.
I'm trying to generate code for default values for class attributes. But EA seems to ignore that and does not generate code for them.  :'(

When defining an initial value of 10 for an "int" attribute in my class diagram...


+----------------------------+
|                   MyClass                        |
+----------------------------+
| - m_IntAttribute: int = 10 |
+----------------------------+
| + MyClass()                               |
| + ~MyClass()                              |
+----------------------------+

...I would like to have the following code generated:

MyClass::MyClass():
m_IntAttribute(10)
{

}

Does somebody know how to achieve this?

Thanks in advance for any help!

have a nice day,
Best regards,
Manfred

Goarnisson

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: generate code for attribute default values?
« Reply #1 on: May 20, 2005, 02:52:38 am »
U need use : Configuration>Code Generation Template.

U select language u use : C++, C#, Java ...(C++ for you)

And then in "Attribute Declaration", u need to add the line :
%attInitial ? "(" value ")"%

for example : with C# it's :
%attInitial ? " = " value%

Hope, have help you

Guillaume Goarnisson

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
Re: generate code for attribute default values?
« Reply #2 on: May 20, 2005, 02:56:37 am »
Hi Guillaume,

Thanks for your reply!
I'll give it a try!

I'll post again if I don't get it sorted... ;D

have a nice weekend!
Best regards,
Manfred

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: generate code for attribute default values?
« Reply #3 on: May 22, 2005, 03:54:35 pm »
Hello Guillaume,

The C++ default values are a bit trickier to handle than the C# etc ones and neither will be synchronised.

For non-static default values you will need to create a new custom template, and execute a list over it in the class body template where the default constructor is being generated.

What you need to add will look something like this.

Code: [Select]
$defaults = %list="Attribute__Default" @separator=", " attStatic != "T" and attDefault != ""%
%if $defaults != ""%
: $defaults


If you add this to the method declaration template, when the operation name equals the class name instead of the opTag:"initializer" code then it should even synchronise.

To generate the static attribute initialisation again you will need a custom template and list over all the static attributes with default values.

Hope that helps.

Simon

golyshkin

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: generate code for attribute default values?
« Reply #4 on: July 08, 2005, 02:02:16 pm »
I did it sir,

So u need create new template Attribute__Implement
$COMMENT = "Its script implement initialization for constructors"
%PI=" "%

%if attStatic==""%

$COMMENT = "Not static initialization"
$type=%attQualType%
$type=%REPLACE($type,".","::")%
$qualType=%packagePath% + "::" + %attType%
%PI=""%
%attContainment=="By Reference" ? "&" : ""%
%attName%( %attInitial% )

%else%

$COMMENT = "Static initialization"

%endIf%

Replace Class Body Implement template to following code
$templateArgs=%list="ClassParameter" @separator=", "%
%if $templateArgs != ""%
$templateArgs="<" + $templateArgs + ">"
$templ="template" + $templateArgs
%endIf%
$consPrefix=$templ + "\n" + %classQualName% + "::"

%if classStereotype != "struct"%

%PI=" "%
%if genOptGenConstructor == "T" and genOptGenConstructorInline != "T" and classHasConstructor != "T"%
$defaults = %list="Attribute__Implement" @separator=", " attInitial !=""%
$consPrefix%className%()
%if $defaults != ""%
: $defaults
%endIf%
\n{\n\n}
%endIf%

%PI="\n\n"%

%if genOptGenDestructor == "T" and genOptGenDestructorInline != "T" and classHasDestructor != "T"%
$destructor=$consPrefix+"~"+%className%+"()\n{\n\n}"
$destructor
%endIf%

%if genOptGenCopyConstructor == "T" and genOptGenCopyConstructorInline != "T" and classHasCopyConstructor != "T"%
$consPrefix%className%( const %className%& the%className% )\n{\n\n}
%endIf%

%endIf%

%list="OperationImpl" @separator="\n\n\n"%

%list="InnerClassImpl" @separator=""%

I checked - its works

golyshkin

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: generate code for attribute default values?
« Reply #5 on: July 08, 2005, 03:22:54 pm »
Now static works too  ;D

$COMMENT = "Its script implement initialization for constructors"
%PI=" "%

%if attStatic==""%

$COMMENT = "Not static initialization"
$type=%attQualType%
$type=%REPLACE($type,".","::")%
$qualType=%packagePath% + "::" + %attType%
%PI=""%
%attContainment=="By Reference" ? "&" : ""%
%attName%( %attInitial% )

%else%

$COMMENT = "Static initialization"
%attQualType% %className%::%attName% = %attInitial%;

%endIf%

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
Re: generate code for attribute default values?
« Reply #6 on: July 11, 2005, 01:11:42 am »
Hi golyshkin,

Thanks for your solution! it generates just fine.
:)
But unfortunately it does not synchronize when reverse engeneering.  :(

When you reverse engeneer it, it will clear all the default values in the model!

Any ideas?

have a nice day everybody!
Best regards,
Manfred

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: generate code for attribute default values?
« Reply #7 on: July 11, 2005, 01:37:13 am »
Quote
Hi golyshkin,

Thanks for your solution! it generates just fine.
 :)
But unfortunately it does not synchronize when reverse engineering.  :(

When you reverse engineer it, it will clear all the default values in the model!

Any ideas?

have a nice day everybody!
There are, probably, no ideas to be had...

EA (I think)  uses a different engine to reverse engineer from the one it uses to forward engineer!  So, changes made in one are not reflected in the other.  In addition, it provides access to one engine, but not the other...  

Thus, for example, you can create a new forward engineering language (as I did), but you can't reverse engineer it.

HTH,

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

wink

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
  • Montjoie, que jamais ne choit!
    • View Profile
Re: generate code for attribute default values?
« Reply #8 on: July 11, 2005, 01:45:25 am »
Hi Paolo

Thanks for you indications. This is really sad... :(
Such a great product and then this...

Is there any hope to get access to the reverse engine one day?

Hello fellow Sparxians! Please hear our prayers!!! ;)
I'm sure I'm not the only one out there...


Best regards,
Manfred

thomaskilian

  • Guest
Re: generate code for attribute default values?
« Reply #9 on: July 11, 2005, 04:15:04 am »
I vaguely remeber having read in a post that this is under construction. But I can't remeber where :-[