How to use Enumerations in DXL Scripts?
Asked Answered
F

4

5

I'd like to test the value of an enumeration attribute of a DOORs object. How can this be done? And where can I find a DXL documentation describing basic features like this?

if (o."Progress" == 0) // This does NOT work
{
  // do something
}
Fungistat answered 30/8, 2011 at 8:43 Comment(1)
Wow, I never expected to be confronted with a language so exotic that stackoverflow keeps its thousands of mouthes shut.Fungistat
F
5

So after two weeks and an expired bounty I finally made it. Enum-Attributes can be assigned to int or string variables as desired. But you have to assign to a variable to perform such a conversion. It is not casted when a mere comparison is done like in my example. So here comes the solution:

int tmp = o."Progress"
if (tmp == 0)
{
  // do something
}

When tmp is a string, a comparison to the enum literals is possible.

That was easy. Wasn't it? And here I finally found the everything-you-need-to-know-about-DXL manual.

Fungistat answered 16/9, 2011 at 9:35 Comment(1)
Unfortunately, the DXL Reference Manual does not explain much in detail. In particular, while trying to achieve the same as you tried, I browsed through the manual before searching and finding the solution here. If the manual contained the hint, it would be great to add the section number to it. Anyway, thanks for your question and solution!Cnossus
I
3

For multi-valued enumerations, the best way is if (isMember(o."Progress", "0")) {. The possible enumerations for single and multi-enumeration variables are considered strings, so Steve's solution is the best dxl way for the single enumeration.

Imbroglio answered 2/6, 2017 at 3:16 Comment(1)
This is exactly what I was looking for! Thank you.Avicenna
V
2

You can also do

if(o."Progress" "" == "0")
{
   //do something
}

This will cast the attribute value to a string and compare it to the string "0"

Vannesavanness answered 29/8, 2012 at 18:54 Comment(0)
E
1

If you're talking about the "related number" that is assignable from the Edit Types box, then you'll need to start by getting the position of the enumeration string within the enum and then retrieve EnumName[k].value .

I'm no expert at DXL, so the only way to find the index that I know of off the top of my head is to loop over 1 : EnumName.size and when you get a match to the enumeration string, use that loop index value to retrieve the enumeration "related number."

Extol answered 31/1, 2017 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.