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,f4a284296951c45f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 09 Feb 2008 04:48:25 +0100 From: Georg Bauhaus Reply-To: rm.tsho+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Loosing tagged type via linked list References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <47ad2289$0$370$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 09 Feb 2008 04:48:25 CET NNTP-Posting-Host: eedf7219.newsspool2.arcor-online.net X-Trace: DXC=aP0;FAXOa9J2:OR3:3gaE@A9EHlD;3YcB4Fo<]lROoRA^YC2XCjHcbI7C 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