1 with Ada
.Streams
; use Ada
.Streams
;
3 package body Opt41_Pkg
is
5 type Wstream
is new Root_Stream_Type
with record
9 procedure Read
(Stream
: in out Wstream
;
10 Item
: out Stream_Element_Array
;
11 Last
: out Stream_Element_Offset
) is null;
13 procedure Write
(Stream
: in out Wstream
; Item
: Stream_Element_Array
) is
15 for J
in Item
'Range loop
16 Append
(Stream
.S
, Character'Val (Item
(J
)));
20 function Rec_Write
(R
: Rec
) return Unbounded_String
is
23 Rec
'Output (S
'Access, R
);
27 type Rstream
is new Root_Stream_Type
with record
32 procedure Write
(Stream
: in out Rstream
; Item
: Stream_Element_Array
) is null;
34 procedure Read
(Stream
: in out Rstream
;
35 Item
: out Stream_Element_Array
;
36 Last
: out Stream_Element_Offset
) is
38 Last
:= Stream_Element_Offset
'Min
39 (Item
'Last, Item
'First + Stream_Element_Offset
(Stream
.S
'Last - Stream
.Idx
));
40 for I
in Item
'First .. Last
loop
41 Item
(I
) := Stream_Element
(Character'Pos (Stream
.S
(Stream
.Idx
)));
42 Stream
.Idx
:= Stream
.Idx
+ 1;
46 function Rec_Read
(Str
: String_Access
) return Rec
is
50 return Rec
'Input (S
'Access);