8 #include "typepath/typepath.h"
16 const std::string name
;
19 TypeEntry(const std::string
&typeName
) : name(typeName
), baseId(-1) {}
23 * Used by Store.internalize() to read from file.
28 * The store was read as an Alien because its type is not registered.
31 static const unsigned int TYPENOTFOUND
= 1;
33 * The store was read as an Alien because its version is not in the accepted range.
35 static const unsigned int ALIENVERSION
= 2;
38 * The input stream associated with this reader.
40 std::istream
&d_rider
;
43 * Whether the currently executing Store.internalize() has been cancelled.
44 * If so, it will be read as an Alien.
49 * Cause of current read being an Alien.
54 * Whether any alien has been read from the input stream.
59 * The TypeList should be used for consistency checking on type paths.
62 std::vector
<TypeEntry
*> d_typeList
;
65 * List of stores that have been read already, to enable repeated occurences
66 * of a single store to reference them.
67 * Elem type stores have IDs that are separate from the IDs of other stores.
69 std::vector
<Store
*> d_elemList
;
71 * List of stores that have been read already, to enable repeated occurences
72 * of a single store to reference them.
73 * Elem type stores have IDs that are separate from the IDs of other stores.
75 std::vector
<Store
*> d_storeList
;
78 * Stores the reader state so that we can rewind a failed Store.internalize().
82 * Position of the next store in the current level
86 * Position just after the last read store
92 * The store that is currently being read.
97 * Reader state at the start of reading the current store (before calling Store.internalize())....
103 * Construct a reader from the istream rider.
104 * @param rider An istream (binary mode).
106 Reader(std::istream
&rider
);
108 /* Omitted reading methods:
110 * There are a number of ReadX* methods that read a SHORT type but return a LONG type. Those have been omitted.
112 * PROCEDURE (VAR rd: Reader) ReadBool (OUT x: BOOLEAN)
114 * Reads a Boolean value.
116 * PROCEDURE (VAR rd: Reader) ReadLong (OUT x: LONGINT)
118 * Reads a long integer (-9223372036854775808..9223372036854775807).
120 * PROCEDURE (VAR rd: Reader) ReadSReal (OUT x: SHORTREAL)
122 * Reads a short real (32-bit IEEE number).
124 * PROCEDURE (VAR rd: Reader) ReadReal (OUT x: REAL)
126 * Reads a real (64-bit IEEE number).
128 * PROCEDURE (VAR rd: Reader) ReadSet (OUT x: SET)
130 * Reads a set (32 elements).
132 * PROCEDURE (VAR rd: Reader) ReadString (OUT x: ARRAY OF CHAR)
134 * Reads a 0X-terminated string.
137 * Reads a short character (00X..0FFX).
139 SHORTCHAR
readSChar();
141 * Reads a string of short characters (00X..0FFX).
143 void readSChar(SHORTCHAR
*buf
, size_t len
);
145 * Reads a character (0000X..0FFFFX).
149 * Reads a string of characters (0000X..0FFFFX).
151 void readLChar(CHAR
*buf
, size_t len
);
153 * Reads a very short integer (-128..127).
157 * Reads a short integer (-32768..32767).
161 * Reads an integer (-2147483648..2147483647).
165 * Reads a 0X-terminated short string.
166 * Used to read string that have a known maximum length.
168 void readSString(SHORTCHAR
*out
);
170 * (Explanation from the BlackBox source.)
171 * 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.
172 * 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.
173 * 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).
177 * (Explanation from the BlackBox source.)
178 * Read a version byte and return it in version. If version is not in the
179 * specified range [min .. max], the store currently being read is turned
180 * into an alien, with cause = alienVersion.
182 INTEGER
readVersion(INTEGER min
, INTEGER max
);
184 * (Explanation from the BlackBox source.)
185 * A store which is currently being internalized can turn itself into an
186 * alien, e.g., if it has read a component store which is an alien.
188 void turnIntoAlien(int cause
);
191 * @return Whether the current read has been cancelled.
199 Store
*readStoreOrElemStore(bool isElem
);
201 * Read a Nil store. A Nil store doesn't contain anything, but may require us to skip some bytes.
203 Store
*readNilStore();
205 * Read a link to an Elem-type store.
207 Store
*readLinkStore();
209 * Read a link to a non-Elem-type store.
211 Store
*readNewLinkStore();
213 * Read an alien store.
215 void readAlien(Alien
*alien
, std::streampos down
, std::streampos end
);
218 * Make store name consistent with names found in BlackBox source.
220 std::string
&fixTypeName(std::string
&name
);
227 * Add another component to the current path. If first==true, start a new path.
229 void addPathComponent(bool first
, const std::string
&typeName
);
231 static bool isBigEndian();
232 static bool isLittleEndian();