![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Comparision integer attributes Topic Summary: Created On: 24-Oct-2006 16:34 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: No. The object.attr construct is not a string, its a variable called 'attrRef' in the DXL manual but is actually undocumented type 'Attr__'. obj."Absolute Number" is not a string but it often behaves like one. You can convert the value of such a variable to a string by [1] assigning it to a string or by [2] concatenating it to a string: [1] string AttrVal = obj.NameAttr [2] print obj.NameAttr "\n" Doing this is legal but doesn't make sense: Attr__ aRef = obj.NameAttr [1] string AttrVal = aRef [2] print aRef "\n" Using Attr__ is useful if you write a function that wants a reference and not a value. If you assign an attrRef to an int/real/char/bool it works so long as the attrRef's value is appropriate; if the value is "AAA" you get a DXL error if you assign it to a bool variable. However, you cannot convert an attrRef to these variable types in any kind of concatenation; you need to assign explicitely. Thus, the original posters observations and frustrations are accurate and reasonable, but also unavoidable. The 'intoOf(obj."Absolute Number" "") == 10 looks quite reasonable to me. The Paradign is that one really isn't comparing integers in the example, one is trying to compare the integer representation of the attribute to an integer; looking at it that way having a conversion function seems reasonable to me. - Louie | |
![]() |
|
Hello,
Let's have a look at elementary comparision: //this is wrong if (obj."Absolute Number" == 10) It can be replaced by: //this causes 2 conversions: int->string and string->int if (intOf(obj."Absolute Number""") == 10) or int absno = obj."Absolute Number" if (absno == 10) But is there any way to do this simplier? I mean efficent, single-line expression ![]() Rafal Dudycz SIEMENS Sp. z o.o. |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
But I'm affraid that it is also not so efficient as comparing directly 2 integers. In your code there are still 2 conversions: int->string and int->string... But I would like to take value from attribute as it is (witout any conversions!)
Rafal Dudycz SIEMENS Sp. z o.o. |
|
![]() |
|
![]() |
|
The problem is that the dot operator "." when supplied with an Object reference and a string, as in:
obj."Absolute Number" returns a type of Attr__, and hence obj."Absolute Number" == 10 is comparing an Attr__ with an int, which is invalid. You could overload the dot operator to return an int thus: int ::.(Object o, string s) { return intOf(o.s "") } //This now works: if (obj."Absolute Number" == 10) Of course, this does not avoid the conversion problem, it just moves it into a separate function. Also, this technique is perhaps not for the Amish amongst us ;-) Edited: 25-Oct-2006 at 11:09 by Paul Worrall |
|
![]() |
|
![]() |
|
No. The object.attr construct is not a string, its a variable called 'attrRef' in the DXL manual but is actually undocumented type 'Attr__'. obj."Absolute Number" is not a string but it often behaves like one.
You can convert the value of such a variable to a string by [1] assigning it to a string or by [2] concatenating it to a string: [1] string AttrVal = obj.NameAttr [2] print obj.NameAttr "\n" Doing this is legal but doesn't make sense: Attr__ aRef = obj.NameAttr [1] string AttrVal = aRef [2] print aRef "\n" Using Attr__ is useful if you write a function that wants a reference and not a value. If you assign an attrRef to an int/real/char/bool it works so long as the attrRef's value is appropriate; if the value is "AAA" you get a DXL error if you assign it to a bool variable. However, you cannot convert an attrRef to these variable types in any kind of concatenation; you need to assign explicitely. Thus, the original posters observations and frustrations are accurate and reasonable, but also unavoidable. The 'intoOf(obj."Absolute Number" "") == 10 looks quite reasonable to me. The Paradign is that one really isn't comparing integers in the example, one is trying to compare the integer representation of the attribute to an integer; looking at it that way having a conversion function seems reasonable to me. - Louie |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Comparision integer attributes
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.