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: Type coercion (dereferenc?) and enumerates
Topic Summary:
Created On: 17-Aug-2004 18:07
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, August 20, 2004 7:10 PM

Answer:
Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check".

o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "":
if (o."Enum" "" == "A")

- Louie

Little snippetts of code are OK in the message. Longer ones should be attached via the [Attach Code] button, sibling to [Reply to Thread].
 17-Aug-2004 18:07
User is offline View Users Profile Print this message


Andrew Mellinger

Posts: 31
Joined: 11-Aug-2004

Greetings!

I am cutting my teeth on DXL. I have a strong background in many other languages, but I seem to be having trouble figuring out some basic programming things.

First of all enumerates.

When I'm using a non mulit-select enumerate, I can assign it to a string, which results in coercion from some internal type to a string. Then I can do stuff with it like compare it. However, if I simply try to use it, it doens't goet coerced as I expect. Let's assume I have an enum of {A, B, C}. I want to do this:

(BTW: I can't find the markup tag for code, so bear with me...)

Object o = my object
if (o."Enum" == "A")
{
// Do somehting cool.
}

Now, I've tried reversing the o."Enum" and the "A" equality operator, but to no avail. I've tried coercing with 'string', parenthesis, etc. Again, to no avail. How does one get this thing to be a string without the manual assignment?

Thanks for any help.
Report this to a Moderator Report this to a Moderator
 17-Aug-2004 19:08
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Answer Answer
Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check".

o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "":
if (o."Enum" "" == "A")

- Louie

Little snippetts of code are OK in the message. Longer ones should be attached via the [Attach Code] button, sibling to [Reply to Thread].
Report this to a Moderator Report this to a Moderator
 17-Aug-2004 20:20
User is offline View Users Profile Print this message


Andrew Mellinger

Posts: 31
Joined: 11-Aug-2004



<< Try translating "no avail" into something tangible, such as "illegal if DXL error" or "it fails the if check".

o."Enum" is not a string, its an internal attrRef type. Convert ..err.. coerce it to a string using o."Enum" "":
if (o."Enum" "" == "A")

- Louie
>>



Louie,

Thanks for the quick response!

You're right, I apologize for not being specific with my description. For the sake of clarity, my script was generating an error. The error was "-E- DXL: <Line:8> incorrect arguments for (==)".

I tried appending the empty quotes to coerce it (i.e. o."Enum" "") and it works. Is there another syntax that is cleaner or more standard? Like:

string(o."Enum")

or

o."Enum".string

or

*o."Enum"

or something like that? That extra set of quotes is certainly not intuitive.

-Andrew
Report this to a Moderator Report this to a Moderator
 18-Aug-2004 08:24
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

There are no C like casts in DXL. So you are stuck with appending the empty string.
You will soon get the hang of adding empty strings all over the place!

This works for strings, but for comparing other typed attribute values you will need to assign them to a variable before comparison.

if (o."Approved") // illegal


bool app = o."Approved"

if (app) // okay

There I go again, mouthing off before my first coffee of the day. Ignore this reply and read Paul's, which makes more sense;.

-------------------------
Tony Goodman
http://www.smartdxl.com

Edited: 18-Aug-2004 at 08:36 by Tony Goodman
Report this to a Moderator Report this to a Moderator
 18-Aug-2004 08:27
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Type conversion:

stringOf, intOf, realOf can convert one type to another.

If you want to cast, use (string otherType), not string(otherType), for instance when doing a get from an array, always cast the return to ensure you use the correct (overloaded) function (see p135 of the 7.0sp1 DXL manual):

string a = (string get(ary, idx_x, idx_y))

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 18-Aug-2004 14:44
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

I don't know and cannot find the internal type of "attrRef", but if it exists it would look something like "attributeRef_". If you found it, you could write a function:
string stringOf(attributeReference_ ar)
{ return(ar "")
}

You can now write a function:
string stringOf(Object obj, string NameAttr)
{ return(obj.NameAttr "")
}

and also write:
bool boolOf(Object obj, string NameAttr)
{ bool Value = obj.NameAttr
return(Value)
}

These functions could also check to insure that NameAttr has the correct "type".

- Louie
Report this to a Moderator Report this to a Moderator
 18-Aug-2004 17:14
User is offline View Users Profile Print this message


Andrew Mellinger

Posts: 31
Joined: 11-Aug-2004

I'll try this, it certainly would make it more readable.

Thanks!
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 0 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 0 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.