comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: "access constant" discriminant
Date: 20 Feb 2003 16:42:33 -0800
Date: 2003-02-21T00:42:33+00:00	[thread overview]
Message-ID: <1ec946d1.0302201642.66eb93e5@posting.google.com> (raw)
In-Reply-To: uu1eyluui.fsf@nasa.gov

Stephen Leake <Stephen.A.Leake@nasa.gov> wrote in message news:<uu1eyluui.fsf@nasa.gov>...
>
> Because the body needs to call other functions that take access types
> (that may beg the question, but it's the best I can do :).

Access parameters carry accessibility information around, to check
that an object in an outer scope doesn't refer to another object in an
inner scope.

These accessibility checks can be turned off using the
'Unchecked_Access attribute, or by using a pragma to suppress
Access_Check.

One example of the use of access parameters is the "multiple views"
idiom in Ada95, to effect the equivalent of multiple inheritance in
other languages.  For example, given a mechanism to store objects that
are "persistent":

   procedure Write 
     (Persistence : access Persistence_Type'Class);

then we can save any object that supports this view, like this:

   Some_Object : aliased T;
   ...
   Write (Persistence_View (Some_Object'Access));

The selector function would be written as:

  function Persistence_View 
   (Object : access T) return Persistence_Class_Access;

In the canonical model, type T would have an aliased component whose
type derives from Root_Persistence_Type, and the selector function is
implemented simply as:

   fuction Persistence_View 
     (Object : access T) return Persistence_Class_Access is
   begin
      return Object.Persistence_View'Access;
   end;

Here we see the reason why we passed an access parameter: it's because
we're returning an access value that designates one of our own
components.

The view component would be implemented like this:

   type Persistence_Type is
      new Root_Persistence_Type (Object : access T) with null record;

   type T is
      limited record
         Persistence_View : aliased Persistence_Type (T'Access);
         ...
      end record;

Presumably the Root_Persistence_Type has primitive operations for
writing an object into a stream, e.g.

   procedure Write 
     (Persistence : access Root_Persistence_Type;
      Stream      : in out Root_Stream_Type'Class) is abstract;

The Persisence_Type about would override the Write operation, to write
a T object into the stream.  It has visibility to the T object via its
access discriminant.

Access discriminants are very powerful.  No serious Ada95 program can
be written without them.



  reply	other threads:[~2003-02-21  0:42 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-10  8:26 "access constant" discriminant tmoran
2003-02-10 14:43 ` Frank J. Lhota
2003-02-10 18:57   ` tmoran
2003-02-15 19:17     ` Richard Riehle
2003-02-15 19:59       ` Larry Kilgallen
2003-02-15 23:53         ` Richard Riehle
2003-02-16  1:50           ` Eric G. Miller
2003-02-20  2:23         ` Matthew Heaney
2003-02-20 17:34         ` Stephen Leake
2003-02-21  0:42           ` Matthew Heaney [this message]
2003-02-21 10:41             ` Lutz Donnerhacke
2003-02-21 20:21               ` Randy Brukardt
2003-02-23 12:22                 ` Simon Wright
2003-02-24  7:06                 ` Dale Stanbrough
2003-02-24 18:58                 ` Matthew Heaney
2003-02-24 21:05                   ` Randy Brukardt
2003-02-25 14:15                     ` Frank J. Lhota
2003-02-26  1:05                       ` Randy Brukardt
2003-02-24 16:03               ` Matthew Heaney
2003-02-21 15:03             ` Hyman Rosen
2003-02-21 20:09               ` Randy Brukardt
2003-02-21 21:33               ` Matthew Heaney
2003-02-21 20:07             ` Randy Brukardt
2003-02-24 19:11               ` Matthew Heaney
2003-02-24 21:17                 ` Randy Brukardt
2003-02-25 17:49                   ` Richard Riehle
2003-02-20  2:23       ` Matthew Heaney
2003-02-20  2:20     ` Matthew Heaney
2003-02-10 19:26 ` Robert A Duff
2003-02-10 22:27 ` Rod Chapman
2003-02-11  2:00   ` Jeffrey Carter
2003-02-20  2:28   ` Matthew Heaney
2003-02-20  9:45     ` Lutz Donnerhacke
2003-02-20  2:17 ` Matthew Heaney
replies disabled

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