comp.lang.ada
 help / color / mirror / Atom feed
* Usage of Ada.Streams
@ 2000-01-18  0:00 Joerg Ruedenauer
  2000-01-19  0:00 ` David C. Hoos, Sr.
  0 siblings, 1 reply; 5+ messages in thread
From: Joerg Ruedenauer @ 2000-01-18  0:00 UTC (permalink / raw)


Hello there,

I don't quite know how to use Ada.Streams to read Objects using
dispatching.
To be specific, I have a private tagged type, say Data, and want to
read/write Objects derived from that type. Writing works fine like this:
Data_Pointer: PData; -- an access all Data'class
Str: Stream_Access;
...
Data'Class'Write(Str, Data.all);
But I can't find a solution to read the objects equally nice. From the
Ada95 Rationale I gather I should use 'Input and 'Output somehow, but I'm
just missing an example. Could anyone help me?

Joerg
--
"Quoth the raven: Nevermore!" -- E.A.Poe







^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Usage of Ada.Streams
  2000-01-18  0:00 Usage of Ada.Streams Joerg Ruedenauer
@ 2000-01-19  0:00 ` David C. Hoos, Sr.
  2000-01-19  0:00   ` Pascal Obry
  0 siblings, 1 reply; 5+ messages in thread
From: David C. Hoos, Sr. @ 2000-01-19  0:00 UTC (permalink / raw)



Joerg Ruedenauer <ruedenjg@trick.informatik.uni-stuttgart.de> wrote in
message news:862lc7$s8a$1@inf2.informatik.uni-stuttgart.de...
> Hello there,
>
> I don't quite know how to use Ada.Streams to read Objects using
> dispatching.
> To be specific, I have a private tagged type, say Data, and want to
> read/write Objects derived from that type. Writing works fine like this:
> Data_Pointer: PData; -- an access all Data'class
> Str: Stream_Access;
> ...
> Data'Class'Write(Str, Data.all);
> But I can't find a solution to read the objects equally nice. From the
> Ada95 Rationale I gather I should use 'Input and 'Output somehow, but I'm
> just missing an example. Could anyone help me?
>
If you want to have the tags in the stream (so that the specific
types can be distinguished when reading back), you need to use:
Data'Class'Output(Str, Data_Pointer.all);

Then, to read them back, you would say:
Data_Pointer := new Data'Class'(Data'Class'Input (str));

That statement allocates memory for the object, and initializes it
with the value read from the stream.







^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Usage of Ada.Streams
  2000-01-19  0:00   ` Pascal Obry
@ 2000-01-19  0:00     ` David C. Hoos, Sr.
  2000-01-19  0:00       ` Pascal Obry
  0 siblings, 1 reply; 5+ messages in thread
From: David C. Hoos, Sr. @ 2000-01-19  0:00 UTC (permalink / raw)



Pascal Obry <p.obry@wanadoo.fr> wrote in message
news:863vhk$qje$1@wanadoo.fr...
> David C. Hoos, Sr. a �crit dans le message ...
> >If you want to have the tags in the stream (so that the specific
> >types can be distinguished when reading back), you need to use:
> >Data'Class'Output(Str, Data_Pointer.all);
> >
> >Then, to read them back, you would say:
> >Data_Pointer := new Data'Class'(Data'Class'Input (str));
> >
> >That statement allocates memory for the object, and initializes it
> >with the value read from the stream.
> >
>
> That's correct, but note that it is not necessary to use pointer under
> Ada95.

Agreed.  I only used an access type because the original poster was
writing from a dereferenced access object.

Also, local declare blocks, of course, are more restricted in scope than
dynamically-allocated objects.

Which to use depends on other considerations, but I would probably use
a storage pool if dynamically allocating, especially in a long-running
program reading from, say, a network stream.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Usage of Ada.Streams
  2000-01-19  0:00 ` David C. Hoos, Sr.
@ 2000-01-19  0:00   ` Pascal Obry
  2000-01-19  0:00     ` David C. Hoos, Sr.
  0 siblings, 1 reply; 5+ messages in thread
From: Pascal Obry @ 2000-01-19  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]

David C. Hoos, Sr. a �crit dans le message ...
>If you want to have the tags in the stream (so that the specific
>types can be distinguished when reading back), you need to use:
>Data'Class'Output(Str, Data_Pointer.all);
>
>Then, to read them back, you would say:
>Data_Pointer := new Data'Class'(Data'Class'Input (str));
>
>That statement allocates memory for the object, and initializes it
>with the value read from the stream.
>

That's correct, but note that it is not necessary to use pointer under
Ada95.

Data'Class'Output (Str, Object);

(with Object whatever instance in the class heriachy).

New_Object : constant Data'Class := Data'Class'Input (Str);

Pascal.

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://ourworld.compuserve.com/homepages/pascal_obry
--|
--| "The best way to travel is by means of imagination"







^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Usage of Ada.Streams
  2000-01-19  0:00     ` David C. Hoos, Sr.
@ 2000-01-19  0:00       ` Pascal Obry
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2000-01-19  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 945 bytes --]


David C. Hoos, Sr. a �crit dans le message ...
>Agreed.  I only used an access type because the original poster was
>writing from a dereferenced access object.
>

Sure, It was just side note that was more an answer to the original poster.

>Also, local declare blocks, of course, are more restricted in scope than
>dynamically-allocated objects.
>
>Which to use depends on other considerations, but I would probably use
>a storage pool if dynamically allocating, especially in a long-running
>program reading from, say, a network stream.


Certainly something to have in mind.

Pascal.

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://ourworld.compuserve.com/homepages/pascal_obry
--|
--| "The best way to travel is by means of imagination"







^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-01-19  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-18  0:00 Usage of Ada.Streams Joerg Ruedenauer
2000-01-19  0:00 ` David C. Hoos, Sr.
2000-01-19  0:00   ` Pascal Obry
2000-01-19  0:00     ` David C. Hoos, Sr.
2000-01-19  0:00       ` Pascal Obry

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