comp.lang.ada
 help / color / mirror / Atom feed
From: dgibson@snoopy.cis.ohio-state.edu (david scott gibson)
Subject: Q. about generic child unit instantiation
Date: 1996/06/25
Date: 1996-06-25T00:00:00+00:00	[thread overview]
Message-ID: <4qq38lINN641@snoopy.cis.ohio-state.edu> (raw)


Hi.  I have a question about generic child units.  I would like to
have a generic parent package with two generic child units.  In one of
the generic child units, I would like to create an instance of its
sibling unit.  However, in order to instantiate the sibling, I need to
instantiate the parent unit which doesn't seem to be legal (inside
one of its child units).  Does anyone know of a way I can instantiate
a generic child unit of a generic parent inside of its sibling?

Here's an example:

                         P[P_Item]
                         /       \
                        /         \       PC2[P_Item]
                 P.C1[C_Item]   P.C2[] 

I would like to instantiate P.C1 inside of P.C2 achieving the effect
of PC2 (which is not in the child unit hierarchy).  In this scheme, C1
and C2 provide (non-dispatching) implementations of the abstraction in
P.  The purpose of C2 is to provide C1's implementation of P but with
parameter C_Item fixed.  The only problem with PC2 (assuming it works)
is that it doesn't follow the parent:child :: abstraction:implemenation 
pattern I'd like to use.

--
Dave
dgibson@cis.ohio-state.edu

--------------------------------------------------
-- PACKAGE P

generic

   type P_Item is private;

package P is

   type T is abstract tagged null record;

   procedure Op1(x:T; y:P_Item) is abstract;

end P;

--------------------------------------------------
-- PACKAGE P.C1[C_Item]

generic

   type C_Item is private;

package P.C1 is

   type T is new P.T with private;

   procedure Op1(x:T; y:P_Item);

private

   type T is new P.T with
      record
         rep: Integer;  
      end record;

end P.C1;

--------------------------------------------------
-- PACKAGE P.C2[]

with P.C1;

generic

package P.C2 is

   type T is new P.T with private;

   procedure Op1(x:T; y:P_Item);

private
                                  -- I cannot instantiate P here.
   package P_C1_Integer is new    -- This doesn't work, but shows
      P.C1(C_Item => Integer);    -- to what I would like to do

   type T is new P.T with 
      record
         rep: P_C1_Integer.T;
      end record;

end P.C2;

--------------------------------------------------
-- PACKAGE P_C2[P_Item]

with P.C1;

generic

   type P_Item is private;  

package P_C2 is

   package PI is new P(P_Item => P_Item);

   package PI_C1_Integer is new PI.C1(C_Item => Integer);   

   type T is new PI_C1_Integer.T with null record;

end P_C2;









             reply	other threads:[~1996-06-25  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-25  0:00 david scott gibson [this message]
     [not found] ` <DtM900.1D0@world.std.com>
     [not found]   ` <4qsdjvINNsv0@bahama.cis.ohio-state.edu>
1996-06-27  0:00     ` Q. about generic child unit instantiation Robert A Duff
replies disabled

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