comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Runtime type selection
Date: Tue, 13 Oct 2009 10:01:58 +0300
Date: 2009-10-13T10:01:58+03:00	[thread overview]
Message-ID: <4ad42604$0$6263$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <cf8b99d7-c675-4002-bf33-9f3d00096111@p10g2000prm.googlegroups.com>

Adam Beneschan wrote:
> On Oct 11, 12:54 pm, Niklas Holsti <niklas.hol...@tidorum.invalid>
> wrote:
>> xorque wrote:
>>> On Oct 11, 5:02 pm, Niklas Holsti <niklas.hol...@tidorum.invalid>
>>> wrote:
>>>> Keep a list or array of (accesses to) a factory function for each
>>>> possible (derived) type.
>>> 'Lo,
>>> That does sound like the sort of thing I'd have done in C.
>> Yes. Ada makes it easier since you can use elaboration-time statement
>> blocks in package bodies to register stuff.
>>
>>> I still
>>> have a nagging sensation that Ada actually provides other means to
>>> do this based on such things as the 'Tag attribute.
>> Did you read about the package Ada.Tags (RM 3.9)? There is a generic
>> function Ada.Tags.Generic_Dispatching_Constructor that takes a tag as
>> parameter and creates an object with that tag, but I don't hink there is
>> any way to find the tags for all types in a given derivation class. So
>> even with  Ada.Tags.Generic_Dispatching_Constructor your program still
>> has to register the types, or their tags, or a prototype object of each
>> type, to create the program-accessible set of types/tags that can be in
>> the graph.
>>
>> Perhaps some expert can explain why this reflection capability (find
>> tags for all derived types in a class) was not included in Ada.Tags?
>> Perhaps because Ada run-time systems do not need such a function for
>> their own purposes?
> 
> Maybe I don't understand the problem clearly enough, but would
> Ada.Tags.Descendant_Tag help?  This takes an external tag (a string)
> and the 'Tag of the ancestor type, and will find a type in the
> ancestor type's class whose 'External_Tag is the given external tag
> string (as long as it's not more deeply nested than the ancestor
> type).

The program would still need to get the set of valid external tag 
strings from somewhere -- it could not just try one random string after 
another, blindly. As I understand the OP's problem, the program contains 
a base tagged type from which several types are derived, and the OP 
wants a method to create an object of some, randomly chosen, derived 
type. Ada.Tags.Descendant_Tag could be used only if the program 
registers the external tags for all such derived types in some central 
data structure. The OP intends to register the tags of the derived 
types, which is simpler.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  reply	other threads:[~2009-10-13  7:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-11 16:41 Runtime type selection xorque
2009-10-11 17:02 ` Niklas Holsti
2009-10-11 17:15   ` xorque
2009-10-11 19:54     ` Niklas Holsti
2009-10-12  9:26       ` Georg Bauhaus
2009-10-12 12:02         ` xorque
2009-10-12 23:42       ` Randy Brukardt
2009-10-13  6:50         ` Niklas Holsti
2009-10-13  0:59       ` Adam Beneschan
2009-10-13  7:01         ` Niklas Holsti [this message]
2009-10-11 17:15 ` mockturtle
2009-10-11 20:06 ` Dmitry A. Kazakov
2009-10-13 10:45   ` Colin Paul Gloster
2009-10-13 10:17     ` Dmitry A. Kazakov
2009-10-13 15:11 ` xorque
2009-10-13 15:50   ` Dmitry A. Kazakov
2009-10-13 16:02     ` xorque
replies disabled

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