comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Preventing private procedure visibility being made public through extension
Date: Sun, 21 May 2017 15:46:06 -0700 (PDT)
Date: 2017-05-21T15:46:06-07:00	[thread overview]
Message-ID: <05ed8053-be36-4332-8b75-7bca9afd65cc@googlegroups.com> (raw)
In-Reply-To: <ofsvgp$sjc$1@dont-email.me>

On Sunday, May 21, 2017 at 5:09:59 PM UTC-4, Jeffrey R. Carter wrote:
> On 05/21/2017 10:21 PM, Jere wrote:
> >
> > I just don't
> > like using access types if I can avoid them.
> 
> Of course you can avoid them.
> 
> > So something like:
> >
> >    type My_Type is tagged limited private;
> >    function Get_Libaray_Component
> >       (Obj : in out My_Type)
> >       return not null access Library_Type;
> > private
> >    type My_Type is new Other_Library_Type with record
> >       Base : aliased Library_Type;
> >    end record;
> 
> There are a finite number of operations defined for Library_Type, and, as you 
> said, a smaller number that make sense for your abstraction. So you simply 
> define equivalent operations for My_Type that call the appropriate operations 
> for Library_Type with the Base component. No access types, simple, safe, and clear.

I'll use a more concrete example here.  I created a modal dialog box type
for Gnoga.  My spec looks like:

with Gnoga.Gui.Window;
with Gnoga.Gui.View;
package Gnoga.Gui.Modal_Dialog is

   type Dialog_Type is tagged limited private;
   type Dialog_Access is access all Dialog_Type;
   type Pointer_To_Dialog_Class is access all Dialog_Type'Class;

   procedure Create
      (Dialog : in out Dialog_Type;
       Parent : in out Gnoga.Gui.Window.Window_Type'Class;
       ID     : in     String := "");

private

   type Dialog_Type is new Gnoga.Gui.View.View_Type with record
      Main_View : Gnoga.Gui.View.View_Access := null;
   end record;

end Gnoga.Gui.Modal_Dialog;

and the body:

with Gnoga.Gui.Window;
with Gnoga.Gui.Base;
with Gnoga.Gui.Element;

package body Gnoga.Gui.Modal_Dialog is

   procedure Create
      (Dialog : in out Dialog_Type;
       Parent : in out Gnoga.Gui.Window.Window_Type'Class;
       ID     : in     String := "")
   is
      use type Gnoga.Gui.View.View_Access;
      Old_View : Gnoga.Gui.Base.Pointer_To_Base_Class := Parent.Get_View;
   begin

      if Dialog.Main_View = null then

         -- Create the Dialog
         Gnoga.Gui.View.View_Type(Dialog).Create
            (Parent => Parent,
             ID     => ID);

         -- Creating a view using a window as a parent sets the view as the
         -- window's main view.  This line sets it back to the original.
         Parent.Set_View(Old_View.all);


         -- Configure the Modal Background
         Dialog.Fill_Parent;
         Dialog.Background_Color("Grey");

         -- Set the default show/hide state
         Dialog.Show(False);

         -- Create the main view of the dialog
         Dialog.Main_View := new Gnoga.Gui.View.View_Type;
         Dialog.Main_View.Dynamic;
         Dialog.Main_View.Create(Dialog);
         Dialog.Main_View.Background_Color("White");
         Dialog.Main_View.Position(Gnoga.Gui.Element.Fixed);

         -- Center the view as a default
         Dialog.Center;

      end if;

   end Create;

end Gnoga.Gui.Modal_Dialog;

At this point, I need a clean way to let a client
add components (Buttons, forms, etc.) to the dialog box.

Adding all the operations to Dialog_Type won't help me
since all the components use a Create procedure that
takes a Gnoga.Gui.Base.Base_Type'Class parent.  I don't
want to publicly expose the extension of Dialog_Type
since procedures like Create_From_HTML and such
will really mess with the Dialog_Type.  

My initial solution was to add:

   function Get_View
      (Dialog : in out Dialog_Type)
       return Gnoga.Gui.View.View_Access is
   begin
      return Dialog.Main_View;
   end Get_View;

which is why you see Main_View declare as an
access type internally (it was originally just
a Gnoga.Gui.View.View_Type before).

I don't like this method and am open to other
options.  Basically, I need something to
pass to the Create procedure for any components
added.

The other option I was tossing around was to
instead add a

procedure Add_Component
   (Dialog : in out Dialog_Type;
    Object : in out Gnoga.Gui.Base.Basetype'Class);

but the problem there is the components still
need to call Create on some parent, and for the
dialog box to work, I think it needs to be
the view in my tagged type.

Thoughts?


  reply	other threads:[~2017-05-21 22:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-20 17:33 Preventing private procedure visibility being made public through extension Jere
2017-05-20 20:13 ` AdaMagica
2017-05-20 21:55   ` Jere
2017-05-20 20:32 ` Dmitry A. Kazakov
2017-05-20 22:51   ` Jere
2017-05-21  0:51     ` Jere
2017-05-21  9:16       ` Chris Moore
2017-05-21 22:55         ` Jere
2017-05-21  8:44     ` Dmitry A. Kazakov
2017-05-21 12:19       ` J-P. Rosen
2017-05-21 12:53         ` Dmitry A. Kazakov
2017-05-21 20:06       ` Jere
2017-05-21 21:07         ` Dmitry A. Kazakov
2017-05-21 22:28           ` Jere
2017-05-22  8:52             ` Dmitry A. Kazakov
2017-05-22 13:33               ` AdaMagica
2017-05-22 13:43           ` AdaMagica
2017-05-22 21:17         ` Randy Brukardt
2017-05-25  4:06           ` Jere
2017-05-25 19:39             ` Randy Brukardt
2017-05-25 22:53               ` Jere
2017-05-25 22:57                 ` Jere
2017-05-26 20:46                 ` Randy Brukardt
2017-05-26 22:35                   ` Simon Wright
2018-05-20 11:22                     ` Simon Wright
2018-05-20 12:03                       ` Jere
2017-05-26 22:58                   ` Jeffrey R. Carter
2017-05-30 21:15                     ` Randy Brukardt
2017-06-02  1:07                       ` Jere
2017-06-02  7:31                         ` Dmitry A. Kazakov
2017-06-02  8:09                         ` Mark Lorenzen
2017-06-02 11:31                         ` Simon Wright
2017-05-22 21:12   ` Randy Brukardt
2017-05-23  7:38     ` Dmitry A. Kazakov
2017-05-21 18:14 ` Robert Eachus
2017-05-21 20:21   ` Jere
2017-05-21 21:09     ` Jeffrey R. Carter
2017-05-21 22:46       ` Jere [this message]
2017-05-22 21:24         ` Jeffrey R. Carter
2017-05-25  3:45           ` Jere
2017-05-21 21:20     ` Dmitry A. Kazakov
2017-05-21 21:45       ` Jere
replies disabled

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