I'm having trouble testing a object's boolean attribute value in an "if" statement. |
Re: Using Boolean Attribute in IF statements?
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__)
bool b = false
obj = current
if ( (b = obj."OLE") == true ) {
print "AN OLE OBJECT!"
}
bool ::== (Attr__ a, bool b) {
bool x = a; return ((x and b) or (!x and !b))
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Using Boolean Attribute in IF statements? |
Re: Using Boolean Attribute in IF statements? if (obj."IsRequirement" "" == "True") "True" and "False" with capital letter.
|
Re: Using Boolean Attribute in IF statements? llandale - Mon Jan 31 15:05:23 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
|
Re: Using Boolean Attribute in IF statements? 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"
|
Re: Using Boolean Attribute in IF statements? 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"
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? 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"
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? SystemAdmin - Mon Jan 31 16:56:20 EST 2011 Paul Miller Melbourne, Australia But its nice to know someone has noticed. snif
|