From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3ad432aa4eef81c3 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Extending Nested Tagged Records Date: 1999/12/06 Message-ID: <384c0de3_2@news1.prserv.net>#1/1 X-Deja-AN: 557374656 Content-transfer-encoding: 7bit References: <84E639D0D9829A88.356169F32CD3866A.7936C8200D458BB1@lp.airnews. net> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 6 Dec 1999 19:26:27 GMT, 129.37.213.79 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-06T00:00:00+00:00 List-Id: In article <84E639D0D9829A88.356169F32CD3866A.7936C8200D458BB1@lp.airnews.net> , rlove@antispam.neosoft.com (Robert B. Love ) wrote: > > Can a tagged record owning a tagged record type have the inner > record extended? In trying to understand how the type extension > mechanism in Ada 95 works I'm replacing nested variant records with > tagged types. > > Here is a code snippet-- [code snipped] Here is one idea. Basically, you let types in motorized_device'class extend themselves with extensions of Telemetry_Type, but let clients of the record get at the extension by calling a function that returns a pointer to the telemetry component. There's some code below that shows what I mean. > Does this even make sense? Or is a complete redesign > the better way to go? Do clients of the types use the unencapsulated record? Or is the type private, and clients call primitive operations of the type? The code below assumes the former. However, if clients call primitive operations, then there's no real problem (because you can implement the (private) type anyway you want, and clients are oblivious.) Maybe a mixin approach can be used. Or maybe record composition using access discriminants. --STX package P is type root_motorized_device is abstract tagged record speed: Float; torque : Float; current_cmd : string (1..10); end record; type telemetry_type is tagged record speed: Float; error_flag: boolean; end record; type Telemetry_Access is access all Telemetry_Type'Class; function Telemetry (Device : access Root_Motorized_Device) return Telemetry_Access is abstract; type motorized_device is new root_motorized_device with record Telemetry : aliased Telemetry_Type; end record; function Telemetry (Device : access Motorized_Device) return Telemetry_Access; type Device_1_Telemetry_Type is new Telemetry_Type with record I : Integer; end record; type device_1 is new root_motorized_device with record shaft_position: Float; shaft_load : Float; telemetry: aliased Device_1_Telemetry_Type; end record; function Telemetry (Device : access Device_1) return Telemetry_Access; type Device_2_Telemetry_Type is new Telemetry_Type with record F : Float; end record; type device_2 is new root_motorized_device with record latch_angle: Float; end_of_travel_switch: boolean; telemetry: aliased Device_2_Telemetry_Type; end record; function Telemetry (Device : access Device_2) return Telemetry_Access; end P; package body P is function Telemetry (Device : access Motorized_Device) return Telemetry_Access is begin return Device.Telemetry'Access; end Telemetry; function Telemetry (Device : access Device_1) return Telemetry_Access is begin return Device.Telemetry'Access; end Telemetry; function Telemetry (Device : access Device_2) return Telemetry_Access is begin return Device.Telemetry'Access; end Telemetry; end P;