comp.lang.ada
 help / color / mirror / Atom feed
* Help on arrays of tagged types
@ 1998-01-07  0:00 mrada
  1998-01-09  0:00 ` Matthew Heaney
  1998-01-09  0:00 ` Stephen Leake
  0 siblings, 2 replies; 6+ messages in thread
From: mrada @ 1998-01-07  0:00 UTC (permalink / raw)



Hi all,

I am racking my brains trying to figure out how to have a hetergenous
array of tagged type data.  I have numerous packages all of which have
a Data type inherited from one another.  I would like to declare an
array who components can point to different "Data" type objects.

Any help?

BTW:  The source code would be too volumous to post here.


Chris Sparks




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help on arrays of tagged types
  1998-01-07  0:00 Help on arrays of tagged types mrada
  1998-01-09  0:00 ` Matthew Heaney
@ 1998-01-09  0:00 ` Stephen Leake
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Leake @ 1998-01-09  0:00 UTC (permalink / raw)



mrada wrote:
> 
> Hi all,
> 
> I am racking my brains trying to figure out how to have a hetergenous
> array of tagged type data.  I have numerous packages all of which have
> a Data type inherited from one another.  I would like to declare an
> array who components can point to different "Data" type objects.
	                    ^^^
key word; "point". Use an array of class-wide access type;

type Root_Type is abstract tagged with null record;
type Root_Access_Type is access Root_Type'class;

type Heterogenous_Array_Type is array (foo) of Root_Access_Type;

Yes, this requires allocate/deallocate; that's the price you pay for
flexibility.

If the array elements are constant, they can be staticly declared,
avoiding allocate/deallocate.


> Chris Sparks

-- 
- Stephe




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help on arrays of tagged types
  1998-01-07  0:00 Help on arrays of tagged types mrada
@ 1998-01-09  0:00 ` Matthew Heaney
  1998-01-09  0:00   ` Matthew Heaney
  1998-01-09  0:00 ` Stephen Leake
  1 sibling, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1998-01-09  0:00 UTC (permalink / raw)



In article <34B37A65.607798A2@catalina-inter.net>, mrada
<mrada@CATALINA-INTER.NET> wrote:

>I am racking my brains trying to figure out how to have a hetergenous
>array of tagged type data.  I have numerous packages all of which have
>a Data type inherited from one another.  I would like to declare an
>array who components can point to different "Data" type objects.

You have to use indirection.  

type Root_Data is tagged null record;

type Root_Data_Access_All is access all Root_Data;

type Root_Data_Array is
   array (Positive range <>) of Root_Data_Access_All;

Note that use of heap is _not_ required, if you use a general access type
(as I have indicated in my example).

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help on arrays of tagged types
  1998-01-09  0:00 ` Matthew Heaney
@ 1998-01-09  0:00   ` Matthew Heaney
  1998-01-13  0:00     ` James and Jessica Bear
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1998-01-09  0:00 UTC (permalink / raw)



In article <mheaney-ya023680000901982029460001@news.ni.net>, mheaney@ni.net
(Matthew Heaney) wrote:

>In article <34B37A65.607798A2@catalina-inter.net>, mrada
><mrada@CATALINA-INTER.NET> wrote:
>
>>I am racking my brains trying to figure out how to have a hetergenous
>>array of tagged type data.  I have numerous packages all of which have
>>a Data type inherited from one another.  I would like to declare an
>>array who components can point to different "Data" type objects.
>
>You have to use indirection.  
>
>type Root_Data is tagged null record;
>
>type Root_Data_Access_All is access all Root_Data;
>
>type Root_Data_Array is
>   array (Positive range <>) of Root_Data_Access_All;
>
>Note that use of heap is _not_ required, if you use a general access type
>(as I have indicated in my example).

Oops!  Of course I meant

type Root_Data_Class_Access_All is access all Root_Data'Class;

type Root_Data_Array is
   array (Positive range <>) of Root_Data_Class_Access_All;

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help on arrays of tagged types
  1998-01-09  0:00   ` Matthew Heaney
@ 1998-01-13  0:00     ` James and Jessica Bear
  1998-01-13  0:00       ` Matthew Heaney
  0 siblings, 1 reply; 6+ messages in thread
From: James and Jessica Bear @ 1998-01-13  0:00 UTC (permalink / raw)



[ headers snipped ]
> >>I am racking my brains trying to figure out how to have a hetergenous
> >>array of tagged type data.  I have numerous packages all of which have
> >>a Data type inherited from one another.  I would like to declare an
> >>array who components can point to different "Data" type objects.
> >
	[ snip ]

Hello.  This problem is quite similar to one I have been having also.
I am trying to create a linked list type for objects derived from a
root tagged type.  

The goal is to have a homogenous Linked_List object, that stores objects
of a tagged type derived from "Root_Data".  So you could set up as
follows:

	Socket_List : Linked_List;
	Descriptor_List : Linked_List;
	etc.

The list is set up analogously to the example below, but the problem
arises 
when I try to access the elements of the list. I think the problem is
that 
I try to convert from "access Root_Data'Class" to "access <type derived
from Root_Data>",
which cannot work because it would entail extending the structure of the
object to the
derived type.

> 
> type Root_Data_Class_Access_All is access all Root_Data'Class;
> 
> type Root_Data_Array is
>    array (Positive range <>) of Root_Data_Class_Access_All;
> 

Should I be using generics for this instead?

Thanks for any and all help. :)
James




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help on arrays of tagged types
  1998-01-13  0:00     ` James and Jessica Bear
@ 1998-01-13  0:00       ` Matthew Heaney
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 1998-01-13  0:00 UTC (permalink / raw)



In article <34BC054C.5DB2@peak.org>, jamesjb@peak.org wrote:

>Hello.  This problem is quite similar to one I have been having also.
>I am trying to create a linked list type for objects derived from a
>root tagged type.  
>
>The goal is to have a homogenous Linked_List object, that stores objects
>of a tagged type derived from "Root_Data".  So you could set up as
>follows:
>
>        Socket_List : Linked_List;
>        Descriptor_List : Linked_List;
>        etc.
>
>The list is set up analogously to the example below, but the problem
>arises 
>when I try to access the elements of the list. I think the problem is
>that 
>I try to convert from "access Root_Data'Class" to "access <type derived
>from Root_Data>",
>which cannot work because it would entail extending the structure of the
>object to the
>derived type.
>
>> 
>> type Root_Data_Class_Access_All is access all Root_Data'Class;
>> 
>> type Root_Data_Array is
>>    array (Positive range <>) of Root_Data_Class_Access_All;

You want a "typeless" data structure.  You'll have to downcast in that case:

declare
   Descriptor_As_Data : Root_Data'Class 
      renames Heading (Descriptor_List).all;

   File : File_Descriptor 
      renames File_Descriptor (Descriptor_As_Data);
begin

It's perfectly legal to downcast a class-wide object into the type you
want, because there'll be a tag check to make sure the object really is (or
is descended from) File_Descriptor.

That being said, yes, you really do want to use a generic, if the data
structure is homogeneous.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-01-13  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-07  0:00 Help on arrays of tagged types mrada
1998-01-09  0:00 ` Matthew Heaney
1998-01-09  0:00   ` Matthew Heaney
1998-01-13  0:00     ` James and Jessica Bear
1998-01-13  0:00       ` Matthew Heaney
1998-01-09  0:00 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox