comp.lang.ada
 help / color / mirror / Atom feed
* layered packages
@ 1991-02-15 16:18 David A. Hasan
  1991-02-16 13:32 ` madmats
  1991-02-18  0:16 ` Jim Showalter
  0 siblings, 2 replies; 3+ messages in thread
From: David A. Hasan @ 1991-02-15 16:18 UTC (permalink / raw)


I am having some trouble building generic components in layers.
My motivation is to contruct layers as *independent* generic packages 
by WITHing low layers into higher layers and then adding additional 
features and "reexporting" some of the old features.  I would certainly
appreciate any insight you expreienced Ada folks can give me.

My question is best asked in the context of an example.  Suppose 
I have the following package which exports a primitive
ADT and some fundamental operations on the ADT:

   GENERIC
      TYPE item IS PRIVATE;
      TYPE coord IS (<>);
   PACKAGE grid IS
      TYPE adt IS PRIVATE;
      FUNCTION fetch( from_adt   : IN adt;
                      at_y, at_x : IN coord ) RETURN item;
      PROCEDURE store( the_item   : IN item;
                       in_adt     : IN OUT adt;
                       at_y, at_x : IN coord );
   PRIVATE
      TYPE adt IS ...whatever...;
   END grid;

"grid.adt" could be used for a number of things, but suppose I want 
to build a numerical matrix layer on top.  Here's my attempt:

   WITH grid;
   GENERIC
      TYPE scalar IS PRIVATE;
      -- WITH "+", "-" etc...
      TYPE index  IS (<>);
   PACKAGE matrix IS
      TYPE adt IS PRIVATE;
      FUNCTION fetch( from_adt       : IN adt;
                      at_row, at_col : IN index  ) RETURN scalar;
      PROCEDURE store( in_adt         : IN OUT adt;
                       at_row, at_col : IN index  );
      FUNCTION invert( the_matrix : IN adt ) RETURN adt;
      -- etc...
   PRIVATE
      PACKAGE low_level IS NEW grid(scalar,index);
      TYPE adt IS NEW low_level.adt;
      -- the derived type comes complete with  of low_level
      --    subprograms "fetch" and "store"
   END matrix;

How can one implement "matrix.fetch" and "matrix.store" so that
they are the *same* as the derived subprograms fetch and store visible at the 
end of the PRIVATE part of the package (i.e., how do I reexport them)?
For that matter, how can they be implemented to *call* the derived subprograms?

Should I perhaps use a SUBTYPE instead of a derived type?

----------------------------------------------------------------
: david a hasan -- Univ. of Texas Ctr. for Space Research
:               -- hasan@emx.cc.utexas.edu

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

end of thread, other threads:[~1991-02-18  0:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-02-15 16:18 layered packages David A. Hasan
1991-02-16 13:32 ` madmats
1991-02-18  0:16 ` Jim Showalter

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