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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1e36228aae0595da X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Access to function returning class-wide type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <48ad5922$0$20706$9b4e6d93@newsspool4.arcor-online.net> Date: Thu, 21 Aug 2008 15:50:04 +0200 Message-ID: <9bmxv7t985ke$.p14upop2x80z.dlg@40tude.net> NNTP-Posting-Date: 21 Aug 2008 15:50:07 CEST NNTP-Posting-Host: 403c5ce0.newsspool1.arcor-online.net X-Trace: DXC=MZ7;@j_7@Tm]l@YUW5NBknic==]BZ:afn4Fo<]lROoRa4nDHegD_]RefhoARLlDggcDNcfSJ;bb[eIRnRBaCd On Thu, 21 Aug 2008 15:01:01 +0200, Pawe� 'Nivertius' P�azie�ski wrote: > First of all, the problem with that is, that I couldn't define conditions > and types for them dynamicaly. > Second (of all?), each new Derived type in child, or even remotely other > package needs to be hard-coded into examples package A. > > I have a map between condition on an object of some type (in example it > was 'N') and access-to-function which creates the object derived from > Abstracted. I've also got funcion which gets the 'object of some type' and > for each key in the map checks if the condition is true. If so, > calls 'constructor' passing that 'object of some type' and returns its > result. If no condition is true, the function raises an exception. > (I probably should wrote that in original post). So you could replace it with a map condition->type tag and then proceed with Ada.Tags.Generic_Dispatching_Constructor, because the map tag->constructor is for free, here you do not need pointers any more, in Ada 2005. The compiler will force to override the "constructor" for each concrete derived type. ------------- Having said that, there still is a difficult problem with construction of the map. I don't know if it is an issue for you, but it is for the persistency layer I designed. The problem is that if the map is open-ended, you need some mechanism of registration of each new type in the map. This is still unresolved in Ada. The pattern I am using is that each package declaring a new type is required to call some class-wide procedure registering the type upon package elaboration. In your case it is the condition associated with the type tag. That cannot be enforced, and it works only at the library level, i.e. for "immortal" types. A possible solution in the future language revisions could be to introduce type constructors/destructors: user-defined procedures called upon derivation and leaving the scope of a type. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de