cfd4fc53194f1242de4890a369e5765bc086bce5
13 * Reader for Component Pascal values like integers, reals, or sets. A reader contains a Files.Reader, to which it forwards most operations.
14 * Readers are used in the Store.Internalize procedure.
15 * Readers are not extensible.
20 * rider-: Files.Reader
21 * The file rider which links a Reader to a file.
23 std::istream
&d_rider
;
26 * cancelled-: BOOLEAN valid during a Store.Internalize call
27 * Tells whether the currently executing Internalize has been called by ReadVersion or TurnIntoAlien.
33 * Tells whether any alien has been read since the last ConnectTo.
38 INTEGER d_nextStoreId
;
42 * Construct a reader from the istream rider.
43 * @param rider An istream (binary mode).
45 Reader(std::istream
&rider
);
48 * PROCEDURE (VAR rd: Reader) ConnectTo (f: Files.File)
50 * 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.
51 * ConnectTo is used internally.
54 * 20 (f = NIL) OR (rd.rider = NIL)
60 * (rd.rider # NIL) & (rd.rider.Base() = f)
66 * PROCEDURE (VAR rd: Reader) Pos (): INTEGER
68 * Returns the reader's current position.
71 * 0 <= result <= rd.rider.Base().Length()
76 * PROCEDURE (VAR rd: Reader) SetPos (pos: INTEGER)
78 * Sets the reader's current position to pos.
82 * 21 pos <= rd.rider.Base().Length()
91 * PROCEDURE (VAR rd: Reader) ReadBool (OUT x: BOOLEAN)
93 * Reads a Boolean value.
96 * PROCEDURE (VAR rd: Reader) ReadSChar (OUT x: SHORTCHAR)
98 * Reads a short character (00X..0FFX).
100 SHORTCHAR
readSChar();
101 /* PROCEDURE (VAR rd: Reader) ReadXChar (OUT x: CHAR)
103 * Same as ReadSChar, but has a CHAR-type parameter.
104 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
106 * PROCEDURE (VAR rd: Reader) ReadChar (OUT x: CHAR)
108 * Reads a character (0000X..0FFFFX).
110 * PROCEDURE (VAR rd: Reader) ReadByte (OUT x: BYTE)
112 * Reads a very short integer (-128..127).
114 * PROCEDURE (VAR rd: Reader) ReadSInt (OUT x: SHORTINT)
116 * Reads a short integer (-32768..32767).
118 * PROCEDURE (VAR rd: Reader) ReadXInt (OUT x: INTEGER)
120 * Same as ReadSInt, but has an INTEGER-type parameter.
121 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
125 * PROCEDURE (VAR rd: Reader) ReadInt (OUT x: INTEGER)
127 * Reads an integer (-2147483648..2147483647).
131 * PROCEDURE (VAR rd: Reader) ReadLong (OUT x: LONGINT)
133 * Reads a long integer (-9223372036854775808..9223372036854775807).
135 * PROCEDURE (VAR rd: Reader) ReadSReal (OUT x: SHORTREAL)
137 * Reads a short real (32-bit IEEE number).
139 * PROCEDURE (VAR rd: Reader) ReadXReal (OUT x: REAL)
141 * Same as ReadSReal, but has a REAL-type parameter.
142 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
144 * PROCEDURE (VAR rd: Reader) ReadReal (OUT x: REAL)
146 * Reads a real (64-bit IEEE number).
148 * PROCEDURE (VAR rd: Reader) ReadSet (OUT x: SET)
150 * Reads a set (32 elements).
152 * PROCEDURE (VAR rd: Reader) ReadSString (OUT x: ARRAY OF SHORTCHAR)
154 * Reads a 0X-terminated short string.
157 * invalid index LEN(x) > Length(string)
159 * PROCEDURE (VAR rd: Reader) ReadXString (OUT x: ARRAY OF CHAR)
161 * Same as ReadSString, but has a string-type parameter.
162 * This procedure is provided to simplify migration from Release 1.2 to 1.3.
164 * PROCEDURE (VAR rd: Reader) ReadString (OUT x: ARRAY OF CHAR)
166 * Reads a 0X-terminated string.
169 * invalid index LEN(x) > Length(string)
171 * PROCEDURE (VAR rd: Reader) ReadStore (OUT x: Store)
173 * 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.
174 * 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.
175 * 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).
178 * 20 the reader is at the start position of a new store
181 * empty store on file
183 * non-empty store on file
189 * x.pos >= 0 beginning of store's data
190 * x.len >= 0 length of store's data
191 * alien store contents are on x.file in the range [x.pos .. x.pos + x.len[.
192 * These data include only the store's contents, not its prefix
194 * x was read successfully
198 * PROCEDURE (VAR rd: Reader) ReadVersion (min, max: INTEGER; OUT version: INTEGER)
200 * 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.
206 * min <= version <= max
208 * (version < min) OR (version > max)
210 * rd.cause = alienVersion
214 * PROCEDURE (VAR rd: Reader) TurnIntoAlien (cause: INTEGER)
216 * 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.
223 Store
*readStoreOrElemStore(bool isElem
);
224 Store
*readNilStore();
225 Store
*readLinkStore();
226 Store
*readNewLinkStore();
229 TypeName* = ARRAY 64 OF CHAR;
230 TypePath* = ARRAY 16 OF TypeName;
231 OpName* = ARRAY 32 OF CHAR;
233 inline CHAR
*newTypeName() {
236 inline CHAR
**newTypePath() {
237 CHAR
**out
= new CHAR
*[16];
238 for (int i
= 0; i
< 16; ++i
) {
239 out
[i
] = newTypeName();
243 void readPath(CHAR
**path
);