Count entries in Multi-value ennumeration

I want to create a DXL attribute which looks at another attribute for each object (a multi ennumeration attribute), and counts how many ennumerations have been selected.

Is there a simple way to count the selected number of ennumerations in a multi ennumeration attributeand/or a normal ennumeration (i.e. return 1 or 0).

Seems like there should be but i can't find anything about this in the manual.
liamc - Mon Nov 29 11:11:48 EST 2010

Re: Count entries in Multi-value ennumeration
llandale - Mon Nov 29 11:32:08 EST 2010

You could retrieve the value and count the EOLs; I think single-enums have no EOL in which case the value is either null or not-null; and I think Multi always have an EOL even if only one is selected; you'll need to play with it. You an use the Buffer 'contains(Buf, char, offset) command in a loop, where 'char' is '\n' and offset is the previous results of contains, something like this:

Buffer buf = probeAttr_(obj, "MyMultiEnumAttr")
int Count = 0, Offset = -1,
    DebugCountLoops = 0
while (true)
{  Offset = contains(buf, '\n', Offset)  // ? I don't think you need "Offset+1" here?
   if (Offset >= 0) //
   then Count++
   else break
 
   if (DebugCountLoops++ > 20)
   {  print "Debug break " Count "\t" Offset "\n"
      break
   }
}
delete(buf)
print "# EOLs = Count "\n"


Got the debug statements in there for you lesser folks, not that I have EVER ever ever ever had to abort DOORS due to an invinite loop. :)

You could also read the value into a string and then loop through the length(Value) looking for '\n'; now that I think of it that would be faster since creating/deleting Buffers is VERY slow.

 

string Value = probeAttr_(obj, "MyMultiEnumAttr")
int i, Count = 0
for (i=0; i<length(Value); i++)
{  if (Value[i] == '\n') Count++
}
print "# EOLs = Count "\n"



You will need to try this out, but the following may prove to be correct:



 

 

int NumSelectedValues
if (null Value)
then NumSelectedValues = 0
else NumSelectedValues = CountEOLS+1



You could also retrieve the list of enums and then query the object specifically for whether the enum 'isMember'. Its a little tricky getting the attr type and its valid enums, so I'd go with the EOL method.



 

 

 

  • Louie

 

 

Re: Count entries in Multi-value ennumeration
liamc - Mon Nov 29 11:48:26 EST 2010

Awesome llandale, you're a genius! I'd have never known to look for EOL.

this seems to work:
 

string Value = probeAttr_(obj, "MultiAtt")
int i, Count = 0
for (i=0; i<length(Value); i++)
{  if (Value[i] == '\n') Count++
}
//print "# EOLs = " Count "\n"
    obj.attrDXLName =  count ""

 


However, it seems to be off by 1 every time. Can't quite figure out why, hmmm

 

Re: Count entries in Multi-value ennumeration
liamc - Mon Nov 29 11:55:57 EST 2010

liamc - Mon Nov 29 11:48:26 EST 2010

Awesome llandale, you're a genius! I'd have never known to look for EOL.

this seems to work:
 

string Value = probeAttr_(obj, "MultiAtt")
int i, Count = 0
for (i=0; i<length(Value); i++)
{  if (Value[i] == '\n') Count++
}
//print "# EOLs = " Count "\n"
    obj.attrDXLName =  count ""

 


However, it seems to be off by 1 every time. Can't quite figure out why, hmmm

 

Hmm, is there an EOL on the last ennumeration?

Re: Count entries in Multi-value ennumeration
liamc - Mon Nov 29 12:02:15 EST 2010

Gah! No EOL if only 1 ennumeration is selected!

Re: Count entries in Multi-value ennumeration
liamc - Mon Nov 29 12:43:06 EST 2010

Bazinga

string Value = probeAttr_(obj, "MultiAttribute")
if(Value!=null){
int i, Count = 1
for (i=1; i<length(Value); i++)
{  if (Value[i] == '\n') Count++
}
obj.attrDXLName =  Count
}

Re: Count entries in Multi-value ennumeration
llandale - Mon Nov 29 18:58:03 EST 2010

liamc - Mon Nov 29 12:43:06 EST 2010

Bazinga

string Value = probeAttr_(obj, "MultiAttribute")
if(Value!=null){
int i, Count = 1
for (i=1; i<length(Value); i++)
{  if (Value[i] == '\n') Count++
}
obj.attrDXLName =  Count
}

Not quite. There seems to be zero EOLs when both zero and when one enumeration is selected; you should therefore add "else obj.attrDXLName = 0. Don't tell me that's the default value and you don't need to set it to zero, because you do. If it has one value than the value is 1; if you remove that value your code will not reset it to zero but will continue to display 1.

  • Louie