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-Thread: a07f3367d7,66f9ac28e8d63f60 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail From: AdaMagica Newsgroups: comp.lang.ada Subject: Re: Enforcing initialization protocol for protected type Date: Thu, 10 Sep 2009 22:01:17 -0700 (PDT) Organization: http://groups.google.com Message-ID: <73fb1051-edf9-43f8-be50-5a2faa866040@s31g2000yqs.googlegroups.com> References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> <4aa53c59$0$30237$9b4e6d93@newsspool1.arcor-online.net> NNTP-Posting-Host: 80.156.44.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1252645278 23565 127.0.0.1 (11 Sep 2009 05:01:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Sep 2009 05:01:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s31g2000yqs.googlegroups.com; posting-host=80.156.44.178; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-HTTP-Via: 1.1 webwasher (Webwasher 6.8.4.4828) X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8281 Date: 2009-09-10T22:01:17-07:00 List-Id: On 7 Sep., 22:19, Maciej Sobczak wrote: > type State is private; > type State_Ptr is access State; > > function Make_PO return State_Ptr; > function Make_PO (Some : T; Parameters : T) return State_Ptr; > -- ... > > protected type PO (S : State_Ptr) is > -- ... > private > St : State_Ptr := S; > end PO; > > so that the typical creation pattern would be: > > X : PO (Make_PO); > Y : PO (Make_PO (ABC, DEF)); > > This, however, opens another question: controlled finalization of > protected types to release the state object, if it was allocated > dynamically. Oops. Use an access discriminant of an anonymous type and you will get a coextension that is reclaimed automatically when the object goes out of scope, see RM 3.10(14.3/2,14.4/2) [or in the newest draft of the Amendment 2, (14.1/3,14.4/3), which is a bit clearer]. See also RM 3.7(1.c/2..1.e/2). > But a controlled component of the protected type can take care of > that. > Does it make sense? > > -- > Maciej Sobczak *www.msobczak.com*www.inspirel.com > > Database Access Library for Ada:www.inspirel.com/soci-ada