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,d1df6bc3799debed X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Syntax for tagged record types (was Re: Not intended for use in medical,) Date: 1997/05/28 Message-ID: #1/1 X-Deja-AN: 244393064 References: <3.0.32.19970423164855.00746db8@mail.4dcomm.com> <33867D87.21BA@sprintmail.com> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1997-05-28T00:00:00+00:00 List-Id: In article mheaney@ni.net (Matthew Heaney) writes: > Maybe not: we just need some way of allocating the object on the > stack, and letting the constructor manipulate that object, so that > no copying is ever required. It would be really swell too, if in > the constructor we were able to invoke the constructors for the > object's components. > An important goal, though, is for constructors for limited types > that are indefinate. Hmmm. Let's imagine a generic package: generic type Object_Type(<>) is limited private; type Object_Ref is access Object_Type; ... package Constructor is Object: Object_Ref; end Constructor; pragma Elaborate_Body(Constructor); package body Constructor is ... end Constructor; Now every time I instantiate this package, I create an Object_Ref, and in the body I initialize it to point to a value in the body. For some types the body can be completely in Ada, for others you might have to use extensions/magic tricks/Unchecked_Conversions, etc. in the body, and in particular, the decision whether or not to call Unchecked_Access will almost certainly a significant design issue. When I have played this game, I've done it three different ways: 1) N objects in the package which declares the type, and the generic packages do reference counting. (Actually, it is easier to make the _ref type a controlled type to begin with, but I digress.) 2) Unchecked_Access and programming standards about copying the pointer object. (Or you could try making that type limited, but leave out the unknown discriminants.) 3) Garbage collection provided courtesy of Unbounded_String. Be careful to understand the game here. The safest is to have a (private) token type which is access Unbounded_String, and a conversion which produces an Object_Ref from it. To do otherwise, you have to look at the implementation of Unbounded_String. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...