From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Type declared in record?
Date: Wed, 12 Nov 2003 09:49:08 +0100
Date: 2003-11-12T09:49:08+01:00 [thread overview]
Message-ID: <jvr3rvom1c24fan5cnn9a11sls4eslesbb@4ax.com> (raw)
In-Reply-To: pan.2003.11.11.22.49.29.921243.936@nospam.net
On Tue, 11 Nov 2003 22:43:15 GMT, Freejack <user@nospam.net> 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
next prev parent reply other threads:[~2003-11-12 8:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-11 20:19 Type declared in record? Freejack
2003-11-11 22:08 ` Marius Amado Alves
2003-11-11 22:43 ` Freejack
2003-11-12 8:49 ` Dmitry A. Kazakov [this message]
2003-11-12 4:17 ` James Rogers
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox