Re: Access to function returning class-wide type



On Thu, 21 Aug 2008 21:30:28 +0200, Paweł 'Nivertius' Płazieński wrote:

Dmitry A. Kazakov wrote:

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.

I think that the map condition->type tag is in my case same problem as map
condition->constructor pointer. I need the map registration anyway, because
it basically needs to be changed at run-time.

Why then N is a parameter? When each type knows its N you don't need to
pass it back.

Altrough, all the types I
need to register are library-level types, so the registration mechanism is
pretty simple.

Then the pattern is (assuming N is unknown in advance):

package A is
type Abstracted is abstract tagged null record;
procedure Register
( N : out Natural; -- Given upon registration
Constructor : not null access
function return Abstracted'Class
);
end A;

package B is
type Derived is new Abstracted with ...;
end B;

package body B is
My_N : Natural;

function Create return Abstracted'Class is
begin
return Derived'(...); -- Returns derived
end Create;

begin
Register (My_N, Create'Access);
end B;

You don't need to declare Create in A at all. Each type will declare it in
order to call to Register anyway.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.



Relevant Pages

  • Re: PERL MAP HELP
    ... An explanation of the sematics of... ... map LIST ... the default package main. ... simplest syntax Perl offers and put a nice big red flag "no strict" so ...
    (comp.lang.perl.misc)
  • Re: GPS question: Garmin vs Magellan
    ... First off, thank you John, this is exactly the kind of info I was ... and the complete package with Mapsend TOPO ... >unlimited detail map memory is excellent. ... The Quest ...
    (rec.motorcycles.dirt)
  • Re: changing a symbol name
    ... > Because the intern function must be able to map a string and a package ... the package is (the equivalent ... implementation details. ...
    (comp.lang.lisp)
  • Walking map - Dolomites?
    ... based in Arabba. ... The package includes a map 'Carta Topografica', ...
    (sci.geo.satellite-nav)
  • Re: ruminations on #include and paths
    ... >a package known as foo. ... >way to map a text file containing the list of packages to ... >their locations so that the compiler can pull in the right file. ... This setup if used for self-reference (e.g. the foo package references ...
    (comp.lang.c)