From: LeakyStain <leakstan@erols.com>
Subject: Re: Exposing agreggate members of a class
Date: 1998/12/31
Date: 1998-12-31T12:52:39+00:00 [thread overview]
Message-ID: <368B738E.23BC574@erols.com> (raw)
In-Reply-To: 76cd39$21c8$1@news.gate.net
David Botton wrote:
>
> Given:
>
> with GCanvas_Package; use GCanvas_Package;
>
> type GWindow_Object is tagged with private;
> type GWindow_Pointer is access all GWindow_Object;
>
> private:
>
> type GWindow_Object is tagged
> record
> Canvas : GCanvas_Object;
> end record;
>
> What is the cleanest way to give access to the Canvas by reference in a way
> that will not require Unchecked Programming
Depends on how much "acess" the clients need. If they can destroy
Canvas, then it should not be private.
Windex (http://www.erols.com/leakstan/stephe/index.html) solves a
similar problem; shared access to a Win32 Device Context. The approach I
take is to declare the basic Device Context operations to take a
class-wide object parameter:
package Windex.Graphics_Devices is
type Handle_Type is new Root_Handle_Type with private;
procedure BitBlt
(Dest_Image : in Handle_Type'class;
<other params>);
... other operations
end package Windex.Graphics_Devices;
Root_Handle_Type is derived from Ada.Finalization.Limited_Controlled.
Then, in a child package, declare a type that takes a Windex.Windows
object as a discriminant:
package Windex.Graphics_Devices.Windows is
type Handle_Type (Owner : access Windex.Windows.Handle_Type'class) is
new
Windex.Graphics_Devices.Handle_Type with null record;
-- Handle_Type can be used with all Windex.Graphics_Devices
operations.
procedure Initialize (Handle : in out Handle_Type);
-- Get the device context for Window. This locks the window for
drawing;
-- after drawing, Handle must be finalized to allow normal Window
-- painting.
procedure Finalize (Handle : in out Handle_Type);
-- Release window device context.
end Windex.Graphics_Devices.Windows;
This allows any Windex.Windows object to gain temporary exclusive access
to the Device_Context. All Paint operations in a window procedure use a
Windex.Graphics_Devices.Windows object to gain lock the Device_Context
for drawing.
Hope this helps.
-- Stephe
next prev parent reply other threads:[~1998-12-31 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-12-30 0:00 Exposing agreggate members of a class David Botton
1998-12-30 0:00 ` Tom Moran
1998-12-31 0:00 ` LeakyStain [this message]
1998-12-31 0:00 ` David Botton
1999-01-03 0:00 ` Simon Wright
1999-01-06 0:00 ` 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