From: dennison@telepath.com
Subject: Re: Ada.Streams examples
Date: 1999/03/11
Date: 1999-03-11T00:00:00+00:00 [thread overview]
Message-ID: <7c8nbc$4dr$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 36E7036B.EADEEA80@Boeing.com
In article <36E7036B.EADEEA80@Boeing.com>,
Rex Reges <Rex.R.Reges@Boeing.com> 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
next prev parent reply other threads:[~1999-03-11 0:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-10 0:00 Ada.Streams examples Tom Moran
1999-03-10 0:00 ` dennison
1999-03-10 0:00 ` Tom Moran
1999-03-10 0:00 ` dennison
1999-03-10 0:00 ` Tom Moran
1999-03-11 0:00 ` dennison
1999-03-17 0:00 ` Tom Moran
1999-03-11 0:00 ` Richard D Riehle
1999-03-11 0:00 ` Steve Quinlan
1999-03-11 0:00 ` Richard D Riehle
1999-03-11 0:00 ` Steve Quinlan
1999-03-12 0:00 ` Richard D Riehle
1999-03-10 0:00 ` Rex Reges
1999-03-10 0:00 ` dennison
[not found] ` <36E7036B.EADEEA80@Boeing.com>
1999-03-11 0:00 ` dennison [this message]
1999-03-10 0:00 ` Steve Quinlan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox