Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Comparision integer attributes
Topic Summary:
Created On: 24-Oct-2006 16:34
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Louie Landale, on Friday, October 27, 2006 4:12 PM

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
 24-Oct-2006 16:34
User is offline View Users Profile Print this message


Rafal Dudycz

Posts: 13
Joined: 12-Jul-2005

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.
Report this to a Moderator Report this to a Moderator
 24-Oct-2006 17:07
User is offline View Users Profile Print this message


Bob Mathis

Posts: 32
Joined: 12-Apr-2005

This seems to work.

-------------------------
Bob Mathis
Robert.S.MATHIS@odot.state.or.us
Report this to a Moderator Report this to a Moderator
 25-Oct-2006 09:43
User is offline View Users Profile Print this message


Rafal Dudycz

Posts: 13
Joined: 12-Jul-2005

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.
Report this to a Moderator Report this to a Moderator
 25-Oct-2006 10:32
User is offline View Users Profile Print this message


Paul Worrall

Posts: 87
Joined: 30-Sep-2003

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
Report this to a Moderator Report this to a Moderator
 25-Oct-2006 17:01
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Answer 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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.