13.13.1 The Package Streams
The abstract type Root_Stream_Type is the root type
of the class of stream types. The types in this class represent different
kinds of streams. A new stream type is defined by extending the root
type (or some other stream type), overriding the Read and Write operations,
and optionally defining additional primitive subprograms, according to
the requirements of the particular kind of stream. The predefined stream-oriented
attributes like T'Read and T'Write make dispatching calls on the Read
and Write procedures of the Root_Stream_Type. (User-defined T'Read and
T'Write attributes can also make such calls, or can call the Read and
Write attributes of other types.)
Root_Stream_Type is abstract tagged limited private
Stream_Element is mod implementation-defined
Stream_Element_Offset is range implementation-defined
<>) of aliased
Stream : in out
Item : out
Last : out
Stream_Element_Offset) is abstract
Stream : in out
Item : in
Stream_Element_Array) is abstract
... -- not specified by the language
The Read operation transfers Item'Length
elements from the specified stream to fill the array Item. Elements
are transferred until Item'Length elements have been transferred, or
until the end of the stream is reached. If any elements are transferred,
index of the last stream
element transferred is returned in Last. Otherwise,
Item'First - 1 is returned in Last.
Last is less than Item'Last
only if the end of the stream is reached.
The Write operation appends Item to the specified
The index subtype of Stream_Element_Array is Stream_Element_Offset
because we wish to allow maximum flexibility. Most Stream_Element_Arrays
will probably have a lower bound of 0 or 1, but other lower bounds, including
negative ones, make sense in some situations.
Note that there are some language-defined subprograms
that fill part of a Stream_Element_Array, and return the index of the
last element filled as a Stream_Element_Offset. The Read procedures declared
here, Streams.Stream_IO (see A.12.1), and
System.RPC (see E.5) behave in this manner.
These will raise Constraint_Error if the resulting Last value is not
in Stream_Element_Offset. This implies that the Stream_Element_Array
passed to these subprograms should not have a lower bound of Stream_Element_Offset'First,
because then a read of 0 elements would always raise Constraint_Error.
A better choice of lower bound is 0 or 1.
If Stream_Element'Size is not a multiple of System.Storage_Unit,
then the components of Stream_Element_Array need not be aliased.
If the Stream_Element'Size is less than the size
of System.Storage_Unit, then components of Stream_Element_Array need
not be aliased. This is necessary as the components of type Stream_Element
size might not be addressable on the target architecture architechture.
If the end of stream has been reached, and Item'First
is Stream_Element_Offset'First, Read will raise Constraint_Error.
Stream_Element_Arrays should start at 0 or 1, not Stream_Element_Offset'First.
Extensions to Ada 95
Preelaborable_Initialization to type Root_Stream_Type.
Wording Changes from Ada 95
Fixed the wording for Read to properly define the
result in Last when no stream elements are transfered.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe