Using Boolean Attribute in IF statements?

I'm having trouble testing a object's boolean attribute value in an "if" statement.

I was expecting to be able to do it like this:
{if (o."nameOfBoolAttribute") print "yes"}
However, the following is the only approach I've been able to make work:
{bool b = o."nameOfBoolAttribute"
if (b) print "yes"}

Must one always go through the overhead of creating/assiging a local bool variable to test the value of an object's boolean attribute?
BobSherman - Sat Jan 29 08:41:47 EST 2011

Re: Using Boolean Attribute in IF statements?
Mathias Mamsch - Sat Jan 29 12:58:11 EST 2011

There is no good alternative. The same is true for Date or even integer. The reason is, that "obj.string" will give you a result of type 'Attr__'. The following operators are defined for reading from Attr__:
 

// concatenate Attr__ to string ("cast" to string) 
string ::.. (Attr__, string)
 
// Read the values from the attribute
string ::= (string&, Attr__)
void ::do (Attachment&, Attr__, void)
real ::= (real&, Attr__)
bool ::= (bool&, Attr__)
Date ::= (Date&, Attr__)
int ::= (int&, Attr__)
Buffer ::= (Buffer&, Attr__)

 


So you can see you can always 'cast' to string by concatenating an empty string (obj."AttrName" "") but to really read a bool or an integer you need to use the assignment operator. Note however that attributes in DOORS are all string based, i.e. even bool attributes have three possible values: true, false and empty. That means, whenever you read an attribute value to a DXL datatype (other than string) there will be a cast of the empty value. For dates it will be (null), for boolean it will be false, for int it will be 0, for real it will be 0.0.

Since the assignment operators return the result of the assignment, you can write something like this:

 

 

 

bool b = false
obj = current
if ( (b = obj."OLE") == true ) { 
    print "AN OLE OBJECT!"
}



but that is really not any nicer. You can however anytime extend the DXL syntax by defining a function or operator on 'Attr_' like:



 

 

 

 

bool ::== (Attr__ a, bool b) {
   bool x = a; return ((x and b) or (!x and !b))
}



or a similar function. Hope that helps, regards, Mathias



 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Using Boolean Attribute in IF statements?
BobSherman - Mon Jan 31 06:33:52 EST 2011

Got it. Thanks very much for also explaining the underlying architecture/paradigm that constrains the solution.

Re: Using Boolean Attribute in IF statements?
llandale - Mon Jan 31 15:05:23 EST 2011

This works, concatenating a string to the Attr__ ref:
if (obj."IsRequirement" "" == "True")

"True" and "False" with capital letter.

  • Louie

Re: Using Boolean Attribute in IF statements?
Mathias Mamsch - Mon Jan 31 16:04:49 EST 2011

llandale - Mon Jan 31 15:05:23 EST 2011
This works, concatenating a string to the Attr__ ref:
if (obj."IsRequirement" "" == "True")

"True" and "False" with capital letter.

  • Louie

Hah! I did not know that the bool attribute string representation ("True", "False", "") is different from the DXL boolean string representation: ("true", "false"). I love DXL ... Regards, Mathias
 

Object o = current
print "Boolean from an attribute:" o."OLE" "\n"
print "Boolean False:" false "\n"
bool b = false
print "Oh no: " (b "" == o."OLE" "")  "\n"
/* prints: 
Boolean from an attribute:False
Boolean False:false
Oh no: false
*/

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Using Boolean Attribute in IF statements?
llandale - Mon Jan 31 16:20:38 EST 2011

Mathias Mamsch - Mon Jan 31 16:04:49 EST 2011

Hah! I did not know that the bool attribute string representation ("True", "False", "") is different from the DXL boolean string representation: ("true", "false"). I love DXL ... Regards, Mathias
 

Object o = current
print "Boolean from an attribute:" o."OLE" "\n"
print "Boolean False:" false "\n"
bool b = false
print "Oh no: " (b "" == o."OLE" "")  "\n"
/* prints: 
Boolean from an attribute:False
Boolean False:false
Oh no: false
*/

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

A "Boolean" attribute type is just an enumeration with two values, "True" and "False". Having said that, there indeed seems to be some DXL perms that recognize what it really means, and converts to boolean true and false. So this works:

