* Type declared in record?
@ 2003-11-11 20:19 Freejack
2003-11-11 22:08 ` Marius Amado Alves
2003-11-12 4:17 ` James Rogers
0 siblings, 2 replies; 5+ messages in thread
From: Freejack @ 2003-11-11 20:19 UTC (permalink / raw)
When using Ada records, is there a way to do something like this...
type Foo is record
type Bar is array(1..Blah) of Positive;
Foo1 : Natural;
Foo2 : Natural;
<ect...>
end record;
I know I can achieve the same(or a similiar) effect using a tagged type.
I was just curious if the above approach is possible, if there was a type
constraint that could be placed on type Bar that would garauntee a
correct elaboration at either compile time or run-time.
Just curious.
Frejack
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Type declared in record?
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 4:17 ` James Rogers
1 sibling, 1 reply; 5+ messages in thread
From: Marius Amado Alves @ 2003-11-11 22:08 UTC (permalink / raw)
To: Freejack; +Cc: comp.lang.ada
On Tue, 2003-11-11 at 20:19, Freejack wrote:
> When using Ada records, is there a way to do something like this...
>
> type Foo is record
> type Bar is array(1..Blah) of Positive;
> Foo1 : Natural;
> Foo2 : Natural;
> <ect...>
> end record;
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Type declared in record?
2003-11-11 22:08 ` Marius Amado Alves
@ 2003-11-11 22:43 ` Freejack
2003-11-12 8:49 ` Dmitry A. Kazakov
0 siblings, 1 reply; 5+ messages in thread
From: Freejack @ 2003-11-11 22:43 UTC (permalink / raw)
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.
Freejack.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Type declared in record?
2003-11-11 22:43 ` Freejack
@ 2003-11-12 8:49 ` Dmitry A. Kazakov
0 siblings, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2003-11-12 8:49 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Type declared in record?
2003-11-11 20:19 Type declared in record? Freejack
2003-11-11 22:08 ` Marius Amado Alves
@ 2003-11-12 4:17 ` James Rogers
1 sibling, 0 replies; 5+ messages in thread
From: James Rogers @ 2003-11-12 4:17 UTC (permalink / raw)
Freejack <user@nospam.net> wrote in
news:pan.2003.11.11.20.25.14.453080.936@nospam.net:
> When using Ada records, is there a way to do something like this...
>
> type Foo is record
> type Bar is array(1..Blah) of Positive;
> Foo1 : Natural;
> Foo2 : Natural;
> <ect...>
> end record;
>
> I know I can achieve the same(or a similiar) effect using a tagged type.
> I was just curious if the above approach is possible, if there was a type
> constraint that could be placed on type Bar that would garauntee a
> correct elaboration at either compile time or run-time.
>
type Bar is array(Positive range <>) of Positive;
type Foo (Blah : Positive) is record
Bar1 : Bar(1..Blah);
Foo1 : Natural;
Foo2 : Natural;
<etc...>
end record;
Jim Rogers
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-11-12 8:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2003-11-12 4:17 ` James Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox