comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: generic imports?  void* -> generics?
Date: 23 Sep 2003 06:45:10 +0100
Date: 2003-09-23T06:45:10+01:00	[thread overview]
Message-ID: <x7vvfrkukgp.fsf@smaug.pushface.org> (raw)
In-Reply-To: vmuqao1m3adfd5@corp.supernews.com

"Randy Brukardt" <randy@rrsoftware.com> writes:

> The Claw package puts the stream element array inside of the wrapper
> type.  (The access discriminant is interesting, but it couldn't be
> used on slices or any constrained object, which would make it
> annoying to use.) That makes it a buffer. Usually, it is used by
> 'loading' the buffer by calling Write explicitly, then using the
> stream routines to read from it. (Or vice versa).

Yes, I have BC.Support.Memory_Streams which is like that. No trouble
if I'm starting from an empty stream. But if I've read the data over
the network, say, I need to copy the data into the buffer .. I think
my problem is, providing too much encapsulation, which limits what
users can do with the package. If I want to

  create a streaming buffer
  read data from a socket that has to write to a stream_element_array,
    cos it's datagram-oriented, directly into the buffer

I probably have to make the buffer part of the stream visible.

The new version looks like

   package BC.Support.Array_Streams is

      type Stream_Type
        (Buffer : access Ada.Streams.Stream_Element_Array)
      is new Ada.Streams.Root_Stream_Type with private;
      --  Provides an in-memory Stream over the elements of Buffer.
      --
      --  When one of these Stream_Types is created, it is notionally
      --  empty. If Buffer is not in fact empty (perhaps it has been read
      --  from a datagram socket), use Set_Last to indicate the index of
      --  the last valid element.

      function Last (Used_In : Stream_Type)
                    return Ada.Streams.Stream_Element_Offset;
      --  Returns the index in Used_In's Stream_Element_Array of the last
      --  used element.

      procedure Set_Last (Used_In : in out Stream_Type;
                          To : Ada.Streams.Stream_Element_Offset);
      --  Sets the index of the last valid element in Used_In's
      --  Stream_Element_Array.

      procedure Reset (Stream : out Stream_Type);
      --  Clears Stream.

   private

which is going to require some care to use!


On a style issue, do you think I should make Stream_Type's Read, Write
operations (which must be present because of the derivation from
Root_Stream_Type) visible?

I ask because (in another package) I had a Controlled type with a
visible Initialize and someone mistakenly called it .. I know they
could have done anyway, but its being there in the public part of the
package tempted them.



  reply	other threads:[~2003-09-23  5:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-19 19:20 generic imports? void* -> generics? chris
2003-09-19 20:46 ` chris
2003-09-19 21:18 ` Nick Roberts
2003-09-19 23:12   ` chris
2003-09-20 16:52   ` Simon Wright
2003-09-22 21:30     ` Randy Brukardt
2003-09-23  5:45       ` Simon Wright [this message]
2003-09-23 19:07         ` Randy Brukardt
2003-09-23 20:28           ` Simon Wright
2003-09-24 18:16             ` Randy Brukardt
2003-09-19 22:40 ` Matthew Heaney
2003-09-19 23:01   ` chris
2003-09-20  1:59   ` Jeffrey Carter
2003-09-20 13:52     ` Matthew Heaney
2003-09-23 22:39 ` chris
replies disabled

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