comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Design Question: How Best To Structure Cross-Referencing Types In Ada 95
Date: 1999/01/21
Date: 1999-01-21T00:00:00+00:00	[thread overview]
Message-ID: <m3r9so4j6g.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36A68FCA.E1EEAFFE@hiwaay.net

"Anthony E. Glover" <aeg@hiwaay.net> writes:

> Is there a neat Ada95 way of getting around this cross-referencing
> problem?

You have to forward declare one of the types, which you'll have to make
tagged:

package Root_Cars is

  type Root_Car is abstract tagged null record;

end Root_Cars;


with Root_Cars;  use Root_Cars;
package Parts is

   type Part is private;

   procedure Activate (The_Part : Part);

private

  type Car_Access is access all Root_Car'Class;

  type Part is
    record
      Parent_Car : Car_Access;
    end record;

end Parts;

with Root_Cars;  use Root_Cars;
with Parts;  use Parts;
package Cars is

  type Car is new Root_Car with private;

  procedure Install (On : Car; The_Part : Part);

private

  type Car is
    record
      Part1 : Part;
      Part2 : Part;
    end record;

end Cars;


Now, in the body of Parts, just down-cast to the normal car type:

with Cars;
package body Parts is

  procedure Activate (The_Part : in Part) is

     The_Car : Car renames Car (The_Part.Car.all);
  begin 
    ...
  end;

end Parts;


You don't have to worry the Tag_Check failing, because only type
Cars.Car derives from Root_Cars.Root_Car.  If this check bothers you,
then just disable it:

  procedure Activate (The_Part : in Part) is

     pragma Suppress (Tag_Check);

     The_Car : Car renames Car (The_Part.Car.all);

  begin 
    ...
  end;





  parent reply	other threads:[~1999-01-21  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-20  0:00 Design Question: How Best To Structure Cross-Referencing Types In Ada 95 Anthony E. Glover
1999-01-21  0:00 ` dewar
1999-01-21  0:00   ` Brian Rogoff
1999-01-26  0:00   ` Dale Stanbrough
1999-01-21  0:00 ` dennison
1999-01-21  0:00 ` Matthew Heaney [this message]
1999-01-30  0:00   ` Nick Roberts
1999-01-31  0:00     ` Matthew Heaney
1999-01-22  0:00 ` Steve Whalen
1999-01-22  0:00   ` dennison
replies disabled

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