bool   IsReq = obj."IsRequirement"
bool   IsXXX = "True"


The first converts enumerations "True" and "False" correctly into boolean true and false; the 2nd one is a syntax error.

 

 

  • Louie


Remember being a 3 year old discovering all those cool things about the world? Such kids don't have a notion of what it "should" be like, and have a much easier time accepting reality: what 3 year old cares that hot dogs come in packs of 10 while hot dog buns come in packs of 8? Well, getting such an attitude towards DXL helps a lot. lol

 

 

Re: Using Boolean Attribute in IF statements?
SystemAdmin - Mon Jan 31 16:56:20 EST 2011

llandale - Mon Jan 31 16:20:38 EST 2011

A "Boolean" attribute type is just an enumeration with two values, "True" and "False". Having said that, there indeed seems to be some DXL perms that recognize what it really means, and converts to boolean true and false. So this works:

bool   IsReq = obj."IsRequirement"
bool   IsXXX = "True"


The first converts enumerations "True" and "False" correctly into boolean true and false; the 2nd one is a syntax error.

 

 

  • Louie


Remember being a 3 year old discovering all those cool things about the world? Such kids don't have a notion of what it "should" be like, and have a much easier time accepting reality: what 3 year old cares that hot dogs come in packs of 10 while hot dog buns come in packs of 8? Well, getting such an attitude towards DXL helps a lot. lol

 

 

...Well, getting such an attitude towards DXL helps a lot...

Thanks Louie - I can sleep at night now - I think IBM needs to gather all of Louie's humerous observations and witticisms about DOORS and put them on one of those day-at-a-time flip calendars that have quotes of the day offering soothing advice :-)


Paul Miller
Melbourne, Australia

Re: Using Boolean Attribute in IF statements?
Mathias Mamsch - Mon Jan 31 18:06:07 EST 2011

llandale - Mon Jan 31 16:20:38 EST 2011

A "Boolean" attribute type is just an enumeration with two values, "True" and "False". Having said that, there indeed seems to be some DXL perms that recognize what it really means, and converts to boolean true and false. So this works:

bool   IsReq = obj."IsRequirement"
bool   IsXXX = "True"


The first converts enumerations "True" and "False" correctly into boolean true and false; the 2nd one is a syntax error.

 

 

  • Louie


Remember being a 3 year old discovering all those cool things about the world? Such kids don't have a notion of what it "should" be like, and have a much easier time accepting reality: what 3 year old cares that hot dogs come in packs of 10 while hot dog buns come in packs of 8? Well, getting such an attitude towards DXL helps a lot. lol

 

 

Are you sure that "no value" for your boolean attribute (= default value = empty) is the same as "No Requirement"? If not you should use my special custom type below. :-) Regards, Mathias
 

struct AttrBool {}
 
const AttrBool False = addr_ 0
const AttrBool True = addr_ 1
const AttrBool Don'tKnow = addr_ 2 // hey dxl permits ' in variables names :-) 
 
AttrBool getBool (Attr__ x) {
    string val = x ""
    if (val == "True") return True
    if (val == "False") return False 
    if (val == "") return Don'tKnow
}
 
// -------------------------
obj = current 
AttrBool isReq = getBool(obj."IsRequirement")
 
if (isReq == True) { print "Yeah a requirement ...\n" }
if (isReq == False) { print "Not a requirement ...\n" }
if (isReq == Don'tKnow) { print "No clue ...Sorry!\n" }

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Using Boolean Attribute in IF statements?
llandale - Tue Feb 01 15:00:40 EST 2011

SystemAdmin - Mon Jan 31 16:56:20 EST 2011
...Well, getting such an attitude towards DXL helps a lot...

Thanks Louie - I can sleep at night now - I think IBM needs to gather all of Louie's humerous observations and witticisms about DOORS and put them on one of those day-at-a-time flip calendars that have quotes of the day offering soothing advice :-)


Paul Miller
Melbourne, Australia

If you gather all my witticisms you will find there are a few different types of calandars represented not just 'soothing' ... 'seething' comes to mind.

But its nice to know someone has noticed. snif

  • Louie