Subject: Re: SDL-News: casting to parent type ?
From: Ivon Ritzcovitz (ivon#tseng.co.uk)
Date: Fri Dec 08 2000 - 21:55:42 GMT
Become an SDL Forum Society member <http://www.sdl-forum.org/Society/members.htm>
The originator of this message is responsible for its content.
-----From Ivon Ritzcovitz <ivon#tseng.co.uk> to sdlnews -----
Thomas Garsiot at garsiot#st2e.com wrote on 08/12/2000 08:46:
> Is there any way of casting a variable to its parent type ?
>
> This is what I'm trying to do :
>
> there is a built-in Octet_String type with a substring axiom (coming
> from ASN-1 String0 generator).
>
> This is a type we created :
>
> newtype Frame inherits Octet_String operators all;
> adding operators ...
> endnewtype Frame;
>
> I want to extract data from a frame using :
> Data := substring(sdu,24,48) where Data is an Octet_String and sdu a
> Frame (for example)
Dear Thomas,
It will not work the way you have defined it.
The inherited "substring" will have the signature:
substring: Frame, Integer, Integer -> Frame
and therefore the expression
substring(sdu, 24,28)
has the data type Frame which is in compatible with Data which has the type
OctetString.
In this case there is a quick fix.
There is an operators defined on Octet_String
Bit_String: Octet_String -> Bit_String;
so this is inherited for Frame as
Bit_String: Frame -> Bit_String;
There is also an Operator defined on Octet_String:
Octet_String: Bit_String -> Octet_String;
So
Data := Octet_String(Bit_String( Substring(sdu,24,48) ))
or alternatively:
Data := Substring( Octet_String(Bit_String(sdu)) ,24,48)
should work. However, SDT is a bit fussy about "resolution by context" and
although I think these are fine as far as SDL is concerned you may have to
insert some qualifiers to force SDT to get the right types. Taking the first
case and qualifying all the operators:
Data :=
<<TYPE Octet_String>>Octet_String(
<<TYPE Frame>> Bit_String(
<<TYPE Frame>>Substring(sdu,24,48) ) )
You can then try missing some of them out to see what works.
----------
You can use a similar method to cast types based on Integer by using Fix and
Float:
DCL i Integer, myInt MyInteger;/* where MyInteger INHERITS Integer */
i := Fix(Float(myInt));
----------
You have inherited all the operators from Octet_String into Frame, but I
suggest that you list only the ones that you actually use. This minimises
the overloading of names, and makes resolution easier for SDT. It also makes
it easier to find particular operators when using the Index Viewer (a really
useful tool).
--End text from Ivon Ritzcovitz <ivon#tseng.co.uk> to sdlnews ---
For extra SDL Forum Society benefits join at <http://www.sdl-forum.org/Society/members.htm>
This archive was generated by hypermail 2a23 : Thu May 09 2013 - 16:05:49 GMT