Debian Codegraph @

gcc/ada/libgnat/a-ststun.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . S T R E A M S . S T O R A G E . U N B O U N D E D --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2020-2025, Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
21 -- --
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. --
25 -- --
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/>. --
30 -- --
31 ------------------------------------------------------------------------------
32
33 private with Ada.Finalization;
34
35 package Ada.Streams.Storage.Unbounded with Preelaborate is
36
37 type Stream_Type is new Storage_Stream_Type with private with
38 Default_Initial_Condition => Element_Count (Stream_Type) = 0;
39
40 overriding procedure Read
41 (Stream : in out Stream_Type; Item : out Stream_Element_Array;
42 Last : out Stream_Element_Offset)
43 with Post =>
44 (declare
45 Num_Read : constant Stream_Element_Count :=
46 Stream_Element_Count'Min
47 (Element_Count (Stream)'Old, Item'Length);
48 begin
49 Last = Num_Read + Item'First - 1
50 and
51 Element_Count (Stream) =
52 Element_Count (Stream)'Old - Num_Read);
53
54 overriding procedure Write
55 (Stream : in out Stream_Type; Item : Stream_Element_Array) with
56 Post => Element_Count (Stream) =
57 Element_Count (Stream)'Old + Item'Length;
58
59 overriding function Element_Count
60 (Stream : Stream_Type) return Stream_Element_Count;
61
62 overriding procedure Clear (Stream : in out Stream_Type) with
63 Post => Element_Count (Stream) = 0;
64
65 private
66
67 subtype Stream_Element_Index is Stream_Element_Count
68 range 1 .. Stream_Element_Count'Last;
69
70 type Elements_Type (Last : Stream_Element_Count) is limited record
71 EA : Stream_Element_Array (1 .. Last);
72 end record;
73
74 Empty_Elements : aliased Elements_Type (0);
75
76 type Elements_Access is access all Elements_Type;
77
78 type Controlled_Elements_Access is
79 new Finalization.Limited_Controlled with record
80 A : Elements_Access;
81 end record;
82
83 overriding procedure Finalize (X : in out Controlled_Elements_Access);
84
85 type Stream_Type is new Storage_Stream_Type with record
86 Elements : Controlled_Elements_Access :=
87 (Finalization.Limited_Controlled with A => Empty_Elements'Access);
88 Count : Stream_Element_Count := 0;
89 end record;
90
91 end Ada.Streams.Storage.Unbounded;