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.129.90.134 with SMTP id o128mr1400520ywb.14.1438329221095; Fri, 31 Jul 2015 00:53:41 -0700 (PDT) X-Received: by 10.140.21.74 with SMTP id 68mr10891qgk.16.1438329221070; Fri, 31 Jul 2015 00:53:41 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!z61no4343619qge.0!news-out.google.com!78ni887qge.1!nntp.google.com!69no2979691qgl.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 31 Jul 2015 00:53:40 -0700 (PDT) In-Reply-To: <4cb32c40-f659-490d-bbb6-73585fc069e8@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.218.188.211; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 83.218.188.211 References: <2df4698f-4c8e-457c-822d-209cb2f8ab5e@googlegroups.com> <014427b1-ff7a-4a69-82e6-0330af77ed96@googlegroups.com> <91f88d79-197c-419f-84a8-908e05967a2c@googlegroups.com> <135c2b00-d13c-4f5d-a586-8aca442d363b@googlegroups.com> <87380683vc.fsf@adaheads.sparre-andersen.dk> <347c6be9-c918-4bc0-9494-c93cd6740def@googlegroups.com> <4cb32c40-f659-490d-bbb6-73585fc069e8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Running a preprocessor from GPS? From: gautier_niouzes@hotmail.com Injection-Date: Fri, 31 Jul 2015 07:53:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:27254 Date: 2015-07-31T00:53:40-07:00 List-Id: Le jeudi 30 juillet 2015 22:53:28 UTC+2, EGarrulo a =E9crit=A0: > I am not thinking in C++ terms. I am thinking in terms of patterns > that I know for managing resources. So far, I only know the "shared/weak > pointer" idiom. If Ada offers something else, besides manual reclamation= , I am > eager to learn about it. Fantastic, then the example below is for you! Of course it is a trivial example. You can add a field of type Text to a wi= ndow type for instance, and the memory will be automatically freed when the= window itself is finalized. No pointer, no manual reclamation, no garbage = waiting to be collected!... Magic, isn't it ? -- This test program reads an entire text file into a variable -- of type Text which is a vector of unbounded strings. with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO, Ada.Text_IO.Unbounded_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Containers.Vectors; procedure Text_Container is package Text_Pkg is new Ada.Containers.Vectors(Positive, Unbounded_String= ); =20 --------------------- -- Text container -- --------------------- subtype Text is Text_Pkg.Vector; -- name: constant String:=3D "text_container.adb"; t: Text; f: File_Type; begin Open(f, In_File, name); while not End_of_File(f) loop t.Append(Get_Line(f)); end loop; Close(f); -- Create(f, Out_File, "copy_of_" & name); for line of t loop Put_Line(f, line); end loop; Close(f); end; _________________________ Gautier's Ada programming http://gautiersblog.blogspot.com/search/label/Ada NB: follow the above link for a valid e-mail address