DEADSOFTWARE

Add type handling (disabled until StdTextModel.internalize is implemented)
[odcread.git] / store.cc
1 #include <store.h>
2 #include <reader.h>
4 #include <iostream>
7 namespace odc {
9 template<class T, class A> T join(const A & begin, const A & end, const T &sep) {
10 T result;
12 if (begin != end) {
13 A it = begin;
14 result.append(*it);
15 for (++it; it != end; ++it) {
16 result.append(sep).append(*it);
17 }
18 }
20 return result;
21 }
23 std::string TypePath::toString() const {
24 return join(begin(), end(), std::string("->"));
25 }
27 const std::string Store::TYPENAME("Stores.Store^");
28 const TypeProxy<Store> Store::PROXY;
29 TypePath *Store::s_typePath = 0;
31 Store::Store(INTEGER id): d_id(id) {}
33 INTEGER Store::getId() {
34 return d_id;
35 }
37 const std::string &Store::getType() {
38 return Store::TYPENAME;
39 }
41 const std::string *Store::getSuper() {
42 return 0;
43 }
45 const std::string &Store::getTypeName() const {
46 return Store::getType();
47 }
49 const TypePath &Store::getTypePath() const {
50 if (s_typePath == 0) {
51 s_typePath = calcTypePath(getTypeName());
52 }
53 return *s_typePath;
54 }
56 TypePath *Store::calcTypePath(const std::string &name) const {
57 const std::string *super = TypeRegister::getInstance().get(name)->getSuper();
58 TypePath *path;
59 if (super != 0) {
60 path = calcTypePath(*super);
61 } else {
62 path = new TypePath();
63 }
64 path->push_back(name);
65 return path;
66 }
68 void Store::internalize(Reader &reader) {
69 reader.readVersion(0, 0);
70 }
72 std::string Store::toString() {
73 return getTypeName();
74 }
76 const std::string Elem::TYPENAME("Stores.Elem^");
77 const TypeProxy<Elem> Elem::PROXY;
79 Elem::Elem(INTEGER id) : Store(id) {}
81 const std::string &Elem::getType() {
82 return TYPENAME;
83 }
85 const std::string *Elem::getSuper() {
86 return &Store::getType();
87 }
89 const std::string &Elem::getTypeName() const {
90 return getType();
91 }
93 void Elem::internalize(Reader &reader) {
94 Store::internalize(reader); // just being explicit
95 }
97 const std::string Model::TYPENAME("Models.Model^");
98 const TypeProxy<Model> Model::PROXY;
100 Model::Model(INTEGER id) : Elem(id) {}
102 const std::string &Model::getType() {
103 return TYPENAME;
106 const std::string *Model::getSuper() {
107 return &Elem::getType();
110 const std::string &Model::getTypeName() const {
111 return getType();
114 void Model::internalize(Reader &reader) {
115 Model::internalize(reader);
116 reader.readVersion(0, 0);
119 const std::string ContainerModel::TYPENAME("Containers.Model^");
120 const TypeProxy<ContainerModel> ContainerModel::PROXY;
122 ContainerModel::ContainerModel(INTEGER id) : Model(id) {}
124 const std::string &ContainerModel::getType() {
125 return TYPENAME;
128 const std::string *ContainerModel::getSuper() {
129 return &Model::getType();
132 const std::string &ContainerModel::getTypeName() const {
133 return getType();
136 void ContainerModel::internalize(Reader &reader) {
137 Model::internalize(reader);
138 reader.readVersion(0, 0);
141 const std::string TextModel::TYPENAME("TextModels.Model^");
142 const TypeProxy<TextModel> TextModel::PROXY;
144 TextModel::TextModel(INTEGER id) : ContainerModel(id) {}
146 const std::string &TextModel::getType() {
147 return TYPENAME;
150 const std::string *TextModel::getSuper() {
151 return &ContainerModel::getType();
154 const std::string &TextModel::getTypeName() const {
155 return getType();
158 void TextModel::internalize(Reader &reader) {
159 ContainerModel::internalize(reader);
160 reader.readVersion(0, 0);
163 const std::string StdTextModel::TYPENAME("TextModels.StdModel^");
164 //const TypeProxy<StdTextModel> StdTextModel::PROXY;
166 StdTextModel::StdTextModel(INTEGER id) : TextModel(id) {}
168 const std::string &StdTextModel::getType() {
169 return TYPENAME;
172 const std::string *StdTextModel::getSuper() {
173 return &TextModel::getType();
176 const std::string &StdTextModel::getTypeName() const {
177 return getType();
180 void StdTextModel::internalize(Reader &reader) {
181 TextModel::internalize(reader);
182 reader.readVersion(0, 1);
184 // PROCEDURE (t: StdModel) Internalize (VAR rd: Stores.Reader);
185 // VAR u, un: Run; sp: Piece; lp: LPiece; v: ViewRef;
186 // org, len: INTEGER; ano: BYTE; thisVersion: INTEGER;
187 // attr: Attributes; dict: AttrDict;
188 // BEGIN
189 // ASSERT(t.Domain() = NIL, 20); ASSERT(t.len = 0, 21);
190 // t.Internalize^(rd); IF rd.cancelled THEN RETURN END;
191 // rd.ReadVersion(minVersion, maxStdModelVersion, thisVersion);
192 // IF rd.cancelled THEN RETURN END;
193 // StdInit(t);
194 // dict.len := 0; u := t.trailer;
195 // rd.ReadInt(len); org := rd.Pos() + len;
196 // rd.ReadByte(ano);
197 // WHILE ano # -1 DO
198 // IF ano = dict.len THEN
199 // ReadAttr(rd, attr); Stores.Join(t, attr);
200 // IF dict.len < dictSize THEN dict.attr[dict.len] := attr; INC(dict.len) END
201 // ELSE
202 // attr := dict.attr[ano]
203 // END;
204 // rd.ReadInt(len);
205 // IF len > 0 THEN (* piece *)
206 // NEW(sp); sp.len := len; sp.attr := attr;
207 // sp.file := rd.rider.Base(); sp.org := org; un := sp;
208 // INC(org, len)
209 // ELSIF len < 0 THEN (* longchar piece *)
210 // len := -len; ASSERT(~ODD(len), 100);
211 // NEW(lp); lp.len := len DIV 2; lp.attr := attr;
212 // lp.file := rd.rider.Base(); lp.org := org; un := lp;
213 // INC(org, len)
214 // ELSE (* len = 0 => embedded view *)
215 // NEW(v); v.len := 1; v.attr := attr;
216 // rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view);
217 // v.view.InitContext(NewContext(v, t));
218 // un := v; INC(org)
219 // END;
220 // INC(t.len, un.len); u.next := un; un.prev := u; u := un;
221 // rd.ReadByte(ano)
222 // END;
223 // rd.SetPos(org);
224 // u.next := t.trailer; t.trailer.prev := u
225 // END Internalize;
226 //
231 } // namespace odc