Ada Programming/Input Output
From Wikibooks, the open-content textbooks collection
Contents |
Ada has 5 independent libraries for input/output operations. So the most important lesson to learn is choosing the right one.
[edit] Text I/O
Text I/O is probably the most used Input/Output package. All data inside the file are represented by human readable text. Text I/O provides support for line and page layout but the standard is free form text.
with Ada.Strings; use Ada.Strings; with Ada.Text_IO; use Ada.Text_IO; procedure Main is Str : String (1..5); Last : Natural; begin Ada.Text_IO.Get_Line (Str, Last); Ada.Text_IO.Put_Line (Str (1..Last)); end;
[edit] Direct I/O
Direct I/O is used for random access files which contain only elements of one specific type. With Direct_IO you can position the file pointer to any element of that type (random access), however you can't freely choose the element type, the element type needs to be a definite subtype.
[edit] Sequential I/O
Direct I/O is used for random access files which contain only elements of one specific type. With Sequential_IO it is the other way round: you can choose between definite and indefinite element types but you have to read and write the elements one after the other.
[edit] Storage I/O
Storage I/O allows you to store one element inside a memory buffer. The element needs to be a definite subtype. Storage I/O is useful in Concurrent programming where it can be used to move elements from one task to another.
[edit] Stream I/O
Stream I/O is the most powerful input/output package which Ada provides. Stream I/O allows you to mix objects from different element types in one sequential file. In order to read/write from/to a stream each type provides a 'Read and 'Write attribute as well as an 'Input and 'Output attribute. These attributes are automatically generated for each type you declare.
The 'Read and 'Write attributes treat the elements as raw data. They are suitable for low level input/output as well as interfacing with other programming languages.
The 'Input and 'Output attribute add additional control informations to the file, like for example the 'First and 'Last attributes from an array.
In object orientated programming you can also use the 'Class'Input and 'Class'Output attributes - they will store and recover the actual object type as well.
Stream I/O is also the most flexible input/output package. All I/O attributes can be replaced with user defined functions or procedures using representation clauses and you can provide your own Stream I/O types using flexible object oriented techniques.
[edit] See also
[edit] Wikibook
- Ada Programming
- Ada Programming/Libraries/Ada.Direct_IO
- Ada Programming/Libraries/Ada.Sequential_IO
- Ada Programming/Libraries/Ada.Storage_IO
- Ada Programming/Libraries/Ada.Streams
- Ada Programming/Libraries/Ada.Text_IO
- Ada Programming/Libraries/Ada.Text_IO.Complex_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Decimal_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Enumeration_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Fixed_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Float_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Integer_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Modular_IO (nested package)
- Ada Programming/Libraries/Ada.Text_IO.Editing
- Ada Programming/Libraries/Ada.Float_Text_IO
- Ada Programming/Libraries/Ada.Integer_Text_IO
[edit] Ada 95 Reference Manual
- 13.13 Streams (Annotated)
- A.8.1 The Generic Package Sequential_IO (Annotated)
- A.8.4 The Generic Package Direct_IO (Annotated)
- A.10.1 The Package Text_IO (Annotated)
- A.12.1 The Package Streams.Stream_IO (Annotated)
[edit] Ada 2005 Reference Manual
- 13.13 Streams (Annotated)
- A.8.1 The Generic Package Sequential_IO (Annotated)
- A.8.4 The Generic Package Direct_IO (Annotated)
- A.10.1 The Package Text_IO (Annotated)
- A.12.1 The Package Streams.Stream_IO (Annotated)

