comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephe.Leake@nasa.gov>
Subject: Re: Need advice re package organization.
Date: 01 Aug 2003 17:33:30 -0400
Date: 2003-08-01T21:34:53+00:00	[thread overview]
Message-ID: <uu191kqqd.fsf@nasa.gov> (raw)
In-Reply-To: vilhrvdbtidm49@corp.supernews.com

"Randy Brukardt" <randy@rrsoftware.com> writes:

> "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca> wrote in message
> news:7GfWa.5186$mv6.907516@news20.bellglobal.com...
> <snip>
> >
> > We're talking about protected access of classes (C++).
> 
> As I said above, I don't know C++ well enough to know exactly what it is
> that you are proposing. And in any case, Ada is not C++. Please describe
> what you want in Ada terms, with Ada syntax.

Perhaps I can help, since I beleive I do know C++ and Ada well enough
:).

The C++ notions of public, protected, and private member functions do
not map one-to-one into Ada, but they map fairly well according to the
following scheme (data members below):
       
C++         Ada
public      public part of package spec
protected   private part of package spec
private     package body

C++ can make the same distinctions among data members of a record
type. For example:

class Foo
{
public:
   int A;
protected:
   int B;
private:
   int C;
}

A is visible to all children and clients of Foo; B is visible to
children of Foo; C is only visible within Foo.

To achieve the same visibility in Ada, we need to break up the record
type:

package Foo_Package is

   type Protected_Foo is private;

   type Foo is record
      A : Integer;
      Protected_Stuff : Protected_Foo;
   end record;

private
   type Private_Foo;
   type Private_Foo_Access is access Private_Foo;

   type Protected_Foo is record
      B : integer;
      Private_Stuff : Private_Foo_Access;
   end record;
end Foo_Package;

package body Foo_Package is
   type Private_Foo is record
       C : Integer;
   end type;
   
end Foo_Package;

If you are comming from a C++ background, the Ada approach seems
contorted. From an Ada point of view, the C++ approach seems
simplistic :).


I believe I have seen proposals that allow a single Ada record to have
public and private parts, something like:

package Foo_Package is

   type Foo is record
      A : Integer;
   end record with private;

private

   type Foo is record with private
      B : integer;
   end record;

end Foo_Package;

But that only achieves the C++ protected visibility, not the private.

-- 
-- Stephe



  reply	other threads:[~2003-08-01 21:33 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-26 13:08 Need advice re package organization Bobby D. Bryant
2003-07-26 14:25 ` Robert I. Eachus
2003-07-26 15:27   ` Warren W. Gay VE3WWG
2003-07-26 22:00     ` Robert I. Eachus
2003-07-27 22:01       ` chris
2003-07-28  2:53         ` Robert I. Eachus
2003-07-29  4:52           ` Richard Riehle
2003-07-27 22:02       ` Warren W. Gay VE3WWG
2003-07-28  8:38         ` Dmitry A. Kazakov
2003-07-29 17:18           ` Warren W. Gay VE3WWG
2003-07-30  8:42             ` Dmitry A. Kazakov
2003-07-30 21:00               ` Warren W. Gay VE3WWG
2003-07-30 22:46                 ` Randy Brukardt
2003-07-31 16:39                   ` Warren W. Gay VE3WWG
2003-07-31 17:31                     ` Randy Brukardt
2003-07-31 21:00                       ` Warren W. Gay VE3WWG
2003-07-31 22:13                     ` Robert I. Eachus
2003-08-01 12:51                       ` Warren W. Gay VE3WWG
2003-07-31  5:57                 ` Matthew Heaney
2003-07-31 16:57                   ` Warren W. Gay VE3WWG
2003-07-31 22:33                     ` Robert I. Eachus
2003-08-01  2:58                       ` Chad R. Meiners
2003-08-01 13:51                         ` Stephen Leake
2003-08-01 22:15                           ` Robert I. Eachus
2003-08-04 13:45                             ` Stephen Leake
2003-08-01 13:01                       ` Warren W. Gay VE3WWG
2003-07-31  9:04                 ` Dmitry A. Kazakov
2003-07-31 16:59                   ` Warren W. Gay VE3WWG
2003-07-31 20:41                     ` Randy Brukardt
2003-07-31 21:15                       ` Warren W. Gay VE3WWG
2003-08-01 20:04                         ` Randy Brukardt
2003-08-01 21:33                           ` Stephen Leake [this message]
2003-08-04 19:40                             ` Randy Brukardt
2003-08-04 19:52                               ` Stephen Leake
2003-08-05  3:36                   ` Richard Riehle
2003-08-05  4:03                     ` Hyman Rosen
2003-08-05  7:16                     ` Dmitry A. Kazakov
2003-07-26 17:03 ` Nick Roberts
replies disabled

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