1 ------------------------------------------------------------------------------
3 -- GNAT RUNTIME COMPONENTS --
5 -- S Y S T E M . S T R E A M _ A T T R I B U T E S --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada
.IO_Exceptions
;
35 with Ada
.Streams
; use Ada
.Streams
;
36 with Unchecked_Conversion
;
38 package body System
.Stream_Attributes
is
40 Err
: exception renames Ada
.IO_Exceptions
.End_Error
;
41 -- Exception raised if insufficient data read (note that the RM implies
42 -- that Data_Error might be the appropriate choice, but AI195-00132
43 -- decides with a binding interpretation that End_Error is preferred).
45 SU
: constant := System
.Storage_Unit
;
47 subtype SEA
is Ada
.Streams
.Stream_Element_Array
;
48 subtype SEO
is Ada
.Streams
.Stream_Element_Offset
;
50 generic function UC
renames Unchecked_Conversion
;
52 -- Subtypes used to define Stream_Element_Array values that map
53 -- into the elementary types, using unchecked conversion.
55 Thin_Pointer_Size
: constant := System
.Address
'Size;
56 Fat_Pointer_Size
: constant := System
.Address
'Size * 2;
58 subtype S_AD
is SEA
(1 .. (Fat_Pointer_Size
+ SU
- 1) / SU
);
59 subtype S_AS
is SEA
(1 .. (Thin_Pointer_Size
+ SU
- 1) / SU
);
60 subtype S_B
is SEA
(1 .. (Boolean'Size + SU
- 1) / SU
);
61 subtype S_C
is SEA
(1 .. (Character'Size + SU
- 1) / SU
);
62 subtype S_F
is SEA
(1 .. (Float'Size + SU
- 1) / SU
);
63 subtype S_I
is SEA
(1 .. (Integer'Size + SU
- 1) / SU
);
64 subtype S_LF
is SEA
(1 .. (Long_Float'Size + SU
- 1) / SU
);
65 subtype S_LI
is SEA
(1 .. (Long_Integer'Size + SU
- 1) / SU
);
66 subtype S_LLF
is SEA
(1 .. (Long_Long_Float'Size + SU
- 1) / SU
);
67 subtype S_LLI
is SEA
(1 .. (Long_Long_Integer'Size + SU
- 1) / SU
);
68 subtype S_LLU
is SEA
(1 .. (UST
.Long_Long_Unsigned
'Size + SU
- 1) / SU
);
69 subtype S_LU
is SEA
(1 .. (UST
.Long_Unsigned
'Size + SU
- 1) / SU
);
70 subtype S_SF
is SEA
(1 .. (Short_Float'Size + SU
- 1) / SU
);
71 subtype S_SI
is SEA
(1 .. (Short_Integer'Size + SU
- 1) / SU
);
72 subtype S_SSI
is SEA
(1 .. (Short_Short_Integer'Size + SU
- 1) / SU
);
73 subtype S_SSU
is SEA
(1 .. (UST
.Short_Short_Unsigned
'Size + SU
- 1) / SU
);
74 subtype S_SU
is SEA
(1 .. (UST
.Short_Unsigned
'Size + SU
- 1) / SU
);
75 subtype S_U
is SEA
(1 .. (UST
.Unsigned
'Size + SU
- 1) / SU
);
76 subtype S_WC
is SEA
(1 .. (Wide_Character'Size + SU
- 1) / SU
);
78 -- Unchecked conversions from the elementary type to the stream type
80 function From_AD
is new UC
(Fat_Pointer
, S_AD
);
81 function From_AS
is new UC
(Thin_Pointer
, S_AS
);
82 function From_F
is new UC
(Float, S_F
);
83 function From_I
is new UC
(Integer, S_I
);
84 function From_LF
is new UC
(Long_Float, S_LF
);
85 function From_LI
is new UC
(Long_Integer, S_LI
);
86 function From_LLF
is new UC
(Long_Long_Float, S_LLF
);
87 function From_LLI
is new UC
(Long_Long_Integer, S_LLI
);
88 function From_LLU
is new UC
(UST
.Long_Long_Unsigned
, S_LLU
);
89 function From_LU
is new UC
(UST
.Long_Unsigned
, S_LU
);
90 function From_SF
is new UC
(Short_Float, S_SF
);
91 function From_SI
is new UC
(Short_Integer, S_SI
);
92 function From_SSI
is new UC
(Short_Short_Integer, S_SSI
);
93 function From_SSU
is new UC
(UST
.Short_Short_Unsigned
, S_SSU
);
94 function From_SU
is new UC
(UST
.Short_Unsigned
, S_SU
);
95 function From_U
is new UC
(UST
.Unsigned
, S_U
);
96 function From_WC
is new UC
(Wide_Character, S_WC
);
98 -- Unchecked conversions from the stream type to elementary type
100 function To_AD
is new UC
(S_AD
, Fat_Pointer
);
101 function To_AS
is new UC
(S_AS
, Thin_Pointer
);
102 function To_F
is new UC
(S_F
, Float);
103 function To_I
is new UC
(S_I
, Integer);
104 function To_LF
is new UC
(S_LF
, Long_Float);
105 function To_LI
is new UC
(S_LI
, Long_Integer);
106 function To_LLF
is new UC
(S_LLF
, Long_Long_Float);
107 function To_LLI
is new UC
(S_LLI
, Long_Long_Integer);
108 function To_LLU
is new UC
(S_LLU
, UST
.Long_Long_Unsigned
);
109 function To_LU
is new UC
(S_LU
, UST
.Long_Unsigned
);
110 function To_SF
is new UC
(S_SF
, Short_Float);
111 function To_SI
is new UC
(S_SI
, Short_Integer);
112 function To_SSI
is new UC
(S_SSI
, Short_Short_Integer);
113 function To_SSU
is new UC
(S_SSU
, UST
.Short_Short_Unsigned
);
114 function To_SU
is new UC
(S_SU
, UST
.Short_Unsigned
);
115 function To_U
is new UC
(S_U
, UST
.Unsigned
);
116 function To_WC
is new UC
(S_WC
, Wide_Character);
122 function I_AD
(Stream
: access RST
) return Fat_Pointer
is
127 Ada
.Streams
.Read
(Stream
.all, T
, L
);
140 function I_AS
(Stream
: access RST
) return Thin_Pointer
is
145 Ada
.Streams
.Read
(Stream
.all, T
, L
);
158 function I_B
(Stream
: access RST
) return Boolean is
163 Ada
.Streams
.Read
(Stream
.all, T
, L
);
168 return Boolean'Val (T
(1));
176 function I_C
(Stream
: access RST
) return Character is
181 Ada
.Streams
.Read
(Stream
.all, T
, L
);
186 return Character'Val (T
(1));
194 function I_F
(Stream
: access RST
) return Float is
199 Ada
.Streams
.Read
(Stream
.all, T
, L
);
212 function I_I
(Stream
: access RST
) return Integer is
217 Ada
.Streams
.Read
(Stream
.all, T
, L
);
230 function I_LF
(Stream
: access RST
) return Long_Float is
235 Ada
.Streams
.Read
(Stream
.all, T
, L
);
248 function I_LI
(Stream
: access RST
) return Long_Integer is
253 Ada
.Streams
.Read
(Stream
.all, T
, L
);
266 function I_LLF
(Stream
: access RST
) return Long_Long_Float is
271 Ada
.Streams
.Read
(Stream
.all, T
, L
);
284 function I_LLI
(Stream
: access RST
) return Long_Long_Integer is
289 Ada
.Streams
.Read
(Stream
.all, T
, L
);
302 function I_LLU
(Stream
: access RST
) return UST
.Long_Long_Unsigned
is
307 Ada
.Streams
.Read
(Stream
.all, T
, L
);
320 function I_LU
(Stream
: access RST
) return UST
.Long_Unsigned
is
325 Ada
.Streams
.Read
(Stream
.all, T
, L
);
338 function I_SF
(Stream
: access RST
) return Short_Float is
343 Ada
.Streams
.Read
(Stream
.all, T
, L
);
356 function I_SI
(Stream
: access RST
) return Short_Integer is
361 Ada
.Streams
.Read
(Stream
.all, T
, L
);
374 function I_SSI
(Stream
: access RST
) return Short_Short_Integer is
379 Ada
.Streams
.Read
(Stream
.all, T
, L
);
392 function I_SSU
(Stream
: access RST
) return UST
.Short_Short_Unsigned
is
397 Ada
.Streams
.Read
(Stream
.all, T
, L
);
410 function I_SU
(Stream
: access RST
) return UST
.Short_Unsigned
is
415 Ada
.Streams
.Read
(Stream
.all, T
, L
);
428 function I_U
(Stream
: access RST
) return UST
.Unsigned
is
433 Ada
.Streams
.Read
(Stream
.all, T
, L
);
446 function I_WC
(Stream
: access RST
) return Wide_Character is
451 Ada
.Streams
.Read
(Stream
.all, T
, L
);
464 procedure W_AD
(Stream
: access RST
; Item
: in Fat_Pointer
) is
465 T
: constant S_AD
:= From_AD
(Item
);
468 Ada
.Streams
.Write
(Stream
.all, T
);
475 procedure W_AS
(Stream
: access RST
; Item
: in Thin_Pointer
) is
476 T
: constant S_AS
:= From_AS
(Item
);
479 Ada
.Streams
.Write
(Stream
.all, T
);
486 procedure W_B
(Stream
: access RST
; Item
: in Boolean) is
490 T
(1) := Boolean'Pos (Item
);
491 Ada
.Streams
.Write
(Stream
.all, T
);
498 procedure W_C
(Stream
: access RST
; Item
: in Character) is
502 T
(1) := Character'Pos (Item
);
503 Ada
.Streams
.Write
(Stream
.all, T
);
510 procedure W_F
(Stream
: access RST
; Item
: in Float) is
511 T
: constant S_F
:= From_F
(Item
);
514 Ada
.Streams
.Write
(Stream
.all, T
);
521 procedure W_I
(Stream
: access RST
; Item
: in Integer) is
522 T
: constant S_I
:= From_I
(Item
);
525 Ada
.Streams
.Write
(Stream
.all, T
);
532 procedure W_LF
(Stream
: access RST
; Item
: in Long_Float) is
533 T
: constant S_LF
:= From_LF
(Item
);
536 Ada
.Streams
.Write
(Stream
.all, T
);
543 procedure W_LI
(Stream
: access RST
; Item
: in Long_Integer) is
544 T
: constant S_LI
:= From_LI
(Item
);
547 Ada
.Streams
.Write
(Stream
.all, T
);
554 procedure W_LLF
(Stream
: access RST
; Item
: in Long_Long_Float) is
555 T
: constant S_LLF
:= From_LLF
(Item
);
558 Ada
.Streams
.Write
(Stream
.all, T
);
565 procedure W_LLI
(Stream
: access RST
; Item
: in Long_Long_Integer) is
566 T
: constant S_LLI
:= From_LLI
(Item
);
569 Ada
.Streams
.Write
(Stream
.all, T
);
576 procedure W_LLU
(Stream
: access RST
; Item
: in UST
.Long_Long_Unsigned
) is
577 T
: constant S_LLU
:= From_LLU
(Item
);
580 Ada
.Streams
.Write
(Stream
.all, T
);
587 procedure W_LU
(Stream
: access RST
; Item
: in UST
.Long_Unsigned
) is
588 T
: constant S_LU
:= From_LU
(Item
);
591 Ada
.Streams
.Write
(Stream
.all, T
);
598 procedure W_SF
(Stream
: access RST
; Item
: in Short_Float) is
599 T
: constant S_SF
:= From_SF
(Item
);
602 Ada
.Streams
.Write
(Stream
.all, T
);
609 procedure W_SI
(Stream
: access RST
; Item
: in Short_Integer) is
610 T
: constant S_SI
:= From_SI
(Item
);
613 Ada
.Streams
.Write
(Stream
.all, T
);
620 procedure W_SSI
(Stream
: access RST
; Item
: in Short_Short_Integer) is
621 T
: constant S_SSI
:= From_SSI
(Item
);
624 Ada
.Streams
.Write
(Stream
.all, T
);
631 procedure W_SSU
(Stream
: access RST
; Item
: in UST
.Short_Short_Unsigned
) is
632 T
: constant S_SSU
:= From_SSU
(Item
);
635 Ada
.Streams
.Write
(Stream
.all, T
);
642 procedure W_SU
(Stream
: access RST
; Item
: in UST
.Short_Unsigned
) is
643 T
: constant S_SU
:= From_SU
(Item
);
646 Ada
.Streams
.Write
(Stream
.all, T
);
653 procedure W_U
(Stream
: access RST
; Item
: in UST
.Unsigned
) is
654 T
: constant S_U
:= From_U
(Item
);
657 Ada
.Streams
.Write
(Stream
.all, T
);
664 procedure W_WC
(Stream
: access RST
; Item
: in Wide_Character) is
665 T
: constant S_WC
:= From_WC
(Item
);
668 Ada
.Streams
.Write
(Stream
.all, T
);
671 end System
.Stream_Attributes
;