1 #ifndef _READER_H_
2 #define _READER_H_
4 #include <iostream>
5 #include <vector>
7 #include <oberon.h>
8 #include <store.h>
9 #include <alien.h>
15 INTEGER baseId;
18 };
20 /**
21 * TYPE Reader
22 * Reader for Component Pascal values like integers, reals, or sets. A reader contains a Files.Reader, to which it forwards most operations.
23 * Readers are used in the Store.Internalize procedure.
24 * Readers are not extensible.
25 */
31 /*
32 * rider-: Files.Reader
33 * The file rider which links a Reader to a file.
34 */
37 /*
38 * cancelled-: BOOLEAN valid during a Store.Internalize call
39 * Tells whether the currently executing Internalize has been cancelled by ReadVersion or TurnIntoAlien.
40 */
43 /**
44 * readAlien-: BOOLEAN
45 * Tells whether any alien has been read since the last ConnectTo.
46 */
49 /**
50 * Cause of current read being alien.
51 */
62 /**
63 * Position of the next store in the current level
64 */
66 /**
67 * Position just after the last read store
68 */
70 };
74 /**
75 * Construct a reader from the istream rider.
76 * @param rider An istream (binary mode).
77 */
80 /**
81 * PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File)
82 * NEW
83 * Connect the reader to a file. All the following operations require connected readers, i.e., rd.rider # NIL. This precondition is not checked explicitly, however. After connecting, the reader's position is at the beginning of the file. If the same reader should be reused on another file, it must first be closed, by connecting it to NIL.
84 * ConnectTo is used internally.
85 *
86 * Pre
87 * 20 (f = NIL) OR (rd.rider = NIL)
88 *
89 * Post
90 * f = NIL
91 * rd.rider = NIL
92 * f # NIL
93 * (rd.rider # NIL) & (rd.rider.Base() = f)
94 * rd.Pos() = 0
95 */
96 // FIXME
98 /**
99 * PROCEDURE (VAR rd: Reader) Pos (): INTEGER
100 * NEW
101 * Returns the reader's current position.
102 *
103 * Post
104 * 0 <= result <= rd.rider.Base().Length()
105 */
106 // FIXME
108 /**
109 * PROCEDURE (VAR rd: Reader) SetPos (pos: INTEGER)
110 * NEW
111 * Sets the reader's current position to pos.
112 *
113 * Pre
114 * 20 pos >= 0
115 * 21 pos <= rd.rider.Base().Length()
116 *
117 * Post
118 * rd.Pos() = pos
119 * ~rd.rider.eof
120 */
121 // FIXME
123 /**
124 * PROCEDURE (VAR rd: Reader) ReadBool (OUT x: BOOLEAN)
125 * NEW
126 * Reads a Boolean value.
127 */
128 /**
129 * PROCEDURE (VAR rd: Reader) ReadSChar (OUT x: SHORTCHAR)
130 * NEW
131 * Reads a short character (00X..0FFX).
132 */
135 /* PROCEDURE (VAR rd: Reader) ReadXChar (OUT x: CHAR)
136 * NEW
137 * Same as ReadSChar, but has a CHAR-type parameter.
138 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
139 */
140 /**
141 * PROCEDURE (VAR rd: Reader) ReadChar (OUT x: CHAR)
142 * NEW
143 * Reads a character (0000X..0FFFFX).
144 */
147 /**
148 * PROCEDURE (VAR rd: Reader) ReadByte (OUT x: BYTE)
149 * NEW
150 * Reads a very short integer (-128..127).
151 */
153 /**
154 * PROCEDURE (VAR rd: Reader) ReadSInt (OUT x: SHORTINT)
155 * NEW
156 * Reads a short integer (-32768..32767).
157 */
159 /**
160 * PROCEDURE (VAR rd: Reader) ReadXInt (OUT x: INTEGER)
161 * NEW
162 * Same as ReadSInt, but has an INTEGER-type parameter.
163 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
164 */
166 /**
167 * PROCEDURE (VAR rd: Reader) ReadInt (OUT x: INTEGER)
168 * NEW
169 * Reads an integer (-2147483648..2147483647).
170 */
172 /*
173 * PROCEDURE (VAR rd: Reader) ReadLong (OUT x: LONGINT)
174 * NEW
175 * Reads a long integer (-9223372036854775808..9223372036854775807).
176 *
177 * PROCEDURE (VAR rd: Reader) ReadSReal (OUT x: SHORTREAL)
178 * NEW
179 * Reads a short real (32-bit IEEE number).
180 *
181 * PROCEDURE (VAR rd: Reader) ReadXReal (OUT x: REAL)
182 * NEW
183 * Same as ReadSReal, but has a REAL-type parameter.
184 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
185 *
186 * PROCEDURE (VAR rd: Reader) ReadReal (OUT x: REAL)
187 * NEW
188 * Reads a real (64-bit IEEE number).
189 *
190 * PROCEDURE (VAR rd: Reader) ReadSet (OUT x: SET)
191 * NEW
192 * Reads a set (32 elements).
193 */
194 /**
195 * PROCEDURE (VAR rd: Reader) ReadSString (OUT x: ARRAY OF SHORTCHAR)
196 * NEW
197 * Reads a 0X-terminated short string.
198 *
199 * Pre
200 * invalid index LEN(x) > Length(string)
201 */
203 /**
204 * PROCEDURE (VAR rd: Reader) ReadXString (OUT x: ARRAY OF CHAR)
205 * NEW
206 * Same as ReadSString, but has a string-type parameter.
207 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
208 */
209 //void readXString(CHAR *out);
210 /**
211 * PROCEDURE (VAR rd: Reader) ReadString (OUT x: ARRAY OF CHAR)
212 * NEW
213 * Reads a 0X-terminated string.
214 *
215 * Pre
216 * invalid index LEN(x) > Length(string)
217 *
218 * PROCEDURE (VAR rd: Reader) ReadStore (OUT x: Store)
219 * NEW
220 * Reads a store's type, allocates it, and then reads its contents, by calling the store's Internalize procedure. x may also be NIL, or an alien if the store's module cannot be loaded, or if internalization has been cancelled by the Internalize procedure.
221 * If the store has already been read in, a pointer to the same store is returned instead of allocating a new one. This means that arbitrary graphs that have been written with WriteStore are reconstructed correctly, including alias pointers to the same store, cycles, etc.
222 * If the file on which the reader operates does not contain correct input, then an assertion trap will be caused (traps 101 to trap 106).
223 *
224 * Pre
225 * 20 the reader is at the start position of a new store
226 *
227 * Post
228 * empty store on file
229 * x = NIL
230 * non-empty store on file
231 * x # NIL
232 * x IS Alien
233 * x.cause # 0
234 * x.type # ""
235 * x.file # NIL
236 * x.pos >= 0 beginning of store's data
237 * x.len >= 0 length of store's data
238 * alien store contents are on x.file in the range [x.pos .. x.pos + x.len[.
239 * These data include only the store's contents, not its prefix
240 * ~(x IS Alien)
241 * x was read successfully
242 */
244 /**
245 * PROCEDURE (VAR rd: Reader) ReadVersion (min, max: INTEGER; OUT version: INTEGER)
246 * NEW
247 * Read a version byte and return it in version. If version is not in the specified range [min .. max], the store currently being read is turned into an alien, with cause = alienVersion.
248 *
249 * Pre
250 * 20 0 <= min <= max
251 *
252 * Post
253 * min <= version <= max
254 * legal version
255 * (version < min) OR (version > max)
256 * illegal version
257 * rd.cause = alienVersion
258 * rd.cancelled
259 * rd.readAlien
260 */
262 /*
263 * PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: INTEGER)
264 * NEW
265 * A store which is currently being internalized can turn itself into an alien, e.g., if it has read a component store which is an alien.
266 *
267 * Pre
268 * 20 cause > 0
269 */
283 /**
284 * Add another component to the current path. If first==true, start a new path.
285 */
287 };