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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8a074a0043177938 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-12 00:46:44 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Type declared in record? Date: Wed, 12 Nov 2003 09:49:08 +0100 Message-ID: References: NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 1068626802 48457762 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:2400 Date: 2003-11-12T09:49:08+01:00 List-Id: On Tue, 11 Nov 2003 22:43:15 GMT, Freejack wrote: >On Tue, 11 Nov 2003 17:08:56 -0500, Marius Amado Alves wrote: > >> On Tue, 2003-11-11 at 20:19, Freejack wrote: >> >> This is not representative of any problem I can think of. Maybe you want >> an array component, maybe a generic type, maybe something else. Please >> rethink your problem and restate it. > >Right now I'm working on Variant Records. For example... > >generic > > type Item is private; > >package storage is > > type Data_Structure is (Tree, Stack, List); > type Store(DatConf : Data_Structure) is private; >private > > type Node_Pointer is access Store; > > subtype BlockSize is Positive range 1..1024; > > type Item_Array is array(BlockSize) of Item; > > type STree is record > Value : Item; > LPointer : Node_Pointer; > RPointer : Node_Pointer; > TPointer : Node_Pointer; -- Could be used for Threading, or NULL. -- > end record; > > type DLinkedList is record > Element : Item; > Next : Node_Pointer; > Prev : Node_Pointer; > end record; > > > type Store (DatConf : Data_Structure) is record > > case DatConf is > when Tree => > TreeConf : STree; > > when Stack => > StackConf : Item_Array; > > when List => > ListConf : DLinkedList; > end case; > > end record; > > >end storage; > > >This is all swell...but working with it would be a bit of a pain, so I'm >toying around with other ideas that might give me better results. Tagged types! ------------ Interface package ------------ generic type Item is private; package Storage is type Store is new abstract Ada.Finalization.Limited_Controlled with private; function Get (Container : Store; ...) return Item is abstract; ... -- All other interface methods private type Store is new abstract Ada.Finalization.Limited_Controlled with null record; end Storage; ------------ An implementation using bounded arrays --------- generic Max_Number_Of_Items : Positive; package Storage.Bounded_Arrays is type Array_Store is new Store with private; function Get (Container : Array_Store; ...) return Item; -- Implements Get for Array_Store ... private type Item_Array is array (Integer range 1..Max_Number_Of_Items) of Item; type Array_Store is new Store with record Size : Natural := 0; Data : Item_Array; end record; end Storage.Bounded_Arrays; ------------ An implementation using double-linked lists --------- .... --- Regards, Dmitry Kazakov www.dmitry-kazakov.de