From: puk @ umn._edu_ (Paul Pukite)
Subject: Reading from a saved stream
Date: Wed, 23 Jan 2002 04:10:58 GMT
Date: 2002-01-23T04:10:58+00:00 [thread overview]
Message-ID: <3c4e2839.2139458@news.tc.umn.edu> (raw)
Is the attached pattern legal & portable Ada? I believe
so but a compiler upgrade from Rational Apex 3.0.0b
to Rational Apex 4.0.0b resulted in the following
questionable output for the Stream_Save main procedure:
Received Move Command with Speed = 259
Speed should be = 999
The dispatching works OK but the transferred data looks odd.
I would like to know if this is more likely a regression
bug or if Rational is following the standard leading to
an unexpected outcome. The results are independent of
the OS by the way. Also, the same behavior occurs if the
base class is not labelled abstract.
We have spent a lot of effort creating streamable classes and
to hit this issue has got me second-guessing this particular idiom.
Any comments are appreciated.
thanks,
Paul Pukite
::::::::::::::
base.1.ada
::::::::::::::
package Base is
type Selection is (Zero, One, Two, Three);
type Item is abstract tagged
record
Menu : Integer := 1;
Enum : Selection := Three;
end record;
-- Primitive op
procedure Input (Msg : in Item) is abstract;
end Base;
::::::::::::::
gizmo.1.ada
::::::::::::::
with Base;
package Gizmo is
pragma Elaborate_Body;
type Move is new Base.Item with
record
Speed : Integer := 1;
end record;
procedure Input (Obj : in Move);
end Gizmo;
::::::::::::::
gizmo.2.ada
::::::::::::::
with Text_Io;
package body Gizmo is
procedure Input (Obj : in Move) is
begin
Text_Io.Put_Line ("Received Move Command with Speed =" &
Integer'Image (Obj.Speed));
end Input;
end Gizmo;
::::::::::::::
stream_save.2.ada
::::::::::::::
with Ada.Streams.Stream_Io;
with Text_Io;
with Base;
with Gizmo;
procedure Stream_Save is
Stream_File_Name : constant String := "stream.out";
procedure Save (Cmd : in Base.Item'Class) is
File : Ada.Streams.Stream_Io.File_Type;
S : Ada.Streams.Stream_Io.Stream_Access;
begin
Ada.Streams.Stream_Io.Create (File, Name => Stream_File_Name);
S := Ada.Streams.Stream_Io.Stream (File);
Base.Item'Class'Output (S, Cmd);
Ada.Streams.Stream_Io.Close (File);
end Save;
procedure Play_Back is
File : Ada.Streams.Stream_Io.File_Type;
S : Ada.Streams.Stream_Io.Stream_Access;
begin
Ada.Streams.Stream_Io.Open
(File, Ada.Streams.Stream_Io.In_File, Stream_File_Name);
S := Ada.Streams.Stream_Io.Stream (File);
Base.Input (Base.Item'Class'Input (S));
Ada.Streams.Stream_Io.Close (File);
end Play_Back;
Obj : Gizmo.Move;
Speed : constant Integer := 999;
begin
Obj.Speed := Speed;
Save (Obj); -- Save the command
Play_Back; -- Play back (and dispatch) the command
Text_Io.Put_Line ("Speed should be =" & Integer'Image (Speed));
end Stream_Save;
pragma Main (Posix_Compliant => False); -- needed for Text_IO.Create
next reply other threads:[~2002-01-23 4:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-23 4:10 Paul Pukite [this message]
2002-01-23 17:49 ` Reading from a saved stream Stephen Leake
2002-01-24 6:03 ` Greg Bek
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox