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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,36da339e8d10520c,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-08 18:40:05 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!coop.net!newsfeed1.global.lmco.com!newsfeed3.global.lmco.com!news.vf.lmco.com!not-for-mail From: "Michael P. Card" Newsgroups: comp.lang.ada Subject: Using 'Access in a limited type declaration as an initialization hook Date: Wed, 08 Aug 2001 21:23:34 -0400 Organization: Lockheed Martin Message-ID: <3B71E616.EEACBB6D@delete_this_anti_spam_part.lmco.com> NNTP-Posting-Host: dhcpeng1974.syr.lmco.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------B461A97574FC9A1EB78D9D9B" X-Trace: knight.vf.lmco.com 997320215 20021 144.219.231.181 (9 Aug 2001 01:23:35 GMT) X-Complaints-To: usenet@news.vf.lmco.com NNTP-Posting-Date: 9 Aug 2001 01:23:35 GMT Cc: michael.p.card@lmco.com X-Mailer: Mozilla 4.7 [en] (WinNT; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:11659 Date: 2001-08-09T01:23:35+00:00 List-Id: This is a multi-part message in MIME format. --------------B461A97574FC9A1EB78D9D9B Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello CLA- Many of you Ada vets out there may know about this already, but I have worked with Ada for years and never knew it was possible. What I am referring to is the ability to use the 'Access attribute on a TYPE in a limited type declaration. For example: type My_Obj_Type is abstract tagged limited private; private -- A special initialization function that returns the initialization value for one of an object's -- attributes, could also as a side effect initialize all of the other fields or do other things function Special_Init_Function (The_Object : access My_Obj_Type) return My_Type; type My_Obj_Type is abstract tagged limited record Attr_1 : My_Type := Special_Init_Function(The_Object => My_Obj_Type'Access); -- more attributes end record; This will cause Special_Init_Function to be invoked whenever an instance of any type derived from My_Obj_Type is created, and the object passed in to the function will be the newly-created instance! You don't need to use abstract tagged types with this, but I showed this as an example because it seemed useful. I don't know about the rest of you, but I always thought that the only way to get an "initialization hook" that would be called whenever an object was created was to use the Ada.Finalization package. Annex K of the LRM does not indicate that 'Access can be used against a subtype, and even Norm Cohen's excellent book "Ada as a Second Language" does not mention this as far as I could tell. I was informed about it during an e-mail dialogue with our support folks at Green Hills. The only thing I could find in the LRM that indicated that something like this would work was LRM 3.10.2 paragraph 24: "X'Access yields an access value that designates the object denoted by X. The type of X'Access is an access-to-object type, as determined by the expected type. The expected type shall be a general access type. X shall denote an aliased view of an object, including possibly the current instance (see 8.6) of a limited type within its definition, ..." I think this is a very powerful and handy capability, as it allows you have an initialization hook without using controlled types. I was investigating this as part of our work on the Real-time Object Database with Extensions to ODMG (RODEO) project, which is an Ada95 real-time object-oriented database manager we (LMC) are using as part of the AN/SLY-2 (AIEWS) system. Hope someone else finds this as useful as I did! - Mike --------------B461A97574FC9A1EB78D9D9B Content-Type: text/x-vcard; charset=us-ascii; name="michael.p.card.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Michael P. Card Content-Disposition: attachment; filename="michael.p.card.vcf" begin:vcard n:Card;Michael tel;fax:315-456-1680 tel;work:315-456-3022 x-mozilla-html:TRUE org:Lockheed Martin ;Naval Electronics & Surveillance Systems - Syracuse version:2.1 email;internet:michael.p.card@lmco.com title:Principal Software Engineer adr;quoted-printable:;;Electronics Park=0D=0ABuilding 7, Room C172 MD42;Syracuse;NY;13221;USA fn:Michael Card end:vcard --------------B461A97574FC9A1EB78D9D9B--