Book a Demo

Author Topic: setting variable to List macro output  (Read 4621 times)

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
setting variable to List macro output
« on: March 14, 2008, 06:01:26 am »
I'm doodling inside the Class Body template and have read up on the documentation on using macro's.

Under "Control Macros" in the documentation, it says you can set the macro's output to a variable for further processing like this:
Code: [Select]
$bases=%list="ClassBase" @separator=", "%
The interesting thing is that if I set the "attribute" base class to a variable, the generate source still generates attributes output to file. Also, removing it entirely or the changing of "attribute" results in no attributes written.

Unusually, the line below results in attributes being written to file, instead of being "commented" out by having it's resulting string redirected/set to a variable named $test.
Code: [Select]
$testVar=%list="Attribute" @separator="\n" @indent="\t"%
It seems like the %list call automatically writes the text to the file, regardless of usages as a "litteral" or variable assigment.

What gives??

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: setting variable to List macro output
« Reply #1 on: March 14, 2008, 09:47:16 am »
What I suspect is happening is that EA is interpreting that line incorrectly as a variable use, followed by the list.  As you won't have anything assigned to the variable nothing will be generated and the end result is just the list.

Now the C++ class body template does pretty much what you have done.  The only significant difference (that I can see) is that there is always a space on either side of the equals.  But I've tried your code exactly (in build 827) and it works as expected.

What build are you using? Could you post the full contents of your template?

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: setting variable to List macro output
« Reply #2 on: March 19, 2008, 12:12:47 am »
I only changed line 11 from the default. My EA is Version 7.0.818 (Build: 818) - Unicode.

Code: [Select]
%if elemType == "Interface"%
{\n
%list="Operation" @separator="\n\n" @indent="\t"%
%PI=""%
}//end %className%
%endTemplate%

{\n
%PI="\n\n"%
%list="InnerClass" @separator="\n\n" @indent="\t"%
$testVar=%list="Attribute" @separator="\n" @indent="\t"%

$ops=""
%if genOptGenConstructor == "T" and classHasConstructor != "T"%
$ops+="\tpublic "+%className%+"(){\n\n\t}"
%endIf%

%if genOptGenDestructor == "T" and classHasDestructor != "T" and classHasFinalizer != "T"%
$ops+="\n\n\t~"+%className%+"(){\n\n\t}"
%endIf%

%if genOptCSGenDispose == "T" and classHasDispose != "T"%
$ops+="\n\n\tpublic "
$ops+=%classHasParent=="T" ? "override " : "virtual "%
$ops+="void Dispose(){\n\n\t}"
%endIf%

%if genOptCSGenFinalizer == "T" and genOptGenDestructor != "T" and classHasFinalizer != "T" and classHasDestructor != "T"%
$ops+="\n\n\tprotected "
$ops+=%classHasParent=="T" ? "override " : "virtual "%
$ops+="void Finalize(){\n"
$ops+=%classHasParent=="T" ? "\t\tbase.Finalize();" : ""% + "\n\t}"
%endIf%

%if genOptGenCopyConstructor == "T" and classHasCopyConstructor != "T"%
$ops+="\n\n\tpublic "
$ops+=%className%+"("+%className%+" the"+%className%+"){\n\n\t}"
%endIf%

$ops
%list="Operation" @separator="\n\n" @indent="\t"%

}//end %className%


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: setting variable to List macro output
« Reply #3 on: March 19, 2008, 08:05:17 am »
When I use your template the attributes aren't generated at all. So everything appears to be working.  (Tested with both 7.0.818 and 7.1.827)

puromtec

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: setting variable to List macro output
« Reply #4 on: March 20, 2008, 12:12:25 am »
Must be my midas touch. I'm sure I'm testing properly.

Anyways, it was just a shot in the dark to possibly achieve automatic camel back attribute creation without setting roles individually, compatible with source->model synchronization, as was discussed here http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1205334586 on last week.

My idea was to intercept the attribute list macro call and make it into a distinct list, since the problem with synchronizing, presented by the solution in the above post, is a duplication of attributes generated in the source code at the third step indicated below:

1. Generate code from model.
2. Synchronize model from code.
3. Generate code from model.

Nevertheless, I've changed course with attribute/associations and explicitly set roles on associations, one by one. Done deal, as instructed by you and Midnight.

In summary, I think I've stumbled upon a fundemental question about EA and the software modeling approach: What is the purpose of modeling mechanisms?

My answer a few day's ago: to provide an "easy and quick" way to design software using a medium that has a direct relation to the concrete code.

My answer today: to provide a "visible and graphic" way to design software....

Anyway, thanks again for the support you guys provide here.