comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent <lutgenl@icloud.com>
Subject: Re: Experimenting with the OOP features in Ada
Date: Wed, 4 Jan 2017 04:18:40 -0800 (PST)
Date: 2017-01-04T04:18:40-08:00	[thread overview]
Message-ID: <f83b387d-01f4-48c0-8751-e21c7c27a9be@googlegroups.com> (raw)
In-Reply-To: <o4gcji$4qr$1@gioia.aioe.org>

On Tuesday, 3 January 2017 15:31:16 UTC+1, Dmitry A. Kazakov  wrote:
> On 2017-01-03 14:57, Laurent wrote:
> 
> > The only thing which I am not able to see is if I can transform this into a
> > procedure and how I would do it. The Ptr confuses me because I don't
> > understand where it should point to in a procedure.
> > > > > > > >
> >    function Create (Value : String) return My_Safe_String
> >    is
> >       Ptr : My_String_Ptr := new My_String (Value'Length);
> >    begin
> >       Ptr.Value := Value;
> >       return Ref (Ptr);
> >    end Create;
> > > > > > > 
> In the sample code this procedure is called Copy. Regarding using 
> in-place notation that would be:
> 
>     Value.Set (new My_String'(Object.Entity with Value'Length, Value));
> 
> > Item.Name.Set (Name=>"Something") looks better than
> > > > > > > >
> > Item.Name := My_Strings.Handle.Create (Value => Name);
> > > > > > > 
> Some people like using unary "+" for this. E.g.
> 
>     function "+" (Value : String) return My_Safe_String
>        renames My_Strings.Handle.Create;
> 
> Then you can do:
> 
>     Item.Name := +"Something";
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
> 
> > > 
The solution with the unary "+" sounds familiar. Forgot only that it was
possible.
Looks less complicate than the other solution.

Other thing I don't understand:

For the persistent storage solution I need those handles. So I tried to adapt
the Base_Types package by copying the Safe_Strings example.

with My_Strings;
with My_Strings.Handle;
with Object;

package Base_Types is

   type Object is abstract new Object.Entity with private;
   
   subtype Name_Type is My_Strings.Handle.My_Safe_String;
   subtype Code_SIL_Type is My_Strings.Handle.My_Safe_String;

   procedure Set_Name (Item : in out Object; Name : String) is abstract;
   procedure Set_Code_SIL (Item : in out Object; Code_SIL : String) is abstract;

   function Name_Value (Item : Object) return String is abstract;
   function Code_SIL_Value (Item : Object) return String is abstract;

private

   type Object 
   is abstract new Object.Entity with
      record
         Name     : Name_Type;
         Code_SIL : Code_SIL_Type;
      end record;
   
   type Base_Type_Ptr is access Object'Class;

end Base_Types;

There seems to be no place where I can insert an tagged keyword? Is that
possible or do I have to do it differently?

When I compile this I get a few errors:

and some more of the following but they are just a symptom not the cause:

test.adb:16:23: invalid prefix in selected component "Test_Antibiotic"
test.adb:16:38: prefixed call is only allowed for objects of a tagged type

base_types.ads:7:32: object "Object" cannot be used before end of its
declaration
base_types.ads:22:20: type "Object" cannot be used before end of its declaration
base_types.ads:28:33: tagged type required, found type "Object" defined at line
21

base_types-antibiotics.ads:12:4: subprogram "Name_Value" is not overriding

Thanks

  parent reply	other threads:[~2017-01-04 12:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-02 13:21 Experimenting with the OOP features in Ada Laurent
2017-01-02 14:11 ` Brian Drummond
2017-01-02 14:43   ` Brian Drummond
2017-01-02 16:27     ` Laurent
2017-01-03 13:01       ` Brian Drummond
2017-01-03 13:57         ` Laurent
2017-01-03 14:31           ` Dmitry A. Kazakov
2017-01-03 17:07             ` G.B.
2017-01-03 20:42               ` Dmitry A. Kazakov
2017-01-04 12:18             ` Laurent [this message]
2017-01-04 12:44               ` Dmitry A. Kazakov
2017-01-05 11:41                 ` Laurent
2017-01-05 13:02                   ` Dmitry A. Kazakov
2017-01-05 13:11                   ` AdaMagica
2017-01-04 15:09               ` Shark8
2017-01-05 11:54                 ` Laurent
     [not found]     ` <85ef59f3-bcbe-4630-9b4d-8285623ab456@googlegroups.com>
2017-01-03 12:48       ` Brian Drummond
2017-01-03 13:43         ` Laurent
2017-01-02 15:54   ` Laurent
2017-01-02 16:41 ` Dmitry A. Kazakov
2017-01-02 18:50   ` Laurent
2017-01-02 20:55     ` Dmitry A. Kazakov
2017-01-03 13:39       ` Laurent
2017-01-03 14:40         ` Dmitry A. Kazakov
replies disabled

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