From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Impossible problem? A protected buffer to queue objects of a class-wide type
Date: 13 Apr 2007 10:26:16 -0700
Date: 2007-04-13T10:26:16-07:00 [thread overview]
Message-ID: <1176485175.985643.16590@e65g2000hsc.googlegroups.com> (raw)
In-Reply-To: <1176483777.264139.239360@p77g2000hsh.googlegroups.com>
On Apr 13, 1:02 pm, "Matthew Heaney" <mhea...@on2.com> wrote:
> On Apr 11, 6:34 am, "Phil Slater" <phil.sla...@baesystems.com> wrote:
>
> > I've hit a brick wall. Every strategy I try doesn't work.
I probably should have pointed out that I my previous post, the Deque
function is implemented this way:
function Deque (Q : not null access QT) return ET;
This will necessitate declaring queue objects as aliased, and then
using taking the 'Access of the object:
declare
Q : aliased QT;
begin
...
declare
E : ET := Deque (Q'Access);
begin
...
end;
...
end;
If you don't like the syntactic overhead, there are a couple of things
you can do. First is to declare the queue type as tagged:
type QT is tagged limited private;
Ada05 allows you do use distinguished-receiver syntax, and will do an
implicit dereference is the object is aliased (or implicitly aliased),
e.g.
declare
Q : aliased QT; -- QT is tagged; explicitly aliased
begin
...
declare
E : ET := Q.Deque;
begin
...
end;
...
end;
--or--
procedure Op (Q : in out QT) is -- implicitly aliased
begin
...
declare
E : ET := Q.Deque;
begin
...
end;
...
end Op;
So taggedness is one option. Another option is to use the Rosen
Trick, which allows a function to modify its parameter, if it's a by-
reference type. (Types whose full view is limited qualify, so we're
eligible.) That allows us to declare the deque function like this:
function Deque (Q : QT) return ET;
In the implementation of the QT, we simply need to add another
component:
private
type HT (Q : not null access QT) is limited null record;
...
type QT is limited record
H : HT (QT'Access);
B : BT;
end record;
end Queues;
Now we just need to make a small change to the implementation of our
deque function:
function Deque (Q : QT) return ET is
Obj : ET_Access;
begin
Q.H.Q.B.Get (Obj); -- manipulate buffer via handle (Rosen
Trick)
return E : ET := Obj.all do
Free (Obj);
end return;
end Deque;
Here I didn't bother making the queue type tagged, but if you like
distinguished-receiver syntax, then you can do that too.
Regards,
Matt
P.S. I'll be giving a tutorial in Geneva at the end of June, to
discuss these sorts of techniques.
next prev parent reply other threads:[~2007-04-13 17:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-11 11:34 Impossible problem? A protected buffer to queue objects of a class-wide type Phil Slater
2007-04-11 12:25 ` Rob Norris
2007-04-11 13:02 ` Phil Slater
2007-04-12 8:36 ` Stephen Leake
2007-04-11 13:14 ` Dmitry A. Kazakov
2007-04-11 14:01 ` Jean-Pierre Rosen
2007-04-11 17:18 ` tmoran
2007-04-13 17:02 ` Matthew Heaney
2007-04-13 17:26 ` Matthew Heaney [this message]
2007-04-13 17:36 ` Ed Falis
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox