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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2a77c9c618b7919 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Received: by 10.68.213.103 with SMTP id nr7mr9246021pbc.7.1351478371553; Sun, 28 Oct 2012 19:39:31 -0700 (PDT) Path: s9ni66434pbb.0!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!newsreader4.netcologne.de!news.netcologne.de!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 24 Oct 2012 16:03:51 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada.Storage_IO: applied example? References: <1idlxs32flh5u.fi8rvodiy7c2.dlg@40tude.net> In-Reply-To: Message-ID: <5087f544$0$6572$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 24 Oct 2012 16:03:48 CEST NNTP-Posting-Host: 0546b8ec.newsspool3.arcor-online.net X-Trace: DXC=IjVQid3]0I1TQL:hoD@>T?McF=Q^Z^V384Fo<]lROoR18kF:Lh>_cHTX3j=NGRADjgdWa3 X-Complaints-To: usenet-abuse@arcor.de X-Received-Bytes: 6423 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2012-10-24T16:03:48+02:00 List-Id: On 24.10.12 13:51, Yannick DuchĂȘne (Hibou57) wrote: > Le Wed, 24 Oct 2012 12:28:00 +0200, Dmitry A. Kazakov > a Ă©crit: > >> On Wed, 24 Oct 2012 02:49:02 -0700 (PDT), AdaMagica wrote: >> >>> See AARM A.9(1.a): >>> Reason: This package exists to allow the portable construction of >>> user-defined direct-access-oriented input-output packages. >> >> portable construction of X /= construction of portable X >> >> The package cannot be used to write files in a way that an application >> compiled by one compiler X1 under OS Y1 could write a file readable for >> compiler X2 under OS Y2. >> >> In order to be portable they should have defined the exact representation >> of the object in the file. Yes, nobody would do that, but then they should >> not include useless packages into the standard either. > > What about private persistent storage? > If traditional Ada I/O is good for your Ada program, you can use Storage_IO in conventional algorithms this way. The setup can employ static polymorphism that allows selecting instances of Storage_IO or Direct_IO as needed. Either at startup or later. The solution, using the egregious generic mechanisms of Ada, will suffer from all the advantages of lack of an unused tagged parameter. The whole approach of stating requirements as generic formals suffers from good opportunities for compilers to perform optimization. It suffers from the fact that stored internal program data is not being stored in an ISO-approved form ready for inspection by non-generic programs of an unrelated make and purpose. It also suffers from the problem that it still cannot make the external world an Ada object, which could mollify the previously argued flaw. It suffers from lack of opportunities to control I/O of octets algorithmically, thus preventing emulation of nice per-program Storage_IO objects in DIY fashion. It also suffers from not being a silver bullet. But other than that ... with Ada.Direct_IO; with Ada.Storage_IO; with Ada.Command_Line; use Ada.Command_Line; procedure Lookahead is use Ada; type Sentence (Length : Positive := 100) is record Text : Wide_String (1 .. 100); end record; subtype Name is Wide_String (1 .. 20); type Big is record -- objects that will be processed First, Last : Name; Age : Natural; Motto : Sentence; end record; generic with procedure Store_Single_Item (Item : in Big); with procedure Fetch_Single_Item (Item : out Big); procedure Process_Records; procedure Process_Records is separate; begin if Natural'Value (Argument(1)) = 0 then declare package Volatile is procedure Store (Item : in Big); procedure Fetch (Item : out Big); end Volatile; package body Volatile is package Undo_Buffer is new Storage_IO (Big); Storage : Undo_Buffer.Buffer_Type; procedure Fetch (Item : out Big) is begin Undo_Buffer.Read (Storage, Item); end Fetch; procedure Store (Item : in Big) is begin Undo_Buffer.Write (Storage, Item); end Store; end Volatile; procedure Run is new Process_Records (Store_Single_Item => Volatile.Store, Fetch_Single_Item => Volatile.Fetch); begin Run; end; else declare package Permanent is procedure Store (Item : in Big); procedure Fetch (Item : out Big); end Permanent; package body Permanent is package Undo_Buffer is new Direct_IO (Big); Storage : Undo_Buffer.File_Type; procedure Fetch (Item : out Big) is begin Undo_Buffer.Read (Storage, Item); end Fetch; procedure Store (Item : in Big) is begin Undo_Buffer.Write (Storage, Item); end Store; use Undo_Buffer; begin open (storage, Inout_File, "item.sto"); end Permanent; procedure Run is new Process_Records (Store_Single_Item => Permanent.Store, Fetch_Single_Item => Permanent.Fetch); begin Run; end; end if; end Lookahead; separate (Lookahead) procedure Process_Records is package Rec_IO is new Direct_IO (Big); use Rec_IO; Current: Big := (Age => Natural'Last, others => <>); input : File_Type; output : File_Type; begin open (input, In_File, "records.all"); open (output, Out_File, "records.flt"); loop Store_Single_Item (Current); Read (input, current); -- ... filter based on pairs ... write (output, current); end loop; end Process_Records;