comp.lang.ada
 help / color / mirror / Atom feed
* Help a dope
@ 1998-05-09  0:00 Chip Richards
  0 siblings, 0 replies; only message in thread
From: Chip Richards @ 1998-05-09  0:00 UTC (permalink / raw)



Okay, I should know better, but I have a mental block here.  Someone, please
give me a nudge!

I'm translating some C++ code to Ada (95).  I'm trying to avoid totally
redesigning it during the translation, but appropriate changes are fine.  The
original code has a single .h file, which is included in multiple .cxx files
which implement most of the method code.  In attempting to follow that
structure (which seemed sound enough, and simple enough), I came up with the
code pasted below (choppable with gnatchop).

This is a GUI package; there's a main "Object" type, from which types like
"Button" are derived.  There's an "Interface" driver, which calls the drawing
routines of the various widgets.  I envision user programs having to "with"
the main (parent) package and whichever child widget packages they use.

My questions are:

1. Isn't there a better way to lay this out in Ada?  I'd prefer to avoid one
giant package file, but splitting it up seems to cause new problems.

2. In the specific code I've done below, I'm told I can't call abstract
subprogram "D" in package P.I's version of "D".  What I really want is to
dispatch to one of several versions of "D", defined in other child packages
such as P.B.  That is, when P.I.D is called with a Bt, I want it to call
P.B.D.  I guess I sorta understand why this isn't working, but what *should* I
do here?

This really isn't a terribly difficult problem, and I am continuing to work on
it, but I'd appreciate suggestions from anyone farther along the Ada OO curve
than I.

-- 
Chip

==============================================================================


-- p.ads
package P is

type Ot is tagged null record;
type It is new Ot with null record;

type OPtr is access all Ot'Class;

procedure D (OP:  access Ot'Class) is abstract;

end P;


-- p-i.ads
package P.I is

procedure D (OP:  access It'Class);

end P.I;


-- p-i.adb
with P.B;   use P.B;

package body P.I is

procedure D (OP:  access It'Class) is
begin
   D (OPtr (OP));
end D;

end P.I;


-- p-b.ads
package P.B is

type Bt is new Ot with null record;

procedure D (BP:  access Bt'Class);

end P.B;


-- p-b.adb
package body P.B is

procedure D (BP:  access Bt'Class) is
begin
   null;
end D;

end P.B;

==============================================================================




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-05-09  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-09  0:00 Help a dope Chip Richards

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