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-Thread: 103376,28a24746aa07c732 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Sat, 10 Mar 2007 07:41:35 -0600 From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Design help References: Date: Sat, 10 Mar 2007 14:38:05 +0100 Message-ID: <87abylnrr6.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:d51GMqw5Ij8xTo9MZ17fvF6evAg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 62.235.213.189 X-Trace: sv3-2tnA05HNYYwIxXuq1EGNZI4S80m0IJoCHYuoCBl2yoFeyCcoA9VFcUv2D1f90oqFoqNBEgE0etHUatV!MAHqtlyJ6UEFSKzvqXjJcDzJPBLLT2gy4ovfSv5J7cK3khdU/Mo5vad45fsGKMi+WpO+rLn7zuA= X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.34 Xref: g2news1.google.com comp.lang.ada:14449 Date: 2007-03-10T14:38:05+01:00 List-Id: Andrew Carrol writes: > I am trying to design (what I guess is) a database table adapter. Yes, > it is a master's course assignment. The current design is to use a file > and have one record per line. My goal is to get each line to be > "serialized" so I can read the whole line in bytes and then take chunks > of it and "cast" those into objects. The answer depends on whether or not your file contains fixed-width records. If that is the case, I would simply declare a record type and use Sequential_IO for the record type directly, like e.g. type Seconds_Since_Epoch is new Ada.Interfaces.Unsigned_32; type DB_Record is record Primary_Key : Ada.Interfaces.Unsigned_32; Name : String (1 .. 20); Address : String (1 .. 100); Date_Of_Birth : Seconds_Since_Epoch; end record; package DB_Record_IO is new Ada.Sequential_IO (Element_Type => DB_Record); But if, on the other hand, the file contains variable-width records, such as comma-separated values (CSV), you will need more sophisticated conversion functions. In that case, I would use Ada.Streams.Stream_IO directly and convert the Stream_Elements one by one. If you want to convert to objects of tagged types, you should provide a constructor function for your tagged type, like so: type T is tagged record ... end record; function To_T (Raw_Bytes : in Ada.Streams.Stream_Element_Array) return T; HTH Note that the database file will probably not contain the tag itself. OTOH, if it does, then you can just use streams. -- Ludovic Brenta.