DocAda(tm) is a productivity tool of KSCE

Prev | Up | ____ | Back | Forward
About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News

13.13.2 Stream-Oriented Attributes

The Write, Read, Output, and Input attributes convert values to a stream of elements and reconstruct values from a stream.

Static Semantics

For every subtype S of a specific type T, the following attributes are defined.

S'Write

   
           procedure S'Write(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item : in T)

S'Read

   
           procedure S'Read(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item : out T)

For elementary types, the representation in terms of stream elements is implementation defined. For composite types, the Write or Read attribute for each component is called in a canonical order. The canonical order of components is last dimension varying fastest for an array, and positional aggregate order for a record. Bounds are not included in the stream if T is an array type. If T is a discriminated type, discriminants are included only if they have defaults. If T is a tagged type, the tag is not included.

For every subtype S'Class of a class-wide type T'Class:

S'Class'Write

    
           procedure S'Class'Write(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item   : in T'Class)

S'Class'Read

    
           procedure S'Class'Read(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item : out T'Class)

Implementation Advice

If a stream element is the same size as a storage element, then the normal in-memory representation should be used by Read and Write for scalar objects. Otherwise, Read and Write should use the smallest number of stream elements needed to represent all values in the base range of the scalar type.

Static Semantics

For every subtype S of a specific type T, the following attributes are defined.

S'Output

    
           procedure S'Output(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item : in T)

S'Input

    
           function S'Input(
              Stream : access Ada.Streams.Root_Stream_Type'Class)
              return T

Unless overridden by an attribute_definition_clause, these subprograms execute as follows:

For every subtype S'Class of a class-wide type T'Class:

S'Class'Output

    
           procedure S'Class'Output(
              Stream : access Ada.Streams.Root_Stream_Type'Class;
              Item   : in T'Class)

S'Class'Input

    
           function S'Class'Input(
              Stream : access Ada.Streams.Root_Stream_Type'Class)
              return T'Class

In the default implementation of Read and Input for a composite type, for each scalar component that is a discriminant or whose component_declaration includes a default_expression, a check is made that the value returned by Read for the component belongs to its subtype. Constraint_Error is raised if this check fails. For other scalar components, no check is made. For each component that is of an access type, if the implementation can detect that the value returned by Read for the component is not a value of its subtype, Constraint_Error is raised. If the value is not a value of its subtype and this error is not detected, the component has an abnormal value, and erroneous execution can result (see 13.9.1).

The stream-oriented attributes may be specified for any type via an attribute_definition_clause. All nonlimited types have default implementations for these operations. An attribute_reference for one of these attributes is illegal if the type is limited, unless the attribute has been specified by an attribute_definition_clause. For an attribute_definition_clause specifying one of these attributes, the subtype of the Item parameter shall be the base subtype if scalar, and the first subtype otherwise. The same rule applies to the result of the Input function.

Examples

Example of user-defined Write attribute:

    
       procedure My_Write(
         Stream : access Ada.Streams.Root_Stream_Type'Class; Item : My_Integer'Base);
       for My_Integer'Write use My_Write;

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
Prev | Up | ____ | Back | Forward


Copyright © 1994-1997 by Kempe Software Capital Enterprises. All Rights Reserved. For comments on this DocAda(tm) hypertext document, please write to KSCE, at docada@ksce.com