From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Design help
Date: Sat, 10 Mar 2007 14:38:05 +0100
Date: 2007-03-10T14:38:05+01:00 [thread overview]
Message-ID: <87abylnrr6.fsf@ludovic-brenta.org> (raw)
In-Reply-To: mailman.116.1173480208.18371.comp.lang.ada@ada-france.org
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.
next prev parent reply other threads:[~2007-03-10 13:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-09 22:43 Design help Carroll, Andrew
2007-03-09 23:07 ` Simon Wright
2007-03-10 1:00 ` Jeffrey R. Carter
2007-03-10 4:40 ` Steve
2007-03-10 13:38 ` Ludovic Brenta [this message]
2007-03-17 20:34 ` Michael Erdmann
-- strict thread matches above, loose matches on Subject: below --
2007-03-13 0:50 Carroll, Andrew
2007-03-13 2:48 ` Randy Brukardt
2007-03-13 8:52 ` Stuart
2007-03-13 9:40 ` Dmitry A. Kazakov
2007-03-13 20:18 ` Simon Wright
2007-03-13 22:22 ` Randy Brukardt
2007-03-26 14:56 Carroll, Andrew
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox