comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pcc482719@gmail.com>
Subject: Re: Encapsulating Ada.Direct_IO
Date: Wed, 17 Nov 2010 07:25:18 -0500
Date: 2010-11-17T07:25:18-05:00	[thread overview]
Message-ID: <tM6dnaTzn6shVH7RRVn_vwA@giganews.com> (raw)
In-Reply-To: <5ba4147a-6099-4a05-b548-09544f58247a@j18g2000yqd.googlegroups.com>

On 2010-11-16 23:44, Bryan wrote:

> Spec file:
> ======================
> with Ada.Direct_IO;
> package Big5_Text_IO is
>   type File_Type is limited private;
>   procedure Close( File : in out File_Type );
> private
>   package Byte_IO is new Ada.Direct_IO(Character);
>   type File_Type is new Byte_IO.File_Type;
> end Big5_Text_IO;
> ======================

Direct_IO allows random access. There is nothing wrong with that, of
course, but if your intention is to read the file sequentially you might
prefer using Sequential_IO.

Something I wonder about (I don't have the answer) is if it necessary to
use a representation clause to force the size of the objects being read
to be 8 bits. I'm a little unclear if the standard requires Character to
be stored in a file in 8 bit units. That is, the language might treat
the type Character rather more abstractly than you want. Again I'm not
sure of this and I'd love to get some insights from others myself.

Thus you might want to do something like

package Big5_Text_IO is
  ...
  type Byte is mod 2**8;
  for Byte'Size use 8;
  ...
private
  package Byte_IO is new Ada.Direct_IO(Byte);
  ...
end Big5_Text_IO;

This approach has the advantage of creating a separate type to represent
the raw data from the file. Thus

C : Character;
B : Big5_Text_IO.Byte;

C := B;  -- Compile error. You haven't decoded B yet.

Peter



  parent reply	other threads:[~2010-11-17 12:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-17  4:44 Encapsulating Ada.Direct_IO Bryan
2010-11-17  5:20 ` Adam Beneschan
2010-11-26 15:31   ` Bryan
2010-11-17 12:25 ` Peter C. Chapin [this message]
2010-11-18  1:16   ` Randy Brukardt
2010-11-18  2:21     ` Peter C. Chapin
2010-11-18 16:36       ` Adam Beneschan
2010-11-18 18:21         ` Peter C. Chapin
2010-11-18 18:36           ` Randy Brukardt
2010-11-18 19:48           ` Adam Beneschan
2010-11-18 20:15             ` Dmitry A. Kazakov
2010-11-18  7:39     ` AdaMagica
2010-11-18 18:38       ` Randy Brukardt
2010-11-18  9:46     ` Maciej Sobczak
2010-11-18 16:31     ` Adam Beneschan
2010-11-18 17:05       ` Dmitry A. Kazakov
     [not found]         ` <ENidndoH8qoqjHvRnZ2dnUVZ_j-dnZ2d@earthlink.com>
2010-11-19  8:24           ` Dmitry A. Kazakov
2010-11-19 16:19             ` Adam Beneschan
2010-11-18 18:45       ` Randy Brukardt
2010-11-24 21:31     ` Warren
2010-11-17 22:32 ` Yannick Duchêne (Hibou57)
2010-11-17 23:03   ` Adam Beneschan
2010-11-17 23:11     ` Yannick Duchêne (Hibou57)
replies disabled

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