comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Enforcing initialization protocol for protected type
Date: Mon, 7 Sep 2009 13:19:02 -0700 (PDT)
Date: 2009-09-07T13:19:02-07:00	[thread overview]
Message-ID: <afd67283-6369-45ba-b50e-92dc8b8a489c@m38g2000yqd.googlegroups.com> (raw)
In-Reply-To: 4aa53c59$0$30237$9b4e6d93@newsspool1.arcor-online.net

On 7 Wrz, 19:01, Georg Bauhaus <rm.dash-bauh...@futureapps.de> wrote:

> The following is not using, I guess, your original
> idea directly.  But it requires that the a proper context
> be set up.  Then, the PO will initialize itself from
> the context.  Context is passed in via known discriminants:
[...]

I see. I guess that in addition to passing the factory (function on
object, as in your example), the state itself can be passed via
discriminant as well.
This would leave the factory call at the user side (note that in your
example it was the protected object itself that called the factory),
which would give more control on factory call parameters and such.

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.
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



  reply	other threads:[~2009-09-07 20:19 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 [this message]
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
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