From: Olivier Scalbert <olivier.scalbert@algosyn.com>
Subject: Question on Controlled types
Date: Sat, 30 May 2009 13:41:41 +0200
Date: 2009-05-30T13:41:41+02:00 [thread overview]
Message-ID: <4a211b98$0$2862$ba620e4c@news.skynet.be> (raw)
Hello,
I am learning controlled types features and I do not understand the
following thing.
With this code:
-------------------------------------
Spec
-------------------------------------
with audio; use audio;
with Ada.Finalization; use Ada.Finalization;
package audio.effect is
type Delay_Line is limited private;
function Make_Delay_Line (Duration: Duration_Type) return Delay_Line;
private
type Delay_Line is new Controlled with record
Duration: Duration_Type;
end record;
overriding procedure Initialize(Object: in out Delay_Line);
overriding procedure Adjust(Object: in out Delay_Line);
overriding procedure Finalize(Object: in out Delay_Line);
end audio.effect;
-------------------------------------
Body
-------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
package body audio.effect is
function Make_Delay_Line(Duration: Duration_Type) return Delay_Line is
D: Delay_Line;
begin
Put_Line("Make_Delay_Line");
return D;
end Make_Delay_Line;
procedure Initialize(Object: in out Delay_Line) is
begin
Put_Line("Initialize Delay_Line");
end;
procedure Adjust(Object: in out Delay_Line) is
begin
Put_Line("Adjust Delay_Line");
end;
procedure Finalize(Object: in out Delay_Line) is
begin
Put_Line("Finalize Delay_Line");
end;
end audio.effect;
-------------------------------------
Test
-------------------------------------
with audio.effect; use audio.effect;
procedure test1 is
Delay1 : Delay_Line := Make_Delay_Line(Duration => 0.1);
begin
null;
end test1;
-------------------------------------
Program output
-------------------------------------
Initialize Delay_Line
Make_Delay_Line
Adjust Delay_Line
Finalize Delay_Line
Finalize Delay_Line
I have two "Finalize(s)" for one "Initialize".
Should I call Initialize from Adjust ?
How to have only one Initialize/Finalize ?
Thanks to help me,
Olivier.
next reply other threads:[~2009-05-30 11:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-30 11:41 Olivier Scalbert [this message]
2009-05-30 13:27 ` Question on Controlled types Dmitry A. Kazakov
2009-05-30 14:16 ` Olivier Scalbert
2009-05-30 14:48 ` Olivier Scalbert
2009-05-30 15:20 ` Robert A Duff
2009-05-30 15:40 ` Olivier Scalbert
2009-05-30 18:37 ` Robert A Duff
2009-06-04 12:32 ` Hibou57 (Yannick Duchêne)
2009-06-04 14:04 ` Dmitry A. Kazakov
2009-06-04 14:34 ` Hibou57 (Yannick Duchêne)
2009-06-04 15:03 ` Dmitry A. Kazakov
2009-06-04 15:13 ` Hibou57 (Yannick Duchêne)
2009-06-06 1:31 ` Randy Brukardt
2009-05-30 13:30 ` christoph.grein
-- strict thread matches above, loose matches on Subject: below --
2003-10-02 8:05 Question on controlled types christoph.grein
2003-10-01 20:03 Beard, Frank Randolph CIV
2003-10-02 18:45 ` Robert I. Eachus
2003-10-01 19:06 Alex Xela
2003-10-01 23:07 ` Matthew Heaney
2003-10-02 7:09 ` Alex Xela
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox