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!news3.google.com!feeder.news-service.com!cyclone01.ams2.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwinds-media.com!newsfe15.ams2.POSTED!40385e62!not-for-mail Message-ID: <4AA92BD9.7050902@bredband.net> From: Per Sandberg User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Enforcing initialization protocol for protected type References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> In-Reply-To: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@WWWSpace.NET NNTP-Posting-Date: Thu, 10 Sep 2009 17:47:29 UTC Date: Thu, 10 Sep 2009 18:39:53 +0200 Xref: g2news2.google.com comp.lang.ada:8274 Date: 2009-09-10T18:39:53+02:00 List-Id: The following will solve your problem but there is a catch. The only compiler that will fix it is to my knowledge the most bleeding edge gnat. /Per ----------------------------- package p is type Protected_t; type initializer_t (Wrapped : not null access Protected_t) is new ada.Finalization.Limited_Controlled with null record; procedure Initialize (self : in out initializer_t); procedure Finalize (self : in out initializer_t); protected type Protected_t is entry tick; procedure Initialize; procedure finalize; private initializer : initializer_t (Protected_t'access); end; end p; package body p is protected body Protected_t is entry tick when True is begin null; end; procedure Initialize is begin null; end; procedure finalize is begin null; end; end; procedure Initialize (self : in out initializer_t) is begin self.Wrapped.Initialize; end; procedure Finalize (self : in out initializer_t) is begin self.Wrapped.Initialize; end; end p; Maciej Sobczak wrote: > Consider the Needs_Constructor type from the code example in the Ada > wikibook: > > http://en.wikibooks.org/wiki/Ada_Programming/Types/limited#Initialisi... > > Is it possible to ensure a given initialization protocol for protected > types as well? > > The problem is that protected types cannot have unknown discriminants. > How can I ensure that objects of a given protected type are always > initialized with a call to proper constructor function? > > Note that wrapping a protected object in another one (presumably > limited and private) would limit the possibility to perform timed > entry calls on the target protected object and preserving this > possibility is essential in my actual use case. > > -- > Maciej Sobczak * www.msobczak.com * www.inspirel.com > > Database Access Library for Ada: www.inspirel.com/soci-ada