Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » GMT (Generative Modeling Technologies) » [MOFScript]How to write this loop in MOFScript
[MOFScript]How to write this loop in MOFScript [message #385269] Thu, 28 August 2008 11:42 Go to next message
yeliu is currently offline yeliuFriend
Messages: 145
Registered: July 2009
Senior Member
Hello,
Anyone knows how to write this code into loop:
------------------------------------------
self.objects->forEach(o:Object)
'Connect '
o.name'.outport['1']->'o.outgoing.first().name ' -> '
o.outgoing.first().outputs.first().name '->
'o.outgoing.first().outputs.first().outgoing.first().name ' ->
'o.outgoing.first().outputs.first().outgoings.first().output s.first().name'.inport['1']'

nl
'Connect '
o.name'.outport['2']->'o.outgoing.last().name ' -> '
o.outgoing.last().outputs.first().name ' ->
'o.outgoing.last().outputs.last().outgoing.first().name ' -> '
o.outgoing.last().outputs.last().outgoing.first().outputs.fi rst().name
'.inport['2']'
nl
-----------------------
In the above code, to simplify,o has 2 outports and 2 outgoings,and I use
outgoing.first() and outgoing.last() to print the two elements in outgoing
list.But acturally,o may have more than 1 outports.o's outgoing is a list
which contains more than 1 elements.

Can anyone help me?
Thank you for your help in advance!


Ye
Re: [MOFScript]How to write this loop in MOFScript [message #385271 is a reply to message #385269] Thu, 28 August 2008 12:48 Go to previous messageGo to next message
Tor Neple is currently offline Tor NepleFriend
Messages: 57
Registered: July 2009
Member
Hello

It would be easier for me to answer your question if you could provide
me the metamodel. But is what you are looking for the possibility to
iterate all of the outgoings? The o.outgoing->forEach(p:Outport) should
iterate them, then you can du the same at the level below. To me it
seems as if this is a case that lends it self toward recursion?

Anyways, if you provide me more details I may be able to be of more help

Regards

Tor Neple

yeliu wrote:
> Hello,
> Anyone knows how to write this code into loop:
> ------------------------------------------
> self.objects->forEach(o:Object)
> 'Connect '
> o.name'.outport['1']->'o.outgoing.first().name ' -> '
> o.outgoing.first().outputs.first().name '->
> 'o.outgoing.first().outputs.first().outgoing.first().name ' ->
> 'o.outgoing.first().outputs.first().outgoings.first().output s.first().name'.inport['1']'
> nl
> 'Connect '
> o.name'.outport['2']->'o.outgoing.last().name ' -> '
> o.outgoing.last().outputs.first().name ' ->
> 'o.outgoing.last().outputs.last().outgoing.first().name ' -> '
> o.outgoing.last().outputs.last().outgoing.first().outputs.fi rst().name
> '.inport['2']' nl
> -----------------------
> In the above code, to simplify,o has 2 outports and 2 outgoings,and I
> use outgoing.first() and outgoing.last() to print the two elements in
> outgoing list.But acturally,o may have more than 1 outports.o's outgoing
> is a list which contains more than 1 elements.
>
> Can anyone help me?
> Thank you for your help in advance!
>
>
> Ye
>
Re: [MOFScript]How to write this loop in MOFScript [message #385277 is a reply to message #385271] Fri, 29 August 2008 07:08 Go to previous messageGo to next message
yeliu is currently offline yeliuFriend
Messages: 145
Registered: July 2009
Senior Member
Hello,
When it comes to the metamodel,it's a long story to tell.As I posted
before,there are four elements(N,K,S,G) which inherit an abstract class
called Objects.N also contains other Objects including itself.Besides
there is another class C which connects other four elements and is also
contained in N. N and K can be connected by only one incoming C and one
outgoing C. S has only one incoming C and more than one outgoing C.
Conversely,G can hava more than one incoming C and only one outgoing C.So
now imagine those elements are connected in the following simple sequence:

K
|
S
/ | \
c1 c2 c3
\ | /
G
|
N
As shown in the graph,S has 3 outports ,G has 3 inports.
Now I wanna print them into code,like:
connect K->S
connect S.outport[1]->c1->G.inport[1]
connect S.outport[2]->c2->G.inport[2]
connect S.outport[3]->c3->G.inport[3]
connect G->N
It's easier When iterate elements with only one incoming C and outgoing
C.I write code like this:
in the context of N.(objects stands for reference from N to Objects)
----------------------------------------
self.objects->forEach(o:Objects){
if(o.outgoingC!=null){
if(!o.oclIsTypeOf(S)){
o.name ' -> ' o.outgoingC.first().name ' -> '
}
----------------------------------
but when it iterate to S ,the' connect ' statement should split into 3
lines, and it's getting hard to get access to objects of C because C is
not Objects and has different containment relations to N. and when print
branchs of S,the printed statement should stop at G.

So , generally,the metamodel is like this and my purpose is also
restated.I don't know if this makes you more confused or a little bit
clearer.If you still need more detail,just tell me ,thank you for your
kind help!


Ye
Re: [MOFScript]How to write this loop in MOFScript [message #385281 is a reply to message #385277] Fri, 29 August 2008 10:19 Go to previous message
Tor Neple is currently offline Tor NepleFriend
Messages: 57
Registered: July 2009
Member
Hmm again, without the Ecore file it is hard..

In your C class, have you got a reference to the incoming and outgoing
Objects? If so a forEach on S's outpros should work I guess. From the
found C instance in each case you should be able to get to the G
instance by following the links forward.

The key trick is to find out when you are in a S instance, and that
should be quite simple, you could for instance use if(o.oclIsTypeOf(S))
and then start the forEach on the found S instance.

Not sure this helped to much, but I guess it should be possible, again
all depending on the details of the metamodel

Tor




yeliu wrote:
> Hello,
> When it comes to the metamodel,it's a long story to tell.As I posted
> before,there are four elements(N,K,S,G) which inherit an abstract class
> called Objects.N also contains other Objects including itself.Besides
> there is another class C which connects other four elements and is also
> contained in N. N and K can be connected by only one incoming C and one
> outgoing C. S has only one incoming C and more than one outgoing C.
> Conversely,G can hava more than one incoming C and only one outgoing
> C.So now imagine those elements are connected in the following simple
> sequence:
>
> K
> |
> S
> / | \
> c1 c2 c3
> \ | /
> G
> |
> N
> As shown in the graph,S has 3 outports ,G has 3 inports.
> Now I wanna print them into code,like:
> connect K->S
> connect S.outport[1]->c1->G.inport[1]
> connect S.outport[2]->c2->G.inport[2]
> connect S.outport[3]->c3->G.inport[3]
> connect G->N
> It's easier When iterate elements with only one incoming C and outgoing
> C.I write code like this:
> in the context of N.(objects stands for reference from N to Objects)
> ----------------------------------------
> self.objects->forEach(o:Objects){
> if(o.outgoingC!=null){
> if(!o.oclIsTypeOf(S)){
> o.name ' -> ' o.outgoingC.first().name ' -> '
> }
> ----------------------------------
> but when it iterate to S ,the' connect ' statement should split into 3
> lines, and it's getting hard to get access to objects of C because C is
> not Objects and has different containment relations to N. and when print
> branchs of S,the printed statement should stop at G.
>
> So , generally,the metamodel is like this and my purpose is also
> restated.I don't know if this makes you more confused or a little bit
> clearer.If you still need more detail,just tell me ,thank you for your
> kind help!
>
>
> Ye
>
Re: [MOFScript]How to write this loop in MOFScript [message #620462 is a reply to message #385269] Thu, 28 August 2008 12:48 Go to previous message
Tor Neple is currently offline Tor NepleFriend
Messages: 57
Registered: July 2009
Member
Hello

It would be easier for me to answer your question if you could provide
me the metamodel. But is what you are looking for the possibility to
iterate all of the outgoings? The o.outgoing->forEach(p:Outport) should
iterate them, then you can du the same at the level below. To me it
seems as if this is a case that lends it self toward recursion?

Anyways, if you provide me more details I may be able to be of more help

Regards

Tor Neple

yeliu wrote:
> Hello,
> Anyone knows how to write this code into loop:
> ------------------------------------------
> self.objects->forEach(o:Object)
> 'Connect '
> o.name'.outport['1']->'o.outgoing.first().name ' -> '
> o.outgoing.first().outputs.first().name '->
> 'o.outgoing.first().outputs.first().outgoing.first().name ' ->
> 'o.outgoing.first().outputs.first().outgoings.first().output s.first().name'.inport['1']'
> nl
> 'Connect '
> o.name'.outport['2']->'o.outgoing.last().name ' -> '
> o.outgoing.last().outputs.first().name ' ->
> 'o.outgoing.last().outputs.last().outgoing.first().name ' -> '
> o.outgoing.last().outputs.last().outgoing.first().outputs.fi rst().name
> '.inport['2']' nl
> -----------------------
> In the above code, to simplify,o has 2 outports and 2 outgoings,and I
> use outgoing.first() and outgoing.last() to print the two elements in
> outgoing list.But acturally,o may have more than 1 outports.o's outgoing
> is a list which contains more than 1 elements.
>
> Can anyone help me?
> Thank you for your help in advance!
>
>
> Ye
>
Re: [MOFScript]How to write this loop in MOFScript [message #621668 is a reply to message #385271] Fri, 29 August 2008 07:08 Go to previous message
yeliu is currently offline yeliuFriend
Messages: 145
Registered: July 2009
Senior Member
Hello,
When it comes to the metamodel,it's a long story to tell.As I posted
before,there are four elements(N,K,S,G) which inherit an abstract class
called Objects.N also contains other Objects including itself.Besides
there is another class C which connects other four elements and is also
contained in N. N and K can be connected by only one incoming C and one
outgoing C. S has only one incoming C and more than one outgoing C.
Conversely,G can hava more than one incoming C and only one outgoing C.So
now imagine those elements are connected in the following simple sequence:

K
|
S
/ | \
c1 c2 c3
\ | /
G
|
N
As shown in the graph,S has 3 outports ,G has 3 inports.
Now I wanna print them into code,like:
connect K->S
connect S.outport[1]->c1->G.inport[1]
connect S.outport[2]->c2->G.inport[2]
connect S.outport[3]->c3->G.inport[3]
connect G->N
It's easier When iterate elements with only one incoming C and outgoing
C.I write code like this:
in the context of N.(objects stands for reference from N to Objects)
----------------------------------------
self.objects->forEach(o:Objects){
if(o.outgoingC!=null){
if(!o.oclIsTypeOf(S)){
o.name ' -> ' o.outgoingC.first().name ' -> '
}
----------------------------------
but when it iterate to S ,the' connect ' statement should split into 3
lines, and it's getting hard to get access to objects of C because C is
not Objects and has different containment relations to N. and when print
branchs of S,the printed statement should stop at G.

So , generally,the metamodel is like this and my purpose is also
restated.I don't know if this makes you more confused or a little bit
clearer.If you still need more detail,just tell me ,thank you for your
kind help!


Ye
Re: [MOFScript]How to write this loop in MOFScript [message #621675 is a reply to message #385277] Fri, 29 August 2008 10:19 Go to previous message
Tor Neple is currently offline Tor NepleFriend
Messages: 57
Registered: July 2009
Member
Hmm again, without the Ecore file it is hard..

In your C class, have you got a reference to the incoming and outgoing
Objects? If so a forEach on S's outpros should work I guess. From the
found C instance in each case you should be able to get to the G
instance by following the links forward.

The key trick is to find out when you are in a S instance, and that
should be quite simple, you could for instance use if(o.oclIsTypeOf(S))
and then start the forEach on the found S instance.

Not sure this helped to much, but I guess it should be possible, again
all depending on the details of the metamodel

Tor




yeliu wrote:
> Hello,
> When it comes to the metamodel,it's a long story to tell.As I posted
> before,there are four elements(N,K,S,G) which inherit an abstract class
> called Objects.N also contains other Objects including itself.Besides
> there is another class C which connects other four elements and is also
> contained in N. N and K can be connected by only one incoming C and one
> outgoing C. S has only one incoming C and more than one outgoing C.
> Conversely,G can hava more than one incoming C and only one outgoing
> C.So now imagine those elements are connected in the following simple
> sequence:
>
> K
> |
> S
> / | \
> c1 c2 c3
> \ | /
> G
> |
> N
> As shown in the graph,S has 3 outports ,G has 3 inports.
> Now I wanna print them into code,like:
> connect K->S
> connect S.outport[1]->c1->G.inport[1]
> connect S.outport[2]->c2->G.inport[2]
> connect S.outport[3]->c3->G.inport[3]
> connect G->N
> It's easier When iterate elements with only one incoming C and outgoing
> C.I write code like this:
> in the context of N.(objects stands for reference from N to Objects)
> ----------------------------------------
> self.objects->forEach(o:Objects){
> if(o.outgoingC!=null){
> if(!o.oclIsTypeOf(S)){
> o.name ' -> ' o.outgoingC.first().name ' -> '
> }
> ----------------------------------
> but when it iterate to S ,the' connect ' statement should split into 3
> lines, and it's getting hard to get access to objects of C because C is
> not Objects and has different containment relations to N. and when print
> branchs of S,the printed statement should stop at G.
>
> So , generally,the metamodel is like this and my purpose is also
> restated.I don't know if this makes you more confused or a little bit
> clearer.If you still need more detail,just tell me ,thank you for your
> kind help!
>
>
> Ye
>
Previous Topic:[GEMS] installation problems
Next Topic:[MOFScript]i+=1 acturally add by two
Goto Forum:
  


Current Time: Fri Apr 19 19:41:45 GMT 2024

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

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

Back to the top