Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Using a integer iterator
Using a integer iterator [message #1101426] Wed, 04 September 2013 12:52 Go to next message
Federico Toledo is currently offline Federico ToledoFriend
Messages: 97
Registered: April 2012
Location: Ciudad Real, Spain
Member
Hi everyone!

I need to iterate a certain number of times, according with the integer value of an attribute.

Let's say that I have an object 'A' with an attribute 'int_att', and I'd like to create as many 'B' as indicated by this attribute.

I found a solution, but I want to know if there is a better way, because I was looking in the documentation and in the forum with no luck.

First I create a collection to have something to iterate
helper def : getCollectionFrom1to(i:Integer) : Collection(Integer) = 
	if i>1 
        then 
             thisModule.getCollectionFrom1to(i-1)->including(i) 
        else 
             Sequence{1} 
        endif;


Then I iterate this collection doing what I need
for (it in thisModule.getCollectionFrom1to(A.int_att)) {
     thisModule.createB(A);
}



Thank you in advance for any feedback
Re: Using a integer iterator [message #1101455 is a reply to message #1101426] Wed, 04 September 2013 13:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi

The idiom is

Sequence{1..N}->....

Regards

Ed Willink


On 04/09/2013 13:52, Federico Toledo wrote:
> Hi everyone!
>
> I need to iterate a certain number of times, according with the
> integer value of an attribute.
> Let's say that I have an object 'A' with an attribute 'int_att', and
> I'd like to create as many 'B' as indicated by this attribute.
> I found a solution, but I want to know if there is a better way,
> because I was looking in the documentation and in the forum with no luck.
>
> First I create a collection to have something to iterate
>
> helper def : getCollectionFrom1to(i:Integer) : Collection(Integer) =
> if i>1 then
> thisModule.getCollectionFrom1to(i-1)->including(i) else
> Sequence{1} endif;
>
>
> Then I iterate this collection doing what I need
>
> for (it in thisModule.getCollectionFrom1to(A.int_att)) {
> thisModule.createB(A);
> }
>
>
>
> Thank you in advance for any feedback
Re: Using a integer iterator [message #1101469 is a reply to message #1101455] Wed, 04 September 2013 13:51 Go to previous messageGo to next message
Federico Toledo is currently offline Federico ToledoFriend
Messages: 97
Registered: April 2012
Location: Ciudad Real, Spain
Member
I guess it is not implemented because it does not compile...
thank you!
Re: Using a integer iterator [message #1102458 is a reply to message #1101469] Thu, 05 September 2013 19:46 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 171
Registered: September 2012
Senior Member

Op 04-09-13 15:51, Federico Toledo schreef:
> I guess it is not implemented because it does not compile...
> thank you!

You're right: ATL syntax does not support the OCL range idiom, so ATL cannot
parse it. For regular ATL, your solution is fine.

Note that ATL/EMFTVM introduces a separate operation for including ranges into
a Collection, which is implemented lazily: Collection::includingRange(start :
Integer, end : Integer) : Collection. It does not actually store the whole
range of numbers, but just generates numbers as the collection is evaluated.

Regards,
Dennis


Cheers,
Dennis
Previous Topic:Refactoring transformation by seprating into modules
Next Topic:how to use primitiveTypes, OclAny, OclVoid in ATL rules
Goto Forum:
  


Current Time: Mon Dec 22 09:26:55 GMT 2014

Powered by FUDForum. Page generated in 0.03852 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software