Chapter 3 The Application Description Language

3.14 Stream Operators

To simplify the use of streams, the ADL provides two stream operators: put (<<) and get (>>).[8]

The operators act differently depending on their arguments. In all cases, the intent is that the << operator sends data into a stream and the >> operator receives data from the other end of the stream. In the next few paragraphs, we describe how the operators work for each set of argument types. Any other argument combinations are type errors. In all cases, the result of the expression is the left operand. When the first argument is an lvalue whose type is list, as in Figure 3.29, these operators make the list act as a stream.
list_lvalue << any_value;
list_lvalue >> simple_variable;

The << operator appends any_value onto the list specified by list_lvalue. The >> operator reverses this operation, removing the first value from the list_lvalue and storing it in the simple_variable on its right. Using the >> operator on an empty list is an error. It is also an error if the value to be stored by the >> operator does not match the type of simple_variable. Figure 3.30 shows the object on the left as a stream into which we put (<<) or from which we take (>>) simple types. The send operator (<<) sends the object a message with one argument, the value on the right hand side.
object << any_value;
object >> simple_variable;

The selector of this message is based on the type of the value. The selector is "Send" concatenated with the name of the type of the value. For instance, the following expression causes the message {"SendBoolean", TRUE} to be sent to myStream:

myStream << TRUE

The receive operator (>>) sends the object a message with no arguments whose selector is based on the type of the simple_variable. The selector is "Receive" concatenated with the name of the type of the variable. This message returns a value of the requested type. The operator then assigns this value to the simple_variable. For instance, in the following:

integer i;

myStream >> i;

myStream is sent the message ReceiveInteger and the value returned is assigned to i. When both operands are objects, as in Figure 3.31, the operators help the object on their right send and receive itself from the object on the left (presumably a stream).
object << object;
object >> object;

To accomplish this, the object on the right is sent a message with a handle to the object on the left. The selector of this message is either SendTo (<<) or ReceiveFrom (>>).


[8] These operators differ from their C++ counterparts in that the meaning of the "send" and "receive" operators are essentially defined by the ADL. Class authors who define methods to handle the messages sent by the operators may modify their effects on objects.
AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker