gcspy.comm
Class CommandStream

java.lang.Object
  extended by gcspy.comm.CommandStream
Direct Known Subclasses:
Interpreter, ShapeStream

public class CommandStream
extends java.lang.Object

Parses a buffered I/O stream and invokes the commands in it

Author:
Tony Printezis

Field Summary
protected  Command[] cmds
          An array of GCspy commands
static int FIRST_AVAILABLE_CMD
          The index of the first command
protected  int max
          The index of the largest numbered command
protected  BufferedOutput output
          The output buffer
 
Constructor Summary
CommandStream()
          Create an emty command stream
CommandStream(Command[] cmds)
          Create a new array of commands
CommandStream(int len)
          Create a new array of commands
 
Method Summary
 void execute(BufferedInput input)
          Read a command and execute it
 void finish()
          Finish the command stream
 void finish(BufferedOutput output)
          Finish the command stream for a BufferedOutput
 byte getCmd(BufferedInput input)
          Get a command from a BufferedInput
 void putCmd(BufferedOutput output, byte cmd)
          Put a command into a BufferedOutput
 void putCmd(byte cmd)
          Put a command into the output buffer
 void setBufferedOutput(BufferedOutput output)
          Set the Buffered Output.
 void start()
          Start the command stream
protected  void start(BufferedOutput output)
          Start a command using a BufferedOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cmds

protected Command[] cmds
An array of GCspy commands


max

protected int max
The index of the largest numbered command


output

protected BufferedOutput output
The output buffer


FIRST_AVAILABLE_CMD

public static final int FIRST_AVAILABLE_CMD
The index of the first command

See Also:
Constant Field Values
Constructor Detail

CommandStream

public CommandStream(Command[] cmds)
Create a new array of commands

Parameters:
cmds - The new commands

CommandStream

public CommandStream(int len)
Create a new array of commands

Parameters:
len - The number of commands

CommandStream

public CommandStream()
Create an emty command stream

Method Detail

execute

public void execute(BufferedInput input)
Read a command and execute it

Parameters:
input - The BufferedInput from which to read the command

setBufferedOutput

public void setBufferedOutput(BufferedOutput output)
Set the Buffered Output. used when we are creating a command stream looks a bit nicer rather than always passing the output


start

public void start()
Start the command stream


start

protected void start(BufferedOutput output)
Start a command using a BufferedOutput

Parameters:
output - The BufferedOutput

finish

public void finish()
Finish the command stream


finish

public void finish(BufferedOutput output)
Finish the command stream for a BufferedOutput

Parameters:
output - The BufferedOutput

putCmd

public void putCmd(byte cmd)
Put a command into the output buffer

Parameters:
cmd - The command

putCmd

public void putCmd(BufferedOutput output,
                   byte cmd)
Put a command into a BufferedOutput

Parameters:
output - The BufferedOutput
cmd - The command

getCmd

public byte getCmd(BufferedInput input)
Get a command from a BufferedInput

Parameters:
input - The VufferedInput
Returns:
The command