comp.lang.ada
 help / color / mirror / Atom feed
From: George J <ivanov_george@list.ru>
Subject: Ada 2005,Doubly_Linked_List with Controlled parameter
Date: Mon, 4 Apr 2016 19:03:23 -0700 (PDT)
Date: 2016-04-04T19:03:23-07:00	[thread overview]
Message-ID: <be918901-786f-421b-9553-fded90925732@googlegroups.com> (raw)

Hi all! I'm using Doubly_Linked_List with Controlled param, example here:

   ----------------------------------------------------------------------
   type Info_Record is new Controlled with
      record
         Name:String_Access;
      end record;
   type Info is access all Info_Record'Class;
   overriding procedure Finalize(Self:in out Info_Record);

   package Test_Containers is new Ada.Containers.Doubly_Linked_Lists(Info_Record);
   use Test_Containers;

   Test_List:Test_Containers.List;
   ----------------------------------------------------------------------
   procedure Free_String is new Ada.Unchecked_Deallocation
(Object => String,
 Name   => String_Access);

   overriding procedure Finalize(Self:in out Info_Record) is
   begin
      if  Self.Name/=null then
            Free_String(Self.Name);
      end if;
   end Finalize;

   ----------------------------------------------------------------------
   procedure Test is
   begin
   Test_List.Append(Info_Record'(Controlled with
                                   Name => new String'("Test_Name"));
   end Test;
   ----------------------------------------------------------------------

  Problem is that after calling "Append"->at once starts Finalization proc, so appended pure line. I just use an access parameter after this "Doubly_Linked_List(Info)", and it's ok now,but i think that i'm wrong,cause Finalization doesn't start with Test_List.Clear and when exiting program. So question is "How I can finalize Doubly_Connected_List Controlled parameter correctly?Or I must not use Controlled parameter in this list?".
Thanks!

             reply	other threads:[~2016-04-05  2:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05  2:03 George J [this message]
2016-04-05  2:27 ` Ada 2005,Doubly_Linked_List with Controlled parameter Jeffrey R. Carter
2016-04-05  3:00   ` George J
2016-04-05  4:13     ` George J
2016-04-05  6:20     ` Jeffrey R. Carter
2016-04-05  6:31       ` George J
2016-04-05  7:58     ` Dmitry A. Kazakov
2016-04-05  8:09       ` George J
2016-04-05  8:35       ` George J
2016-04-05  8:50         ` Dmitry A. Kazakov
2016-04-05  8:57           ` George J
2016-04-05 16:22         ` Jeffrey R. Carter
2016-04-06  1:14           ` George J
2016-04-05  3:25   ` George J
2016-04-05  5:24     ` Jeffrey R. Carter
2016-04-05  6:30       ` George J
2016-04-06 20:29         ` Randy Brukardt
2016-04-06 21:04           ` Jeffrey R. Carter
2016-04-07  1:28           ` George J
replies disabled

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