Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How Increment Variable in loop
How Increment Variable in loop [message #643852] Wed, 08 December 2010 08:41 Go to next message
Manuel Selva is currently offline Manuel Selva
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi all, in my .mtl file (working on EMF model) I have the following loop


[for (param : Param | subCat.params)]
    record.readPayload32("What to put here ??");
[/for]


What I want is to replace the "What to put here" by a value starting at 0 and incremented on each loop's iterration by

[param.length/]
The Param EClass has an integer length attribute.

How can I acheive this ? I was not able to find any solution until now ...

Thanks in advance for your help,
Manu


Re: How Increment Variable in loop [message #643865 is a reply to message #643852] Wed, 08 December 2010 09:08 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080702080304030006030107
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Manuel,

Acceleo defines an implicit "i" variable for iterations in order to
handle such needs :

[for (param : Param | subCat.params)]
record.readPayload32([i/]);
[/for]

Laurent Goubet
Obeo

On 08/12/2010 14:41, Manuel Selva wrote:
> Hi all, in my .mtl file (working on EMF model) I have the following loop
>
>
>
> [for (param : Param | subCat.params)]
> record.readPayload32("What to put here ??");
> [/for]
>
>
> What I want is to replace the "What to put here" by a value starting at
> 0 and incremented on each loop's iterration by
>
> [param.length/] The Param EClass has an integer length attribute.
>
> How can I acheive this ? I was not able to find any solution until now ...
>
> Thanks in advance for your help,
> Manu


--------------080702080304030006030107
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------080702080304030006030107--
Re: How Increment Variable in loop [message #643873 is a reply to message #643865] Wed, 08 December 2010 09:49 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel Selva
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi Laurent,

Thanks for the answer but this is not exactly what I need. I nee to increment this variable with a field of my model:

[param.length/]


the output will look like for example (with 3 parameters of length 2,4,2 respectively)

record.readPayload32(0);
record.readPayload32(2); // 0 + 2
record.readPayload32(6); // 0 + 2 + 4


Re: How Increment Variable in loop [message #643879 is a reply to message #643873] Wed, 08 December 2010 09:59 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070507050705010905060406
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Manuel,

This can still be done... but you'll need to iterate twice on your list :

-----
[for (param : Param | subCat.params)]
record.readPayload32([subCat.params->subSequence(0,
i).length->sum()/]);
[/for]
-----

Laurent Goubet
Obeo

On 08/12/2010 15:49, Manuel Selva wrote:
> Hi Laurent,
>
> Thanks for the answer but this is not exactly what I need. I nee to
> increment this variable with a field of my model:
>
> [param.length/]
>
> the output will look like for example (with 3 parameters of length 2,4,2
> respectively)
>
>
> record.readPayload32(0);
> record.readPayload32(2); // 0 + 2
> record.readPayload32(6); // 0 + 2 + 4
>


--------------070507050705010905060406
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------070507050705010905060406--
Re: How Increment Variable in loop [message #643883 is a reply to message #643879] Wed, 08 December 2010 10:37 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel Selva
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Thanks again it works !!!

Side note I don't have the subSequence function:

Cannot find operation (subSequence(Integer, Integer)) for the type (OrderedSet(Param))


but the
subOrderedSet(0,i)


This means my params field is an OrderedSet and not a Sequence. I just want to know why ? Does this come from my .ecore file ?

Thanks again for the reactive support.
Manu


[Updated on: Wed, 08 December 2010 10:41]

Report message to a moderator

Re: How Increment Variable in loop [message #643904 is a reply to message #643883] Wed, 08 December 2010 11:09 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070908010903090408080404
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Manuel,

subSequence is for Sequences... you have to use "subOrderedSet" on
OrderedSets :p.

Laurent Goubet
Obeo

On 08/12/2010 16:37, Manuel Selva wrote:
> Thanks again but I don't have the subSequence function:
>
> Cannot find operation (subSequence(Integer, Integer)) for the type
> (OrderedSet(Param))
>
> Any ideas about that ?


--------------070908010903090408080404
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------070908010903090408080404--
Previous Topic:[Acceleo 3.0.1] Error notifying registry change listener.
Next Topic:[Acceleo] Protected block indentation problems
Goto Forum:
  


Current Time: Tue Jul 22 17:40:12 EDT 2014

Powered by FUDForum. Page generated in 0.01642 seconds