added FleetProcess
[fleet.git] / src / edu / berkeley / fleet / api / Fleet.java
1 package edu.berkeley.fleet.api;
2 import edu.berkeley.fleet.doc.*;
3 import java.io.*;
4 import java.util.*;
5
6 public abstract class Fleet implements Iterable<Ship> {
7
8     /** read a machine-formatted instruction from a file (into a Java object) */
9     public abstract Instruction readInstruction(DataInputStream is) throws IOException;
10
11     /** write a machine-formatted instruction to a file (from a Java object) */
12     public abstract void        writeInstruction(DataOutputStream os, Instruction instr) throws IOException;
13
14     /** ships must be returned in the same order every time -- ordering may be significant */
15     public abstract Iterator<Ship> iterator();
16
17     /**
18      *  Compute the value that should go in the MACHINE-addressed
19      *  "offset" field of a literal given BYTE-addressed origin and
20      *  target
21      */ 
22     public abstract int computeOffset(int origin, int target);
23
24     /**
25      *  Compute the value that should go in the "offset" field of a
26      *  literal given BYTE-addressed origin and MACHINE-addressed
27      *  target
28      */ 
29     public abstract int computeTarget(int origin, int offset);
30
31     /** if possible, run the given code and create a FleetProcess */
32     public FleetProcess run(byte[] code) {
33         throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
34     }
35
36     /** extract the portion of ShipDescription which is specific to this fleet and generate any source code necessary */
37     public void expand(ShipDescription sd) {
38         throw new RuntimeException("class " + this.getClass().getName() + " does not implement method expand()");
39     }
40
41     /**
42      *  This interface marks Fleets which can create ships on the fly, like the fleeterpreter;
43      *  if available, the parser will use this interface to create ships out of #ship definitions.
44      */
45     public static interface WithDynamicShips {
46         public Ship createShip(String shiptype, String shipname);
47     }
48
49 }