Jump to content

Ada Programming/Libraries/Ada.Storage_IO

From Wikibooks, open books for an open world

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

This language feature is available from Ada 95 on.

Ada.Storage_IO is a unit of the Predefined Language Environment since Ada 95.

Description

[edit | edit source]

Ada.Storage_IO is not a general-purpose Input/Output package. According to A.9: The Generic Package Storage_IO [Annotated](1), it is designed for the construction of user-defined input-output packages, but may also be used to transfer elements from one task to another. Note: None of the language defined IO packages is task-safe.

It allows you to store one element inside a memory buffer. The element needs to be of a definite subtype.

Be careful: The exception Data_Error need not be called when the value read cannot be interpreted as a value of the subtype Element_Type (you have to follow several references given in the RM to A.13: Exceptions in Input-Output [Annotated]), which may lead to erroneous execution; this may especially occur if a value has never been written. Use the 'Valid attribute when not sure.

Specification

[edit | edit source]
 --                     Standard Ada library specification
 --  For copyright, see 
 --  http://ada-auth.org/standards/rm12_w_tc1/html/RM-TTL.html
 -- -------------------------------------------------------------------------

with Ada.IO_Exceptions;
with System.Storage_Elements;

generic
   type Element_Type is private;
package Ada.Storage_IO is
   pragma Preelaborate (Storage_IO);

   Buffer_Size : constant System.Storage_Elements.Storage_Count
     := implementation_defined;

   subtype Buffer_Type is
     System.Storage_Elements.Storage_Array (1 .. Buffer_Size);

   --  Input and output operations

   procedure Read  (Buffer : in  Buffer_Type; Item : out Element_Type);
   procedure Write (Buffer : out Buffer_Type; Item : in  Element_Type);

   --  Exceptions

   Data_Error   : exception renames IO_Exceptions.Data_Error;

end Ada.Storage_IO;

See also

[edit | edit source]

Wikibook

[edit | edit source]

External examples

[edit source]

Ada Reference Manual

[edit | edit source]

Ada 95

[edit | edit source]

Ada 2005

[edit | edit source]

Ada 2012

[edit | edit source]

Open-Source Implementations

[edit | edit source]

FSF GNAT

drake