comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Streams in Ada
Date: Sat, 31 Mar 2001 17:10:30 -0600
Date: 2001-03-31T17:10:30-06:00	[thread overview]
Message-ID: <httx6.2118$mA.961077@newsrump.sjc.telocity.net> (raw)
In-Reply-To: XRrx6.7012$u93.987018@news6-win.server.ntlworld.com

Stream_Elements are the smallest addressable element of the medium
usually an octet (8 bits).

The Index (position) of a stream file can be read using the function
Ada.Streams.Stream_IO.Index, and the index can be set using the
procedure Ada.Streams.Stream_IO.Set_Index.

The first index of a file is 1.

Read and write operations are automatically declared for
every type you declare, so you can just call Superblock_type'Read,
Superblock_type'Write, etc. when the file index is appropriately
positioned.

The 'Read and "write procedures defined by the compiler follow
certain rules which may not be appropriate for some types you
could declare. For example, if a record has elements that do not
begin and end on byte boundaries, you can override the compiler-
defined procedures with your own.

Here is an example of such a type, where a 32-bit record has a
31-bit component, and a 1-bit component.

-- Part of package specification:
with Ada.Streams;
   .
   .
   .
   type An_Hour_Fraction is
     delta 3600.0 * 2.0 ** (-31) range 0.0 .. 3600.0;
   for An_Hour_Fraction'Small use 3600.0 * 2.0 ** (-31);
   for An_Hour_Fraction'Size use 31;
   type A_Time_Stamp_Kind is (Relative, Absolute);
   for A_Time_Stamp_Kind use (Relative => 0, Absolute => 1);
   for A_Time_Stamp_Kind'Size use 1;

   type A_Time_Stamp is
      record
         Seconds : An_Hour_Fraction;
         Kind : A_Time_Stamp_Kind;
      end record;
   for A_Time_Stamp use
      record
         Seconds at 0 range 0 .. 30;
         Kind at 0 range 31 .. 31;
      end record;
   for A_Time_Stamp'Size use 32;

private
   procedure Read_Time_Stamp
               (Stream : access Ada.Streams.Root_Stream_Type'Class;
                Item : out A_Time_Stamp);

   procedure Write_Time_Stamp
               (Stream : access Ada.Streams.Root_Stream_Type'Class;
                Item : in A_Time_Stamp);
   for A_Time_Stamp'Read use Read_Time_Stamp;
   for A_Time_Stamp'Write use Write_Time_Stamp;




-- Part of package body:
 with Ada.Unchecked_Conversion;
with Interfaces;
   .
   .
   .
   function To_Time_Stamp is new Ada.Unchecked_Conversion
     (Source => Interfaces.Unsigned_32,
      Target => A_Time_Stamp);

  function To_Unsigned_32 is new Ada.Unchecked_Conversion
     (Source => A_Time_Stamp,
      Target => Interfaces.Unsigned_32);

    procedure Read_Time_Stamp
     (Stream : access Ada.Streams.Root_Stream_Type'Class;
      Item : out A_Time_Stamp) is
   begin
     Item := To_Time_Stamp (Interfaces.Unsigned_32'Input (Stream));
  end Read_Time_Stamp;

    procedure Write_Time_Stamp
     (Stream : access Ada.Streams.Root_Stream_Type'Class;
      Item : in A_Time_Stamp) is
   begin
      Interfaces.Unsigned_32'Write
        (Stream,
         To_Unsigned_32 (Item));
   end Write_Time_Stamp;


"chris.danx" <chris.danx@ntlworld.com> wrote in message
news:XRrx6.7012$u93.987018@news6-win.server.ntlworld.com...
> Direct IO handles single type files, i.e. all file elements are the same.
I
> want different types in the file i.e. heterogeneous files.  Streams allow
> this so i need streams.
>
> I want to allow the reading and writing of 3 or 4 types.
>
>     type Superblock_type;
>     type Inode_type;
>     type Data_block_type;
>     type FileInfo_block_type;
>
> surely then i want streams.  I did think about direct io but i'd have
severe
> performance losses in the conversion to the smallest unit -- in this case
> byte_type;  Maybe i am looking in the wrong place.
>
> All i want is an example of how to access files using streams in a non
> sequential manner with one or two types.
>
> Cheers,
> Chris Campbell
>
>




  parent reply	other threads:[~2001-03-31 23:10 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-31 14:49 Streams in Ada chris.danx
2001-03-31 15:22 ` chris.danx
2001-03-31 21:37   ` Jeff Creem
2001-03-31 21:49     ` chris.danx
2001-03-31 22:21       ` Robert A Duff
2001-03-31 22:33         ` chris.danx
2001-04-02 13:47         ` Ted Dennison
2001-04-02 14:03           ` Florian Weimer
2001-04-02 14:29             ` Ted Dennison
2001-04-02 14:54               ` Robert A Duff
2001-04-02 14:47             ` Marin David Condic
2001-04-02 15:10               ` Florian Weimer
2001-04-02 15:49                 ` Ted Dennison
2001-04-02 16:57                   ` Marin David Condic
2001-04-02 17:43                     ` PDP-10, was " tmoran
2001-04-02 17:49                     ` Robert A Duff
2001-04-02 22:09                       ` 6-bit characters (was: Re: Streams in Ada) Jeffrey Carter
2001-04-02 23:29                         ` Robert A Duff
2001-04-03 16:41                           ` Jeffrey Carter
2001-04-03 17:57                             ` Florian Weimer
2001-04-03 18:19                               ` Marin David Condic
2001-04-05 18:37                                 ` Tucker Taft
2001-04-03 18:04                             ` Marin David Condic
2001-04-06 22:40                             ` Robert A Duff
2001-04-03 14:10                         ` Marin David Condic
2001-04-03  1:57                       ` Streams in Ada Larry Kilgallen
2001-04-03 14:13                         ` Marin David Condic
2001-04-13 23:21                         ` Robert A Duff
2001-04-02 17:41                   ` Florian Weimer
2001-04-02 18:17                     ` Robert A Duff
2001-04-02 19:36                       ` Marin David Condic
2001-04-02 20:54                         ` Robert A Duff
2001-04-03 10:10                         ` Florian Weimer
2001-04-03 14:21                           ` Marin David Condic
2001-04-03 18:15                             ` Florian Weimer
2001-04-03 23:21                               ` Robert A Duff
2001-04-02 21:13                       ` Florian Weimer
2001-04-02 21:22                         ` Robert A Duff
2001-04-03 10:02                           ` Florian Weimer
2001-04-02 16:42                 ` Marin David Condic
2001-04-13  5:00                 ` David Thompson
2001-03-31 20:48 ` James Rogers
2001-03-31 21:20   ` chris.danx
2001-03-31 21:22     ` chris.danx
2001-03-31 23:10     ` David C. Hoos, Sr. [this message]
2001-04-01 11:27       ` chris.danx
2001-04-02 14:12     ` Ted Dennison
2001-04-02 14:00   ` Ted Dennison
  -- strict thread matches above, loose matches on Subject: below --
2001-04-05 14:24 Brian Gaffney
2001-04-06 22:54 ` Robert A Duff
replies disabled

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