comp.lang.ada
 help / color / mirror / Atom feed
From: Gene <gene.ressler@gmail.com>
Subject: Re: Access idiom
Date: Sun, 20 Jan 2008 20:16:03 -0800 (PST)
Date: 2008-01-20T20:16:03-08:00	[thread overview]
Message-ID: <adad44a1-0519-4333-add6-86936adc7ab1@l1g2000hsa.googlegroups.com> (raw)
In-Reply-To: 87wsq4xa93.fsf@ludovic-brenta.org

On Jan 20, 8:01 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Gene writes:
> > I tentatively have given up on access dispatching entirely,
> > dispatching instead on node types (not access) and copying to form
> > fresh values of a named classwide access type for the return
> > value(s).  This same named type is used for node child pointers.
> > While this okay, there is a lot of useless copying.
>
> > Feels like I'm playing whack-a-mole with the Ada type system.  What's
> > the idomatic way to get this job done without the copying?
>
> Parameters of tagged types being always passed by reference (see ARM
> 6.3.2(5)), there is no copying involved in "dispatching on node types"
> as opposed to access, so I think your solution is fine.  Then again, I
> may have misunderstood your problem.
>

I haven't been clear.  When I dispatch on the tagged record types
rather than access to tagged record, then I have no way of returning a
pointer to the dispatching object or a child pointer.

In concept, what I'd need to do is something like this:

type Node_Ptr_Type is access Node_Type'Class;

procedure Op(P : in Threat_Type; Result : out Node_Ptr_Type) is
begin
   Result := P'Access; -- identity operation
end Op;

... or the other way:

procedure Op(P : access Threat_Type; Result : out Node_Ptr_Type) is
begin
   Result := Node_Ptr_Type(P); -- identity operation
end Op;

Of course neither of these is correct Ada.  Instead I'm doing this:

procedure Op(P : in Threat_Type; Result : out Node_Ptr_Type) is
begin
   Result := Node_Ptr_Type'(new Threat_Type'(P)); -- identity
operation
end Op;

This works, but the copy is unnecessary.




  reply	other threads:[~2008-01-21  4:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-20 19:57 Access idiom Gene
2008-01-21  1:01 ` Ludovic Brenta
2008-01-21  4:16   ` Gene [this message]
2008-01-21 15:37     ` Robert A Duff
2008-01-22  4:11     ` Randy Brukardt
2008-01-22  4:11     ` Randy Brukardt
2008-01-21  9:05 ` Dmitry A. Kazakov
2008-01-21 18:15 ` Jeffrey R. Carter
2008-01-22  3:56   ` Gene
2008-01-22  5:10     ` Gene
2008-01-22  9:01     ` Dmitry A. Kazakov
2008-01-22 18:47     ` Jeffrey R. Carter
2008-01-22  4:15   ` Randy Brukardt
2008-01-22  4:15   ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
2008-01-21  7:12 Grein, Christoph (Fa. ESG)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox