Questions tagged [ocl]

A formal specification language used with MOF meta-models (including UML) to express queries or constraints that cannot otherwise be expressed in diagramic notation.

The object constraint language (OCL) can be used to define invariants, queries, pre- and postconditions for MOF meta-models (including UML models). It allows a user to specify constraints on models, which can not be specified by the graphical notation of the UML.

OCL itself is a side-effect free, typed language based on first-order logic.

Invariants are defined for a context, typically a class. The following invariant states, that all person names should be unique:

context Person inv namesUnique:
  Person.allInstances->forAll(p|self.name=p2.name implies self=p2)

Note, that OCL provides the built in operation allInstances() to access all instances of a class.

Pre- and postconditions are specified in the context of an operation. In a post condition the special operator @pre can be used to access the values of variables, ettributes, etc. before an operation was called. Also, the special variable result can be used to access the result of the operation call.

The following conditions could be specified for an operation pop():OclAny of a Stack:

pop():OclAny
  pre  self.size > 0
  post self.size = self.size@pre - 1
  post result = self.elements@pre->last()

Beside constraint definition, OCL is used as a query language in model transformation approaches like QVT.

Further information about OCL can be found on the websites of the OCL workshop or the OCL Portal.

180 questions
0
votes
1 answer

Body Expression in OCL

I am new to OCL, and I just came across this expression: context Person::descendants(): Set body: result = self.children -> union( self.children -> collect(c | c.descendants())) I now that it's trying to obtain the direct and indirect…
Arwa
  • 575
  • 1
  • 5
  • 17
0
votes
2 answers

Defining multiplicity of attribute with constraint

I have 2 classes in UML and now need to create a constraint for this part - attribute1:String is in class1, and attribute2:int is in class2, connection between classes is generalization - can be changed to association. I need to write this…
Zoran Kokeza
  • 165
  • 12
0
votes
1 answer

greatest common divisor in ocl

How can I write an operation gcd(x : Integer, y : Integer) : Integer which returns the greatest common divisor of two positive integers (the largest integer which divides both of them exactly) in ocl?
any
  • 325
  • 5
  • 17
0
votes
1 answer

How do I compare the value of the current and the previous iteration in a for loop in Acceleo?

Is it possible to compare the value of the current and the previous iteration in a for loop in Acceleo? Knowing that LET can be defined inside for loop but it will be mutable at each current iteration, therefore the previous value will be lost and…
Geek
  • 189
  • 3
  • 13
0
votes
2 answers

OCL : express the unique constraint in a more optimal way

I am learning OCL (using "USE"), I've a question about the isUnique() constraint here's the following example: We want to establish the unique constraint of customer numbers through the class full as follows context Client inv NoClientUnique :…
cbInfo009
  • 71
  • 1
  • 4
  • 14
0
votes
1 answer

Does OCL work with composite structure diagrams?

Is OCL meant to be used in combination with a composite structure diagram? Or does it not make sense? If it makes sense, could someone give a quick example for a possible OCL constraint, e.g. based on this example diagram source ?
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
0
votes
1 answer

OCL: navigating unidirectional associations against the arrowhead direction

I read here https://wiki.eclipse.org/OCL/FAQ that How do I access unnavigable opposites in Ecore In UML, an association that is intended only to be navigated in one direction at run-time may be drawn with a unidirectional arrow. OCL evaluation…
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
0
votes
1 answer

How to write OCL contraint

I am new to OCL, I am using papyrus on eclipse luna 4.4.2 I have a class diagram named CLIENT with the constraint {all attributes are out of scope} a second class named Customer with the constraint {all attributes are mandatory} and another class…
P.Proco
  • 1
  • 1
0
votes
1 answer

Sorting a collection of numbers

Link to OCL documentation If I have a collection of Cars, I can sort it by engine power like this: collectionOfCars -> sortedBy(car|car.power) or simply collectionOfCars -> sortedBy(power) How to sort a collection of numbers? Are the following…
0
votes
1 answer

Acceleo Collection of Collections

I have defined this query [query public genCascadePath(aCSharpResourceModel : CSharpResourceModel) : Sequence(Sequence(CSharpResourceModel)) = aCSharpResourceModel.hasRelatedCSharpRMManager->collect(rmm |…
odyd
  • 194
  • 1
  • 2
  • 13
0
votes
1 answer

How to make a number to be from a given set in OCL?

There's a class 'Grade' with its 'value' atrribute set to Real and my question is how to write in OCL this condition: The grade is a number from a set {2, 3, 3.5, 4, 4.5, 5}
malloa
  • 59
  • 3
0
votes
1 answer

Generate field from association

I want to generate a field from association. The problem that I have is that I'm using: [for (p: Property | aClass.getAssociations().ownedEnd -> select(p: Property | p.type <> aClass)) separator('\n')] [p.visibility/] [p.type.name/]…
user3212350
  • 401
  • 1
  • 6
  • 18
0
votes
1 answer

ForAll and filter with Iterator in OCL

I need to do 2 functions in OCL that work on collection: forAll and filter. The trick is I can only use iterator. This is what I come with: context Collection(T)::forAll(expr) : Boolean body : self -> iterate(t: T, acc: Boolean = true | expr(t)…
MAGx2
  • 3,149
  • 7
  • 33
  • 63
0
votes
0 answers

OpenCV2.4.9 - OpenCL - oclMat

I am currently trying to make a program in c++ using OpenCV library. In order to accelerate my code I am trying to use OpenCV builtin ocl. In my code I'm trying to use oclMat and I need to take a specific cell's value. Ive tried addressing a…
Or Shalom
  • 1
  • 1
0
votes
1 answer

OpenCV OCL Error: GPU API call (-1001) in initializeOpenCLDevices

I've been using some OpenCV for a while now and I'm just starting to delve into the multi threading aspects although I'm having some difficulty getting the following code to work: #include "opencv2/ocl/ocl.hpp" int main(int argc, char *argv[]) { …
user3102241
  • 487
  • 1
  • 7
  • 18