1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . S T R E A M S . S T O R A G E . B O U N D E D --
9 -- Copyright (C) 2020-2024, Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
31 ------------------------------------------------------------------------------
33 package Ada
.Streams
.Storage
.Bounded
with Pure
is
35 type Stream_Type
(Max_Elements
: Stream_Element_Count
) is
36 new Storage_Stream_Type
with private with
37 Default_Initial_Condition
=> Element_Count
(Stream_Type
) = 0;
39 overriding
procedure Read
40 (Stream
: in out Stream_Type
; Item
: out Stream_Element_Array
;
41 Last
: out Stream_Element_Offset
)
44 Num_Read
: constant Stream_Element_Count
:=
45 Stream_Element_Count
'Min
46 (Element_Count
(Stream
)'Old, Item
'Length);
48 Last
= Num_Read
+ Item
'First - 1
50 Element_Count
(Stream
) =
51 Element_Count
(Stream
)'Old - Num_Read
);
53 overriding
procedure Write
54 (Stream
: in out Stream_Type
; Item
: Stream_Element_Array
) with
55 Post
=> Element_Count
(Stream
) =
56 Element_Count
(Stream
)'Old + Item
'Length;
58 overriding
function Element_Count
59 (Stream
: Stream_Type
) return Stream_Element_Count
with
60 Post
=> Element_Count
'Result <= Stream
.Max_Elements
;
62 overriding
procedure Clear
(Stream
: in out Stream_Type
) with
63 Post
=> Element_Count
(Stream
) = 0;
67 type Stream_Type
(Max_Elements
: Stream_Element_Count
) is
68 new Storage_Stream_Type
with record
69 Count
: Stream_Element_Count
:= 0;
70 Elements
: Stream_Element_Array
(1 .. Max_Elements
);
73 end Ada
.Streams
.Storage
.Bounded
;