From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a31b00ad713d92f9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!e65g2000hsc.googlegroups.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Impossible problem? A protected buffer to queue objects of a class-wide type Date: 13 Apr 2007 10:26:16 -0700 Organization: http://groups.google.com Message-ID: <1176485175.985643.16590@e65g2000hsc.googlegroups.com> References: <461cc46d$1_1@glkas0286.greenlnk.net> <1176483777.264139.239360@p77g2000hsh.googlegroups.com> NNTP-Posting-Host: 66.162.65.129 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1176485176 24148 127.0.0.1 (13 Apr 2007 17:26:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 13 Apr 2007 17:26:16 +0000 (UTC) In-Reply-To: <1176483777.264139.239360@p77g2000hsh.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: e65g2000hsc.googlegroups.com; posting-host=66.162.65.129; posting-account=Zl1UPAwAAADEsUSm1PMMiDjihtBlZUi_ Xref: g2news1.google.com comp.lang.ada:14989 Date: 2007-04-13T10:26:16-07:00 List-Id: On Apr 13, 1:02 pm, "Matthew Heaney" wrote: > On Apr 11, 6:34 am, "Phil Slater" 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.