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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f4a284296951c45f,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!postnews.google.com!i29g2000prf.googlegroups.com!not-for-mail From: "jason.height@gmail.com" Newsgroups: comp.lang.ada Subject: Loosing tagged type via linked list Date: Fri, 8 Feb 2008 17:05:58 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 219.90.209.157 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1202519158 19122 127.0.0.1 (9 Feb 2008 01:05:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 9 Feb 2008 01:05:58 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i29g2000prf.googlegroups.com; posting-host=219.90.209.157; posting-account=mYLNogoAAABi0lamnh4VPzcku2F8v5xa User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19747 Date: 2008-02-08T17:05:58-08:00 List-Id: Hi All, I have an interesting problem where i need to store a bunch of procedure calls (for graphics displays) and the associated parameters for later calling (much like a macro call). 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. Ideally i would like the following method to always print B_Type: -------------------------------------------------------------------------------------------- with Text_Io; with Ada.Tags; use Ada.Tags; with Linked_List; procedure Test is type A_Type is tagged record null; end record; type B_Type is new A_Type with record Int : Integer; end record; A : A_Type; B : B_Type := (Int => 1); package MyList is new Linked_List(A_Type); The_List : MyList.List_Type; Itr : MyList.List_Iterator; procedure DoPrint(Input : A_Type'Class) is begin Text_Io.Put_Line("Tag is "&Expanded_Name(Input'Tag)); end; procedure DoPrintTypeCast(Input : A_Type) is begin DoPrint(Input); end; begin --These all print TEST.B_Type DoPrint(B); DoPrint(A_Type(B)); DoPrintTypeCast(A_Type(B)); --This prints TEST.A_Type! --BAD List Impl? MyList.Add(The_List, A_Type(B)); Itr := MyList.First(The_List); DoPrint(MyList.Value(Itr)); end; ------------------------------------------------------------------------------------ Here is the list spec. I was hoping that someone could spot my trouble right off. I must admit i am more at home with Java and C#, where the containers are built into the platform, so this one has had me stumped for a few days. ------------------------------------------------------------------------------------------------------------------------------ with Ada.Finalization; use Ada.Finalization; generic type Item_Type is tagged private; package Linked_List is type List_Type is new Limited_Controlled with private; type List_Iterator is private; function First (List : List_Type) return List_Iterator; function Value (Iterator : List_Iterator) return Item_Type'Class; procedure Add (List : in out List_Type; Item : in Item_Type); private type Item_Record; type Item_Access is access Item_Record; type Item_Record is record Item : Item_Type; Next : Item_Access := null; Pred : Item_Access := null; end record; type List_Header is record First : Item_Access := null; Last : Item_Access := null; Count : Natural := 0; end record; type List_Access is access List_Header; type List_Type is new Limited_Controlled with record List : List_Access := new List_Header; end record; procedure Finalize (Object : in out List_Type); type List_Iterator is record List : List_Access := null; Current : Item_Access := null; end record; end Linked_List; ----------------------------------------------------------------------------------------------------------------------------------------------------------- Thanks in advance Jason