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,FREEMAIL_FROM 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!postnews.google.com!k33g2000yqa.googlegroups.com!not-for-mail From: xorque Newsgroups: comp.lang.ada Subject: Re: Runtime type selection Date: Tue, 13 Oct 2009 08:11:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2100432e-0c92-4776-9878-51a75fffc90b@k33g2000yqa.googlegroups.com> References: <2c15c8a6-b555-4d08-8fe6-f77cb207e7a6@k33g2000yqa.googlegroups.com> NNTP-Posting-Host: 78.143.202.207 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1255446699 24529 127.0.0.1 (13 Oct 2009 15:11:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Oct 2009 15:11:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k33g2000yqa.googlegroups.com; posting-host=78.143.202.207; posting-account=D9GNUgoAAAAmg7CCIh9FhKHNAJmHypsp User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.0.13) Gecko/2009081019 Firefox/3.0.13,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8698 Date: 2009-10-13T08:11:39-07:00 List-Id: 'Lo. I'm currently still a little lost as to how to use Ada.Tags.Generic_Dispatching_Constructor correctly. I have the following test package: with Ada.Numerics.Discrete_Random; with Ada.Tags.Generic_Dispatching_Constructor; with Ada.Tags; with Circle; with Square; package body Shape_Selector is package Tags renames Ada.Tags; -- -- Names associated with types. -- type Shape_Name_t is (Shape_Class, Circle_Class, Square_Class); package Shape_Name_Random is new Ada.Numerics.Discrete_Random (Result_Subtype => Shape_Name_t); Random_Context : Shape_Name_Random.Generator; Shape_Names : constant array (Shape_Name_t) of Tags.Tag := (Shape_Class => Shape.Shape_t'Tag, Circle_Class => Circle.Circle_t'Tag, Square_Class => Square.Square_t'Tag); type Unused_t is null record; function Construct (Params : not null access Unused_t) return Shape.Shape_t'Class is begin -- What?! end Construct; function Dispatching_Constructor is new Ada.Tags.Generic_Dispatching_Constructor (T => Shape.Shape_t'Class, Parameters => Unused_t, Constructor => Construct); -- -- Select a shape at random from Shape_Names. -- function Select_Shape return Shape.Shape_t'Class is Shape_Name : constant Shape_Name_t := Shape_Name_Random.Random (Random_Context); Unused : aliased Unused_t; begin return Dispatching_Constructor (The_Tag => Shape_Names (Shape_Name), Params => Unused'Unchecked_Access); end Select_Shape; end Shape_Selector; I have selected a Tag at random from the Shape_Names array and have passed it to the Dispatching_Constructor procedure but don't know what I'm supposed to put in Construct in this case. I don't see how I can know what type I'm supposed to be constructing (or how I would, even if I was to pass the Tag via Params).