From: Georg Bauhaus <see.reply.to@maps.futureapps.de>
Subject: Re: Loosing tagged type via linked list
Date: Sat, 09 Feb 2008 04:48:25 +0100
Date: 2008-02-09T04:48:25+01:00 [thread overview]
Message-ID: <47ad2289$0$370$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <aaa2346c-2135-48cb-9cb3-3e19dfb0e9c4@i29g2000prf.googlegroups.com>
jason.height@gmail.com wrote:
Looks like an issue with copying into a record component
in the generic list. Copying would be unlike parameter passing.
While tagged objects are passed by reference, assigning to a
variable of a specific type copies a value of the target
type. Only the relevant components of the target type stay.
Consider this:
with Ada.Tags;
with Ada.Text_IO;
procedure Main is
package Type_Hier is
type A_Type is tagged null record;
procedure DoPrint(The_Item: A_Type);
-- print The_Items's actual tag
type B_Type is new A_Type with null record;
end Type_Hier;
package body Type_Hier is
procedure DoPrint(The_Item: A_Type) is
use Ada;
Whoami: A_Type'Class renames A_Type'Class(The_Item);
begin
Text_IO.put_line("Tag is " &
Tags.Expanded_Name(Whoami'Tag));
end DoPrint;
end Type_Hier;
use Type_Hier;
Object: A_Type;
-- this would be the Item_Type component of Item_Record
begin -- Main
DoPrint(A_Type'(null record));
DoPrint(A_Type(B_Type'(null record))); -- A_Type view
Object := A_Type(B_Type'(null record));
-- not a reference, neither just an A_Type view, but a copy
-- of the A_Type parts
DoPrint(Object);
end Main;
$ ./main
Tag is MAIN.TYPE_HIER.A_TYPE
Tag is MAIN.TYPE_HIER.B_TYPE
Tag is MAIN.TYPE_HIER.A_TYPE
One solution would be to use references to classwide types,
somewhat like Java.
> I am attempting this in Ada95, with my own Linked_List container impl,
> which seems to be destroying the type information. If anyone knows a
> Ada95 list implementation that can store items of different types
> (derived from a base type) then please let me know.
The Booch components will let you do this, using indefinite
generic formal types.
http://sourceforge.net/project/showfiles.php?group_id=135616.
(The WiKi seems out of order at this time; doc is contained in
an accompanying archive.)
The Charles library is the predecessor of Ada 2005's container
library, http://charles.tigris.org/ . There is a subdirectory
ai302 which has an Ada 95 implementation of containers for
indefinite types, too.
HTH,
-- Georg
next prev parent reply other threads:[~2008-02-09 3:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-09 1:05 Loosing tagged type via linked list jason.height
2008-02-09 3:48 ` Georg Bauhaus [this message]
2008-02-09 11:40 ` Simon Wright
2008-02-10 17:11 ` Simon Wright
2008-02-09 9:38 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox