comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christoph.grein@eurocopter.com>
Subject: Re: Enforcing initialization protocol for protected type
Date: Thu, 10 Sep 2009 22:01:17 -0700 (PDT)
Date: 2009-09-10T22:01:17-07:00	[thread overview]
Message-ID: <73fb1051-edf9-43f8-be50-5a2faa866040@s31g2000yqs.googlegroups.com> (raw)
In-Reply-To: afd67283-6369-45ba-b50e-92dc8b8a489c@m38g2000yqd.googlegroups.com

On 7 Sep., 22:19, Maciej Sobczak <see.my.homep...@gmail.com> 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



  parent reply	other threads:[~2009-09-11  5:01 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 [this message]
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
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