DEADSOFTWARE

Rename .ih files to module.ih for simplicity
[odcread.git] / reader / readStoreOrElemStore.cc
1 #include "reader/module.ih"
3 namespace odc {
5 Store *Reader::readStoreOrElemStore(bool isElem) {
6 INTEGER id = isElem ? d_elemList.size() : d_storeList.size();
7 TypePath path = readPath();
8 //std::cout << path.toString() << std::endl;
9 const std::string &type = path[0];
10 INTEGER comment = readInt();
11 std::streampos pos1 = d_rider.tellg();
12 std::streamoff next = readInt();
13 std::streamoff down = readInt();
14 std::streamoff len = readInt();
15 std::streampos pos = d_rider.tellg();
16 if (next > 0) {
17 d_state->next = pos1 + next + (std::streamoff)4;
18 } else {
19 d_state->next = 0;
20 }
21 int downPos = 0;
22 if (down > 0) {
23 downPos = pos1 + down + (std::streamoff)8;
24 }
25 d_state->end = pos + len;
26 d_cause = 0;
27 assert(len >= 0);
28 if (next != 0) {
29 assert(d_state->next > pos1);
30 if (down != 0) {
31 assert(downPos < d_state->next);
32 }
33 }
34 if (down > 0) {
35 assert(downPos > pos1);
36 assert(downPos < d_state->end);
37 }
39 const TypeProxyBase *t = TypeRegister::getInstance().get(type); // FIXME type lookup here
40 Store *x = 0;
41 if (t != 0) {
42 x = t->newInstance(id);
43 } else {
44 d_cause = TYPENOTFOUND;
45 }
47 if (x != 0) { // IF READING SUCCEEDS, INSERT MORE CHECKS HERE
48 if (true) { // samePath(x, path)
49 ReaderState *save = d_state;
50 d_state = new ReaderState();
51 x->internalize(*this);
52 delete d_state;
53 d_state = save;
55 if (d_cause != 0) {
56 x = 0;
57 }
58 assert(d_rider.tellg() == d_state->end);
59 assert(!d_rider.eof());
60 } else {
61 // rd.cause := inconsistentType; AlienTypeReport(rd.cause, type);
62 x = 0;
63 }
64 }
66 if (x != 0) {
67 if (d_store == 0) {
68 d_store = x;
69 } else {
70 // join(d_store, x)
71 }
72 if (isElem) {
73 d_elemList.push_back(x);
74 } else {
75 d_storeList.push_back(x);
76 }
77 } else {
78 d_rider.seekg(pos); // x->internalize() could have left us anywhere
79 assert(d_cause != 0);
80 Alien *alien = new Alien(id, path); //, d_cause); //,file
81 if (d_store == 0) {
82 d_store = alien;
83 } else {
84 // join(d_store, alien)
85 }
86 if (isElem) {
87 d_elemList.push_back(alien);
88 } else {
89 d_storeList.push_back(alien);
90 }
91 ReaderState *save = d_state;
92 d_state = new ReaderState();
93 readAlien(alien, downPos, save->end);
94 delete d_state;
95 d_state = save;
96 assert(d_rider.tellg() == d_state->end);
98 // we've just read the alien, so reset the state
99 d_cause = 0;
100 d_cancelled = false;
101 d_readAlien = true;
102 return alien;
105 return x;
108 } // namespace odc