Source code: org/pqt/autorib/instr/InstrForRequest.java
1 //AutoRIB
2 // Copyright © 1998 - 2002, P W Quint
3 //
4 // Contact: autorib00@aol.com
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 package org.pqt.autorib.instr;
21 import java.io.*;
22 import java.util.*;
23
24 import org.pqt.autorib.tokenizer.*;
25 import org.pqt.autorib.globals.*;
26 import org.pqt.autorib.util.*;
27 import org.pqt.autorib.rib.*;
28
29 /**
30 * an abstract class from which all For.. classes derive -
31 * subclasses should overide not read, but readParams, as well as
32 * overriding the filter methods defined in InstrBlockRequest*/
33 public abstract class InstrForRequest extends InstrBlockRequest {
34 Vector handles = new Vector(5,5);
35
36 public final void read(InstrWReader in) throws IOException,
37 FormatException {
38 readRequestName(in);
39 readParams(in);
40 in.inForBlock = true;
41 in.saveState();
42 if (in.inLightBlock)
43 in.readToEndBlock(content, InstrGlobals.validLightsBlockIDs);
44 else if (in.inObjectBlock)
45 in.readToEndBlock(content, InstrGlobals.validObjectsBlockIDs);
46 else
47 throw new FormatException("For blocks must appear inside either a Lights" +
48 " or an Objects block", in.tokenizer);
49 in.restoreState();
50 in.inForBlock = false;
51 }
52
53 public void write(Writer out) throws IOException {
54 Enumeration i = content.elements();
55 writeRequest(out);
56 writeParams(out);
57 out.write("\n{\n");
58 while (i.hasMoreElements()) {
59 ((InstrRequest) i.nextElement()).write(out);
60 out.write("\n");
61 }
62 out.write("}");
63 }
64
65 /**
66 * read in any parameters specific to this for call ie. those between the
67 * instruction and the open brace
68 * @param in the InstrWReader to read from
69 */
70 protected abstract void readParams(InstrWReader in) throws FormatException,
71 IOException;
72
73 protected abstract void writeParams(Writer out) throws IOException;
74
75
76 }//class
77
78
79