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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c7ff90b15f15636c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!peer1.news.newnet.co.uk!news.tele.dk!news.tele.dk!small.news.tele.dk!fi.sn.net!newsfeed2.fi.sn.net!news.song.fi!not-for-mail Date: Tue, 13 Oct 2009 10:01:58 +0300 From: Niklas Holsti Organization: Tidorum Ltd User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Runtime type selection References: <2c15c8a6-b555-4d08-8fe6-f77cb207e7a6@k33g2000yqa.googlegroups.com> <4ad20fd5$0$26308$4f793bc4@news.tdc.fi> <61d081f4-cccc-4575-927f-5c400b73ff90@k19g2000yqc.googlegroups.com> <4ad23819$0$6256$4f793bc4@news.tdc.fi> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4ad42604$0$6263$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 81.17.205.61 X-Trace: 1255417349 news.tdc.fi 6263 81.17.205.61:51320 X-Complaints-To: abuse@tdcnet.fi Xref: g2news2.google.com comp.lang.ada:8691 Date: 2009-10-13T10:01:58+03:00 List-Id: Adam Beneschan wrote: > On Oct 11, 12:54 pm, Niklas Holsti > wrote: >> xorque wrote: >>> On Oct 11, 5:02 pm, Niklas Holsti >>> 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 . @ .