Re: How to hide type internals
- From: "Alex R. Mosteo" <devnull@xxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 13:26:11 +0200
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.
.
- References:
- How to hide type internals
- From: Gerd
- How to hide type internals
- Prev by Date: Re: How to hide type internals
- Next by Date: Re: Custom model in gtkada?
- Previous by thread: Re: How to hide type internals
- Index(es):
Relevant Pages
|