From: Per Sandberg <per.sandberg@bredband.net>
Subject: Re: Enforcing initialization protocol for protected type
Date: Thu, 10 Sep 2009 18:39:53 +0200
Date: 2009-09-10T18:39:53+02:00 [thread overview]
Message-ID: <4AA92BD9.7050902@bredband.net> (raw)
In-Reply-To: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com>
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
next prev parent reply other threads:[~2009-09-10 16:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-07 15:15 Enforcing initialization protocol for protected type Maciej Sobczak
2009-09-07 17:01 ` Georg Bauhaus
2009-09-07 20:19 ` Maciej Sobczak
2009-09-10 17:07 ` Georg Bauhaus
2009-09-11 5:01 ` AdaMagica
2009-09-11 9:03 ` Dmitry A. Kazakov
2009-09-11 15:25 ` AdaMagica
2009-09-11 16:27 ` Dmitry A. Kazakov
2009-09-11 22:24 ` Randy Brukardt
2009-09-12 8:44 ` Dmitry A. Kazakov
2009-09-10 16:39 ` Per Sandberg [this message]
2009-09-14 21:15 ` Adam Beneschan
2009-09-15 0:27 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox