From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b8b2de2a45e33b46 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Usage of Ada.Streams Date: 2000/01/19 Message-ID: #1/1 X-Deja-AN: 574506694 Content-Transfer-Encoding: 7bit References: <862lc7$s8a$1@inf2.informatik.uni-stuttgart.de> Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-ELN-Date: Tue Jan 18 18:17:11 2000 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 948248231 158.252.123.152 (Tue, 18 Jan 2000 18:17:11 PST) Organization: EarthLink Network, Inc. MIME-Version: 1.0 NNTP-Posting-Date: Tue, 18 Jan 2000 18:17:11 PST Newsgroups: comp.lang.ada Date: 2000-01-19T00:00:00+00:00 List-Id: Joerg Ruedenauer 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.