From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: Qs re 'Write & 'Read
Date: Tue, 10 Jun 2003 12:55:37 -0500
Date: 2003-06-10T12:55:37-05:00 [thread overview]
Message-ID: <vec6t08neudvea@corp.supernews.com> (raw)
In-Reply-To: YDeFa.929408$Zo.212966@sccrnsc03
<tmoran@acm.org> wrote in message news:YDeFa.929408$Zo.212966@sccrnsc03...
> Is the default 'Write on a non null access type supposed to write the .all
> and a 'Read supposed to do an allocate and read in the .all value?
> Same questions for generall access types.
No. The actual access value is written to the stream -- not very useful.
However, I have been using stream attribute override procedures like these
for years:
-----------------------------
-- Translation_Access_Read --
-----------------------------
procedure Translation_Access_Read
(The_Stream_Access : access Ada.Streams.Root_Stream_Type'Class;
The_Translation_Access : out Translation_Access)
is
Is_Non_Null : Boolean;
begin
Boolean'Read (The_Stream_Access, Is_Non_Null);
if Is_Non_Null then
The_Translation_Access := new Translation'
(Translation'Input (The_Stream_Access));
else
The_Translation_Access := null;
end if;
end Translation_Access_Read;
------------------------------
-- Translation_Access_Write --
------------------------------
procedure Translation_Access_Write
(The_Stream_Access : access Ada.Streams.Root_Stream_Type'Class;
The_Translation_Access : Translation_Access)
is
begin
if The_Translation_Access /= null then
Boolean'Write (The_Stream_Access, True);
Translation'Output
(The_Stream_Access, The_Translation_Access.all);
else
Boolean'Write (The_Stream_Access, False);
end if;
end Translation_Access_Write;
The idea is that in a similar fashion to the way that for unconstrained
string types
the string itself is preceded by its contstraint, access types are written
to the
stream with a boolean value preceding the data (if any).
It surely seemed to me like the language standard could have defined
something
like this as the default for access types, but alas, it did not.
I'm not sure why i didn't make these procedures as part of a generic package
to
be instantiated with two parameters -- the data type and its access type,
but
this is what I've been using, lo these several years.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
next prev parent reply other threads:[~2003-06-10 17:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-10 6:11 Qs re 'Write & 'Read tmoran
2003-06-10 12:53 ` Rodrigo Garcia
2003-06-10 17:55 ` David C. Hoos [this message]
2003-06-10 19:09 ` tmoran
2003-06-10 21:30 ` David C. Hoos
2003-06-10 23:26 ` tmoran
2003-06-11 1:31 ` David C. Hoos
2003-06-11 19:19 ` Thomas Wolf
2003-06-12 10:12 `
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox