comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: generics and records
Date: Mon, 28 Feb 2005 09:47:44 +0100
Date: 2005-02-28T09:44:50+01:00	[thread overview]
Message-ID: <m05fa5ekbqwi$.1h01o0vxpo7hw$.dlg@40tude.net> (raw)
In-Reply-To: 1109539865.754582.147740@o13g2000cwo.googlegroups.com

On 27 Feb 2005 13:31:05 -0800, spambox@volja.net wrote:

> Dmitry A. Kazakov wrote:
> 
>> 2. Inheritance from a record type with known components:
>>
>> type Common_Base is tagged record
>>    A : Float; -- This will be visible in Foo
>> end record;
>>
>> generic
>>    type Record_Type is new Common_Base with private;
>> package Foo is
>>    ...
>>
>> Instantiation:
>>
>> type My_Record is new Common_Base with record
>>    ... -- These new components will be inaccessible in Foo!
>> end record;
>> package My_Foo is new Foo (My_Record);
> 
> Thanks for the prompt response. One more question: how do I make the
> components (the whole record?) known? Where must it be declared?

You can't do that. Ada has a contract model of generics. That means that
Foo in the example above will never directly see the whole record, only its
Common_Base part. The primitive operations defined on Common_Base will. So
if Foo has to access all record, the only way to do it is to express what
Foo should do in terms of primitive operations defined on Common_Base. They
can dispatch to the specific operations defined on the actual type.
Usually, it is sufficient for all purposes and also is a good OO-ish
programming style. But there is no way to write a generic unit working with
whatever components of an actual parameter. Ada does not provide abstract
record interfaces with enumeration of components and their types at run
time. Though you can implement something close to that using map container
types instead of record types. Probably this is what you actually need. But
again, to work through primitive operations is better.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-02-28  8:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-27 19:34 generics and records spambox
2005-02-27 20:16 ` Dmitry A. Kazakov
2005-02-27 21:31   ` spambox
2005-02-28  8:47     ` Dmitry A. Kazakov [this message]
2005-02-28  9:00       ` spambox
2005-02-28 10:07         ` Dmitry A. Kazakov
2005-02-28  6:02 ` Jeffrey Carter
2005-03-01 11:21 ` Martin Krischik
2005-03-01 19:47   ` Georg Bauhaus
2005-03-01 20:17     ` Dmitry A. Kazakov
replies disabled

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