How to add power operation to the primitive type Integer? [message #1724048] |
Sat, 20 February 2016 03:48  |
Eclipse User |
|
|
|
Hi All,
What is the best way to add the operation power(i: Integer): Integer to the primitive type Integer.
The only solution that I am able to envision is to define a new DataType (e.g. Integer_with_power) that generalise the DataType Integer and defines the operation power(i: Integer): Integer and define the body of this operation via OCL.
Is there any better way do achieve the same result?
Regards,
Roberto
[Updated on: Sat, 20 February 2016 04:32] by Moderator
|
|
|
Re: How to add power function to the primitive type Integer? [message #1724051 is a reply to message #1724048] |
Sat, 20 February 2016 04:40   |
Eclipse User |
|
|
|
Hi
Now that OCL standard libraries are extensible, the 'correct' way is to
use the Math.oclstdlib library. Unfortunately it's on the to-do list as
is a tutorial on how to do it. If you're enthusiastic you can look at
the *.oclstdlib extension libraries for OCL CG, or for QVTd or the JUnit
tests.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=415146
Also on the to-do list is the 'java:java.lang.Math.pow'(a, b) direct
from OCL invocation.
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=378206
The simplest way using OCLinEcore is to add a bogus class Math to your
model and define Math.pow(mantissa : Integer, expoent : Integer). If at
least one of your classes implements Math, you can use it as a bogus
self for self.pow(a, b).
Or in UML you can define a DataType with an OCLforUML::Integer
stereotype. No need to generalize Integer.
In either case you can implement the body in Java.
Using Complete OCL you can define the inefficient
package ocl
context Integer
def pow(Integer : b) = if b > 1 then self*pow(b-1) elseif b = 1 then
self else 1 endif
endpackage
Regards
Ed Willink
On 20/02/2016 08:48, Roberto Saltini wrote:
> Hi All,
>
> What is the better way to add the operation power(i: Integer): Integer
> to the primitive type Integer.
>
> The only solution that I am able to envision is to define a new
> DataType (e.g. Integer_with_power) that generalise the DataType
> Integer and defines the operation power(i: Integer): Integer and
> define the body of this operation via OCL.
>
> Is there any better way do achieve the same result?
>
> Regards,
>
> Roberto
|
|
|
|
|
|
Re: How to add power function to the primitive type Integer? [message #1724117 is a reply to message #1724109] |
Sun, 21 February 2016 04:59  |
Eclipse User |
|
|
|
Hi
Select a Package
UML Editor(on menu bar)->Package->Apply Profile...
Regards
Ed Willink
On 21/02/2016 02:00, Roberto Saltini wrote:
> Hi Ed,
>
> I am using Mars.3(4.5.3) shipped with the latest stable Papyrus.
> I have tried your suggestion to edit the uml file using UML Model Editor, but when I try to apply a new profile I cannot find the profile OCLforUML listed as you can see from the following images.
>
>
>
>
>
> Regards,
> Roberto
|
|
|
Powered by
FUDForum. Page generated in 0.03963 seconds