From: claude.simon@equipement.gouv.fr
Subject: Re: How to hide type internals
Date: 30 Jun 2006 04:19:11 -0700
Date: 2006-06-30T04:19:11-07:00 [thread overview]
Message-ID: <1151666351.044613.327270@x69g2000cwx.googlegroups.com> (raw)
In-Reply-To: <1151664636.528401.15590@d56g2000cwd.googlegroups.com>
Gerd a écrit :
> 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).
> Like this:
>
> package keys is
> type key;
> function GetKey return key;
> procedure FetchElement (k : key);
> -- implementation of key not visible here
> end keys;
>
> package body keys
> ...
> type Data is record
> ...
> end record;
> type key is access Data;
> ...
> end keys;
package Keys is
type Key is private;
function Getkey return Key;
-- ...
private
type Imp_Key; -- deferred type to the body
type Key is access Imp_Key;
end Keys;
package body Keys is
type Imp_Key is new Integer; -- whatever type
function Getkey return Key
is
The_Key : Key := new Imp_Key;
begin
return The_Key;
end GetKey;
end Keys;
next prev parent reply other threads:[~2006-06-30 11:19 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 [this message]
2006-07-04 11:13 ` Gerd
2006-06-30 11:26 ` Alex R. Mosteo
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