From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.99.36.130 with SMTP id k124mr34127987pgk.25.1483532320531; Wed, 04 Jan 2017 04:18:40 -0800 (PST) X-Received: by 10.157.37.151 with SMTP id q23mr2686146ota.4.1483532320486; Wed, 04 Jan 2017 04:18:40 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!b123no172073itb.0!news-out.google.com!u18ni3182ita.0!nntp.google.com!b123no172064itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 4 Jan 2017 04:18:40 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=194.154.216.88; posting-account=sDyr7QoAAAA7hiaifqt-gaKY2K7OZ8RQ NNTP-Posting-Host: 194.154.216.88 References: <29380aa7-0c3b-4908-94c6-aa91f3996b42@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Experimenting with the OOP features in Ada From: Laurent Injection-Date: Wed, 04 Jan 2017 12:18:40 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:33038 Date: 2017-01-04T04:18:40-08:00 List-Id: 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