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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!ihnp4!qantel!lll-lcc!lll-crg!nike!ucbcad!ucbvax!telesoft.UUCP!gary From: gary@telesoft.UUCP (Gary Dismukes @lizard) Newsgroups: net.lang.ada Subject: Re: "=" for limited private access types Message-ID: <8609250236.AA02292@sdcsvax.UCSD.EDU.ucsd.edu> Date: Wed, 24-Sep-86 15:10:55 EDT Article-I.D.: sdcsvax.8609250236.AA02292 Posted: Wed Sep 24 15:10:55 1986 Date-Received: Tue, 30-Sep-86 06:51:40 EDT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: Implementing equality for limited private access types ------------------------------------------------------ The same technique that is used to implement equality for a limited private type whose full type is derived from type INTEGER can be used when the full type is an access type (or, in fact, any type for which "=" is defined): package P is type LP is limited private; function "=" ( LEFT, RIGHT: LP ) return BOOLEAN; private type ACCESS_TYPE is access SOME_TYPE; type LP is new ACCESS_TYPE; end P; package P is function "=" ( LEFT, RIGHT: LP ) return BOOLEAN is begin return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ); end "="; end P; It is just a matter of introducing a type via a separate type declaration, and then deriving from that type in the private type's full type declaration. >From your example it appears that you actually want to define equality for your limited type to be equality of the designated objects. This can be done by implementing the "=" function as follows: function "=" ( LEFT, RIGHT: LP ) return BOOLEAN is begin If ACCESS_TYPE( LEFT ) = null or ACCESS_TYPE( RIGHT ) = null then return FALSE; -- or perhaps: return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ); else return LEFT.all = RIGHT.all; end if; end "="; Also, for efficiency, one might want to compare LEFT and RIGHT directly in the else part before comparing the designated objects in the case of objects that are large: return ACCESS_TYPE( LEFT ) = ACCESS_TYPE( RIGHT ) or else LEFT.all = RIGHT.all; Gary Dismukes TeleSoft gary@telesoft.uucp ucbvax--| hp-sdd--| telesoft!gary@ucsd.arpa decvax--+--sdcsvax--+--telesoft ihnp4--| noscvax--|