comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: How to hide type internals
Date: Fri, 30 Jun 2006 13:26:11 +0200
Date: 2006-06-30T13:26:11+02:00	[thread overview]
Message-ID: <4gkfv6F1nnvl6U1@individual.net> (raw)
In-Reply-To: 1151664636.528401.15590@d56g2000cwd.googlegroups.com

Gerd wrote:

> Hi,
> 
> I would like to write a package that exports functions using a special
> type, without showing the details in the spec (even not in the private
> part).
> In Modula-2 one can declare opaque types (which mostly are pointers but
> also can be any type of word size).

I've done this in occasions where I want to have a multi-platform package,
so switching bodies is enough, keeping the same spec file. Like this:

package Blah is

   type External is private;

   -- Operations on external

private

   type Internal; -- forward declaration

   type Internal_Acess is access all Internal;

   type External is record
      Ptr : Internal_Access;
   end record;

end;

And then you define Internal in the body.

With Ada05 you can even get rid of Internal_Access and simply have

type External is record 
   Ptr : access Internal;
end record;

Of course you can have reference counting, deep copying or whatever making
External a Controlled type, so you can have a proper abstraction (This will
be probably a requisite for initialization anyways...)

Hope this helps.



  parent reply	other threads:[~2006-06-30 11:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-30 10:50 How to hide type internals Gerd
2006-06-30 11:19 ` claude.simon
2006-07-04 11:13   ` Gerd
2006-06-30 11:26 ` Alex R. Mosteo [this message]
2006-07-02 15:23 ` Stephen Leake
2006-07-04 11:11   ` Gerd
replies disabled

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