mmp.engine
Class Output

java.lang.Object
  extended by mmp.engine.Output

public class Output
extends java.lang.Object

Output manages the diversions. The writer given to the constructor is the standard output of the engine, registered as diversion '0'.
The built-in macro 'divert' can generate new diversions or redirect output to already existing diversions.

Author:
Burkhardt Renz

Constructor Summary
Output(java.io.Writer writer)
          Initializes the output to the given writer.
 
Method Summary
 void close()
          Closes the output and flushes all diversions to the writer with divnum '0'.
 void divert(int divnum)
          Sets the current writer to the string writer with diversion number 'divnum'.
 void exit()
          Closes the output without flushing the diversions.
 int getCurrentDivnum()
          Get the number of current diversion.
 void undivert()
          Undiverts all diversions in numerical order into the current diversion.
 void undivert(int divnum)
          Writes the content of diversion 'divnum' to the current writer and discards the diversion.
 void write(int c)
          Write single char to current writer.
 void write(java.lang.String string)
          Write string to current writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Output

public Output(java.io.Writer writer)
Initializes the output to the given writer. This writer is the standard output with divnum '0' of the engine.

Parameters:
writer - where to write output
Pre:
writer != 0
Method Detail

close

public final void close()
                 throws java.io.IOException
Closes the output and flushes all diversions to the writer with divnum '0'.

Throws:
java.io.IOException - if io error

divert

public final void divert(int divnum)
Sets the current writer to the string writer with diversion number 'divnum'.
If there is no string writer with that diversion number, it is created.
If the diversion number is negative, the current writer will be a writer that discards all input.

Parameters:
divnum - number of writer to assign as the current writer.

exit

public final void exit()
                throws java.io.IOException
Closes the output without flushing the diversions.

Throws:
java.io.IOException - if io error

getCurrentDivnum

public final int getCurrentDivnum()
Get the number of current diversion.

Returns:
number of current writer.

undivert

public final void undivert()
                    throws java.io.IOException
Undiverts all diversions in numerical order into the current diversion.

Throws:
java.io.IOException - if io error

undivert

public final void undivert(int divnum)
                    throws java.io.IOException
Writes the content of diversion 'divnum' to the current writer and discards the diversion.

Parameters:
divnum - number of diversion to be output.
Throws:
java.io.IOException - if io error

write

public final void write(int c)
                 throws java.io.IOException
Write single char to current writer.

Parameters:
c - char to be written
Throws:
java.io.IOException - if io error

write

public final void write(java.lang.String string)
                 throws java.io.IOException
Write string to current writer.

Parameters:
string - to be written to the current writer
Throws:
java.io.IOException - if io error