From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6fb0eff797e41c12 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Dynamic Instantiation in Ada95 ? Date: 1998/04/15 Message-ID: #1/1 X-Deja-AN: 344347090 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <01BD6867.17421990.Matthias.Oltmanns@so.sema.de> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-04-15T00:00:00+00:00 List-Id: 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 <>; : 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