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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7876e4356325725b X-Google-Attributes: gid103376,public From: dennison@telepath.com Subject: Re: Ada.Streams examples Date: 1999/03/11 Message-ID: <7c8nbc$4dr$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 453806486 References: <36e61db4.50430543@news.pacbell.net> <7c64kl$r8s$1@nnrp1.dejanews.com> <36E6C291.F97766CB@Boeing.com> <7c6q9p$g28$1@nnrp1.dejanews.com> <36E7036B.EADEEA80@Boeing.com> X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Mar 11 15:26:49 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.5 [en] (WinNT; I) Date: 1999-03-11T00:00:00+00:00 List-Id: In article <36E7036B.EADEEA80@Boeing.com>, Rex Reges wrote: > A container can be accessed by a single task at a time (only one packer at a > time). However, two or more containers could be in the process of being filled > at the same time, but only one task is allowed to do this work for any one > container. The honor system will be used, so a guard task isn't necessary. > > When the container is filled, then an exception should be raised. The choice > then is to either use two containers or to use a bigger container. Good. You are making things very easy for yourself. I needed something more like a pipe, so it was considerably more difficult for me. All you'd have to do in this case is create a simple buffer (an Ada.Stream.Stream_Element_Array), and keep track of the read and write pointers in the Stream's tagged type. I'd put a pointer to the buffer in the stream type, and add a constructor procedure to allocate the array with a given size and a destructor procedure to deallocate it: private type Buffer_Ptr is access all Ada.Streams.Stream_Element_Array; type Stream is new Ada.Streams.Root_Stream_Type with record Head : Index := 1; Tail : Index := 1; Elements : Buffer_Ptr; end record; All you'd have to do after that is: o override "Write" to copy the given stream elements into the buffer at the write pointer, and update the write pointer. o override "Read" to copy the requested amount of stream elements from the buffer at the read pointer, and update the read pointer. If you wanted to get really sexy, I suppose you could implement "Open" calls to prevent Reads from streams that are opened for Writes and the like. T.E.D. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own