* Text_IO from a stream
@ 2008-03-31 15:27 gautier_niouzes
2008-03-31 15:49 ` Dmitry A. Kazakov
0 siblings, 1 reply; 10+ messages in thread
From: gautier_niouzes @ 2008-03-31 15:27 UTC (permalink / raw)
...is it possible ?
The RM tells about the reverse, getting a stream access from a text
file (Text_IO.Text_Streams).
TIA
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 15:27 Text_IO from a stream gautier_niouzes
@ 2008-03-31 15:49 ` Dmitry A. Kazakov
2008-03-31 16:05 ` gautier_niouzes
0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-03-31 15:49 UTC (permalink / raw)
On Mon, 31 Mar 2008 08:27:21 -0700 (PDT), gautier_niouzes@hotmail.com
wrote:
> ...is it possible ?
> The RM tells about the reverse, getting a stream access from a text
> file (Text_IO.Text_Streams).
You can always wrap a File_Type in your own stream object.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 15:49 ` Dmitry A. Kazakov
@ 2008-03-31 16:05 ` gautier_niouzes
2008-03-31 16:33 ` Dmitry A. Kazakov
0 siblings, 1 reply; 10+ messages in thread
From: gautier_niouzes @ 2008-03-31 16:05 UTC (permalink / raw)
Dmitry A. Kazakov:
> You can always wrap a File_Type in your own stream object.
Do you mean something like:
type Text_Stream_Type is new Ada.Streams.Root_Stream_Type with record
virtual_file : Ada.Text_IO.File_Type;
end record;
?
At the end of the day, what I'd really like is
function File(stream: access Ada.Streams.Root_Stream_Type 'Class)
return Ada.Text_IO.File_Type;
so that I can do read ASCII data from any stream:
f:= File(my_stream);
-- f is as if open in In_File mode
Get_Line(f, a_string, length);
Get(f, an_integer); -- not binary, but 123_456
Get(f, a_float); -- not binary, but -123.456e78
I guess it would be difficult... But maybe I'm wrong ?
Gautier
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 16:05 ` gautier_niouzes
@ 2008-03-31 16:33 ` Dmitry A. Kazakov
2008-03-31 19:17 ` Gautier
0 siblings, 1 reply; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-03-31 16:33 UTC (permalink / raw)
On Mon, 31 Mar 2008 09:05:35 -0700 (PDT), gautier_niouzes@hotmail.com
wrote:
> Dmitry A. Kazakov:
>
>> You can always wrap a File_Type in your own stream object.
>
> Do you mean something like:
>
> type Text_Stream_Type is new Ada.Streams.Root_Stream_Type with record
> virtual_file : Ada.Text_IO.File_Type;
> end record;
Yes
> At the end of the day, what I'd really like is
> function File(stream: access Ada.Streams.Root_Stream_Type 'Class)
> return Ada.Text_IO.File_Type;
> so that I can do read ASCII data from any stream:
> f:= File(my_stream);
> -- f is as if open in In_File mode
> Get_Line(f, a_string, length);
> Get(f, an_integer); -- not binary, but 123_456
> Get(f, a_float); -- not binary, but -123.456e78
>
> I guess it would be difficult... But maybe I'm wrong ?
> Gautier
But a stream has no defined formatting and is unrelated to ASCII. Then the
idea of parsing stream looks problematic. If you have in the stream a
sequence " + -", what Get should do after discovering '-'?
Anyway, it is quite simple to do. You can do
type Formatted_Stream (Source : access Root_Stream_Type'Class) is
tagged limited private;
function Get (Stream : access Formatted_Stream) return Integer;
...
The implementation of Formatted_Stream will use Source for all its I/O. So
you could hang it on any existing stream.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 16:33 ` Dmitry A. Kazakov
@ 2008-03-31 19:17 ` Gautier
2008-03-31 19:47 ` Dmitry A. Kazakov
0 siblings, 1 reply; 10+ messages in thread
From: Gautier @ 2008-03-31 19:17 UTC (permalink / raw)
Dmitry A. Kazakov:
> But a stream has no defined formatting and is unrelated to ASCII.
Still, you can read the stream through Character'Read(s,c).
> Then the idea of parsing stream looks problematic. If you have in the stream a
> sequence " + -", what Get should do after discovering '-'?
Exactly the same behaviour as when parsing an ill-formatted text.
Reading a text file (or supposedly so) indirectly via a stream and Stream_IO
would have the same result that via Ada.Text_IO.
> Anyway, it is quite simple to do. You can do
>
> type Formatted_Stream (Source : access Root_Stream_Type'Class) is
> tagged limited private;
> function Get (Stream : access Formatted_Stream) return Integer;
> ...
>
> The implementation of Formatted_Stream will use Source for all its I/O. So
> you could hang it on any existing stream.
Fine, seems I need to rewrite a Text_IO for streams. I hoped for a ready-made
solution...
Well, I think I'll switch to a binary format...
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 19:17 ` Gautier
@ 2008-03-31 19:47 ` Dmitry A. Kazakov
2008-03-31 20:54 ` Gautier
2008-04-01 20:49 ` Simon Wright
0 siblings, 2 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-03-31 19:47 UTC (permalink / raw)
On Mon, 31 Mar 2008 21:17:10 +0200, Gautier wrote:
> Dmitry A. Kazakov:
>> But a stream has no defined formatting and is unrelated to ASCII.
>
> Still, you can read the stream through Character'Read(s,c).
Yes, but will that be ASCII-encoded? And it has somehow invent lines and
pages.
>> Then the idea of parsing stream looks problematic. If you have in the stream a
>> sequence " + -", what Get should do after discovering '-'?
>
> Exactly the same behaviour as when parsing an ill-formatted text.
Ah, yes. I cannot find the place in ARM, but it seems that Text_IO would
swallow syntactically incorrect input before propagating Data_Error.
> Reading a text file (or supposedly so) indirectly via a stream and Stream_IO
> would have the same result that via Ada.Text_IO.
>
>> Anyway, it is quite simple to do. You can do
>>
>> type Formatted_Stream (Source : access Root_Stream_Type'Class) is
>> tagged limited private;
>> function Get (Stream : access Formatted_Stream) return Integer;
>> ...
>>
>> The implementation of Formatted_Stream will use Source for all its I/O. So
>> you could hang it on any existing stream.
>
> Fine, seems I need to rewrite a Text_IO for streams. I hoped for a ready-made
> solution...
But Text_IO also defines all Get procedures on String. So if you knew where
line ends are in your stream you could cache the current line in
Formatted_Stream and then simply route all its Gets to Ada.Text_IO Gets.
> Well, I think I'll switch to a binary format...
I would do that too. Also I would override 'Read and 'Write in order to
make it platform-independent. (Stream_Element should be replaced by
octets.)
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 19:47 ` Dmitry A. Kazakov
@ 2008-03-31 20:54 ` Gautier
2008-04-01 7:49 ` Dmitry A. Kazakov
2008-04-01 20:49 ` Simon Wright
1 sibling, 1 reply; 10+ messages in thread
From: Gautier @ 2008-03-31 20:54 UTC (permalink / raw)
Dmitry A. Kazakov:
> Yes, but will that be ASCII-encoded? And it has somehow invent lines and
> pages.
Sure, it is indeed a zip-archived text file that I intend to read through
UnZip.Streams.
Meanwhile (#ada irc...) there seems to be a nice solution:
http://jesselang.com/software/streams_text_io/
...
>> Well, I think I'll switch to a binary format...
>
> I would do that too. Also I would override 'Read and 'Write in order to
> make it platform-independent. (Stream_Element should be replaced by
> octets.)
No problem with that - there is already a framework in that package (for other
files) that sends things byte-per-byte in a deterministic endianess; floats are
split/merged with certain a Float_portable_binary_transfer package.
Thanks for the help!
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 20:54 ` Gautier
@ 2008-04-01 7:49 ` Dmitry A. Kazakov
0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-04-01 7:49 UTC (permalink / raw)
On Mon, 31 Mar 2008 22:54:35 +0200, Gautier wrote:
> Dmitry A. Kazakov:
>
> Meanwhile (#ada irc...) there seems to be a nice solution:
>
> http://jesselang.com/software/streams_text_io/
Yes.
>>> Well, I think I'll switch to a binary format...
>>
>> I would do that too. Also I would override 'Read and 'Write in order to
>> make it platform-independent. (Stream_Element should be replaced by
>> octets.)
>
> No problem with that - there is already a framework in that package (for other
> files) that sends things byte-per-byte in a deterministic endianess; floats are
> split/merged with certain a Float_portable_binary_transfer package.
No, I meant your idea of a text-oriented stream. So Float'Write would put
Float in a human-readable format (instead of Put). But of course, a binary
transfer is always preferable.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-03-31 19:47 ` Dmitry A. Kazakov
2008-03-31 20:54 ` Gautier
@ 2008-04-01 20:49 ` Simon Wright
2008-04-02 7:36 ` Dmitry A. Kazakov
1 sibling, 1 reply; 10+ messages in thread
From: Simon Wright @ 2008-04-01 20:49 UTC (permalink / raw)
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> I would override 'Read and 'Write in order to make it
> platform-independent. (Stream_Element should be replaced by octets.)
How would that particular change help platform independence?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Text_IO from a stream
2008-04-01 20:49 ` Simon Wright
@ 2008-04-02 7:36 ` Dmitry A. Kazakov
0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2008-04-02 7:36 UTC (permalink / raw)
On Tue, 01 Apr 2008 21:49:41 +0100, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> I would override 'Read and 'Write in order to make it
>> platform-independent. (Stream_Element should be replaced by octets.)
>
> How would that particular change help platform independence?
Because then you would control both the representation (T'Write) and the
medium (octet of bits, assuming it atomic as usual).
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-04-02 7:36 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-31 15:27 Text_IO from a stream gautier_niouzes
2008-03-31 15:49 ` Dmitry A. Kazakov
2008-03-31 16:05 ` gautier_niouzes
2008-03-31 16:33 ` Dmitry A. Kazakov
2008-03-31 19:17 ` Gautier
2008-03-31 19:47 ` Dmitry A. Kazakov
2008-03-31 20:54 ` Gautier
2008-04-01 7:49 ` Dmitry A. Kazakov
2008-04-01 20:49 ` Simon Wright
2008-04-02 7:36 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox