From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,29f36805b9a20fe8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-31 15:11:03 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!falcon.america.net!newspump.monmouth.com!newspeer.monmouth.com!news.maxwell.syr.edu!newsfeed.skycache.com!Cidera!europa.netcrusader.net!64.154.60.72!cyclone2.usenetserver.com!news-out.usenetserver.com!telocity-west!TELOCITY!newsrump.sjc.telocity.net!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada References: <3AC64324.A79AE084@worldnet.att.net> Subject: Re: Streams in Ada MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: X-Trace: MRQwIE5vQXV0aHNzZXIgVEVMT2VJVFktdEVBREVSUyAyMTYuMjI3LjQ3CDQ5ICBTYXQsIBUxIGth!ciAyFjAxBjETOhcwOjA1IFBTVA== X-Abuse-Info: Please forward ALL headers when reporting abuse. X-Complaints-To: abuse@telocity.net NNTP-Posting-Date: Sat, 31 Mar 2001 15:10:05 PST Date: Sat, 31 Mar 2001 17:10:30 -0600 Xref: supernews.google.com comp.lang.ada:6305 Date: 2001-03-31T17:10:30-06:00 List-Id: 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" 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 > >