comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Conceptual Ada Problems
Date: 1996/09/29
Date: 1996-09-29T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023180002909961318230001@news.ni.net> (raw)
In-Reply-To: Pine.GSO.3.93.960929230049.29986A-100000@firefly.sd.monash.edu.au


In article
<Pine.GSO.3.93.960929230049.29986A-100000@firefly.sd.monash.edu.au>,
Vasilios Tourloupis <vasilios@insect.sd.monash.edu.au> wrote:

>* Is there some way I would be able to access key fields
>  of generic data types (records)?

I'm not sure what you mean: Can you be more specific?

>* Is there some way of storing/retrieving records in an Ada.Direct_IO
>  file using key fields of records rather than their location in the file?

As far as I know, the only way to retrieve records using Direct_IO all by
itself is via the Index.

Of course, you could create another abstraction the does allow you to
retrieve records via a key field, that is implemented using Direct_IO.  You
could keep the key-to-index map in a (smaller) seperate file, so that your
abstraction actually comprises 2 files.  When you initialize the
abstraction, it could read into memory the key-to-index file, and during
lookups, use that info to determine the index position of the record in the
direct file.

>* I am not quite sure how to declare functions/procedures as formal
>  parameters to a function/procedure.

If you're using Ada 83, then make the package or the subprogram generic:

   generic
      with procedure P (<args here>);
   procedure Generic_Op (<its args here>);

or

   generic
      with procedure P (...);
   package Generic_Ops is

To use it, you instantiate it:

   procedure P (...) is ...

   procedure Op is new Generic_Op (P);

If you're using Ada 95, then you can still do that, and in addition declare
subprogram pointers:

   type P_Access is access procedure (...);
   procedure Op (..., P : P_Access);

Then no instantiation is required:

   procedure P (...) is ...

   Op (... P'Access);


Give me an example of what you want to do.

>* Also, the Ada compiler complains about some subtype mark being
>  required, in declaring an array comprising of generic linked lists.
>  Any suggestions on how to overcome this are more than welcome, as
>  I have been trying all day, to no avail!

Show me the code that doesn't compile, and then I'll be able to tell you why.

Make sure your array comprises an actual type: you don't get a type from a
generic package directly, only from its instantiation:

   generic
      type T is private;
   package Lists is
      type List is private;
       ...

   type List_Array is (Positive range <>) of Lists.List;   -- not legal Ada

Instantiate first:

   package Integer_Lists is new Lists (Integer);

   type Integer_List_Array is (Positive range <>) of Integer_Lists.List;  -- OK


>Basically, what I am trying to implement is an hash table with the
>ability to save and load records to and from a direct IO file,
>respectively.  Any other suggestions and/or pointers are more than
>welcome.

Again, maybe you want to store off the map (hash table) in another file.

Of course, if you are using Ada 95, then you could play around with
Streams_IO.  It lets you do heterogeneous storage, so maybe you wouldn't
need 2 separate (homogeneous) file.

>Bill Tourloupis

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271




  parent reply	other threads:[~1996-09-29  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-29  0:00 Conceptual Ada Problems Vasilios Tourloupis
1996-09-29  0:00 ` Larry Kilgallen
1996-09-29  0:00   ` Robert Dewar
1996-09-29  0:00 ` Matthew Heaney [this message]
1996-10-01  0:00 ` Dale Stanbrough
replies disabled

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