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-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!p10g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Runtime type selection Date: Mon, 12 Oct 2009 17:59:53 -0700 (PDT) Organization: http://groups.google.com Message-ID: 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> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1255395593 20896 127.0.0.1 (13 Oct 2009 00:59:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Oct 2009 00:59:53 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p10g2000prm.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8689 Date: 2009-10-12T17:59:53-07:00 List-Id: On Oct 11, 12:54=A0pm, 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 =A0Ada.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). -- Adam