comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Dynamic Instantiation in Ada95 ?
Date: 1998/04/15
Date: 1998-04-15T00:00:00+00:00	[thread overview]
Message-ID: <ErGpov.6JH.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 01BD6867.17421990.Matthias.Oltmanns@so.sema.de


Matthias Oltmanns (Matthias.Oltmanns@SO.SEMA.DE) wrote:

: I would like to implement a kind of runtime instantiation for class-wide
: types, where the concrete type is not known
: at compile time.
: I've searched for a method in exact that way as S'Class'Input is working.
: S'Class'Input first reads the external tag name from a stream and than
: makes a dispatching call to the appropriate S'Input method.

: Example:
: ...
:     type Base is tagged with null record;

:     function Create return Base;
:     --
:     function Create_Dynamic (Tag_Name : String) return Base'Class;
:  ...
:    << Some type-extensions for the type Base >>
: ...

: I would like to implement the function as follows:

:    function Create_Dynamic (Tag_Name : String) return Base'Class is
:      T : Ada.Tags.Tag := Ada.Tags.Internal_Tag (Tag_Name);
:     begin
:         return <<dispatching call to Create using tag T>>;
:     end Create_Dynamic;

: Is there a way to do that? I've found only some dirty hacks, using
: unchecked_deallocation , for T'Address use ...
: and so on.

No, there is no easy way to use the external or internal tag value
as a way to drive dynamic object creation (the word "dynamic 
instantiation" will probably make most Ada people think of
generic instantiation).

: I'am interresting for a more portable approach. Any suggestions?

I recommend you create your own registration table, where
you register object-creating functions (by storing an
access-to-subprogram value designating them), one for each
distinct type you want to be able to create.  The registration
table would be indexed by some kind of ID (conceivably the
external tag, though any unique ID would do).  You use this
ID to index into the registration table and get a pointer to the
object-creating function, and then you call that and return
the result.

: Matthias Oltmanns,  Email: Matthias.Oltmanns@so.sema.de, Phone: +49 4421
: 802 207, Fax: +49 4421 802 444,
: SEMA GROUP GmbH Wilhelmshaven (Germany) - Special Systems Division -

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




  reply	other threads:[~1998-04-15  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-15  0:00 Dynamic Instantiation in Ada95 ? Matthias Oltmanns
1998-04-15  0:00 ` Tucker Taft [this message]
1998-04-16  0:00 ` Stephen Leake
1998-04-16  0:00   ` Matthew Heaney
1998-04-17  0:00 ` Robert Dewar
replies disabled

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