comp.lang.ada
 help / color / mirror / Atom feed
From: Doug Rogers <rogers@innocon.com>
Subject: Sequential_Mixed_IO (DEC) for GNAT
Date: 1996/03/25
Date: 1996-03-25T00:00:00+00:00	[thread overview]
Message-ID: <4j794u$ldn@ra.nrl.navy.mil> (raw)

This is moved from another thread (Gripe about Ada...).

I have a requirement to use Ada83 only, 'cause it's DEC
Ada on OpenVMS AXP.  I need access to a heterogeneous
stream of data coming from a binary file.  DEC provides
a few packages for doing this "mixed" IO, one called
Sequential_Mixed_IO.  It includes a generic for getting
and putting typed data to disk.  Here are the basics of
it:

package Sequential_Mixed_IO is
  type File_Type is new System.Sequential_IO.File_Type;
  procedure Open (...);  -- all the standard file IO routines
  
  generic
    type Item_Type is private;
  procedure Get_Item (File : in File_Type; Item : out Item_Type);

  -- plus Put_Item, etc.
end Sequential_Mixed_IO;

  -- with's deleted
package body Sequential_Mixed_IO is
   -- NOTE: lots of stuff deleted
   package FIO renames System.File_IO;
   package FCB renames System.File_Control_Block;
   SU : constant := System.Storage_Unit;
   subtype AP is FCB.AFCB_Ptr;

--   generic
--      type Item_Type is private;
  procedure Get_Item
      (File : in File_Type;
       Item : out Item_Type) is
    Siz  : constant size_t := (Item'Size + SU - 1) / SU;
  begin -- Get_Item
    FIO.Check_Read_Status (AP (File));
    FIO.Read_Buf (AP (File), Item'Address, Siz);
  end Get_Item;

end Sequential_Mixed_IO;

The Open/Create procedures are NOT generic.  Now, I copied
the spec pretty much verbatim from DEC (with (c) notice!),
and then I began to implement the body.  I found that I
could only implement it by using .File_IO child package.
I simply copied the code from System.Sequential_IO.

This raised an uproar when I mentioned it on the
aforementioned thread.  "My GOD!  Someone is using a
GNAT-specific, totally unsupported, possibly changing
package for user code!"  I explained that it was prototype
code.  It works.  It allows me to do development in an
environment that's local (and not 28.8kb away).

There were calls out to make "with"-ing such packages
illegal.  Well, first the language makes it practically
impossible to get access to binary data (Sequential_IO on
a byte type doesn't cut it!), now even the low-level hacks
will be gone (yes, of course it's a hack -- conveniently
localized to only one file).

If you can know of an elegant way to get access to mixed
types from a binary file, please let me know.

I heard mention of streams (?) under Ada95.  I'll look into
that myself (I have to abandon Ada83 for my GNAT
compilations, anyway, 'cause my solution invokes a child
unit -- not allowed in Ada83 -- when the generic is
instantiated during compilation, a strictly GNAT thing).

Doug

=------cxiuj-opinioj-estas-sole-miaj.-----any-opinions-are-mine-alone.------=
= Doug Rogers      vocxe/voice = 1.703.893.2007  fakse/fax = 1.703.893.5890 =
= Innovative Concepts Inc; 8200 Greensboro Drive Suite 801; McLean VA 22102 =
= PGP ID: pub  1024/016DE91D 1994/11/14   Doug Rogers  <rogers@innocon.com> =
=senemankasalvimultodatempolernulaanglan-ifyouvegotalittletimelearnesperanto=





             reply	other threads:[~1996-03-25  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-25  0:00 Doug Rogers [this message]
1996-03-25  0:00 ` Sequential_Mixed_IO (DEC) for GNAT Robert Dewar
1996-03-27  0:00   ` Fergus Henderson
1996-03-27  0:00     ` Robert Dewar
1996-03-28  0:00       ` Fergus Henderson
replies disabled

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