DEADSOFTWARE

bc76a32798a9feff7848e7014bc6ca5ece906244
[odcread.git] / textmodel.cc
1 #include <textmodel.h>
2 #include <reader.h>
4 #include <vector>
6 namespace odc {
8 const std::string TextModel::TYPENAME("TextModels.Model^");
9 const TypeProxy<TextModel> TextModel::PROXY;
11 TextModel::TextModel(INTEGER id) : ContainerModel(id) {}
13 const std::string &TextModel::getType() {
14 return TYPENAME;
15 }
17 const std::string *TextModel::getSuper() {
18 return &ContainerModel::getType();
19 }
21 const std::string &TextModel::getTypeName() const {
22 return getType();
23 }
25 void TextModel::internalize(Reader &reader) {
26 ContainerModel::internalize(reader);
27 if (reader.isCancelled()) return;
28 reader.readVersion(0, 0);
29 }
31 const std::string StdTextModel::TYPENAME("TextModels.StdModel^");
32 const TypeProxy<StdTextModel> StdTextModel::PROXY;
34 StdTextModel::StdTextModel(INTEGER id) : TextModel(id) {}
36 const std::string &StdTextModel::getType() {
37 return TYPENAME;
38 }
40 const std::string *StdTextModel::getSuper() {
41 return &TextModel::getType();
42 }
44 const std::string &StdTextModel::getTypeName() const {
45 return getType();
46 }
48 /*
49 * This is my current theory of how the StdTextModel storage format works:
50 * byte 0: version
51 * byte 1-5: len (length of piece descriptions)
52 * byte 6-5+len: piece descriptions
53 * byte 6+len-end: pieces (length of each defined in piece descriptions)
54 */
55 void StdTextModel::internalize(Reader &reader) {
56 TextModel::internalize(reader);
57 if (reader.isCancelled()) return;
58 reader.readVersion(0, 1);
59 if (reader.isCancelled()) return;
61 std::vector<Store *> dict;
62 INTEGER len = reader.readInt();
63 BYTE ano = reader.readByte();
64 std::cout << "len " << len << " ano " << (int)ano << std::endl;
65 while (ano != -1) {
66 if (ano == dict.size()) {
67 Store *attr = reader.readStore(); // readAttributes(); Stores.Join(t, attr)
68 dict.push_back(attr);
69 }
70 INTEGER pieceLen = reader.readInt();
71 if (pieceLen > 0) { // shortchar piece
72 std::cout << "Found SChar piece" << std::endl;
73 // NEW(sp); sp.len := len; sp.attr := attr;
74 // sp.file := rd.rider.Base(); sp.org := org; un := sp;
75 // INC(org, len) -- increment org by len ?
76 } else if (pieceLen < 0) { // longchar piece
77 std::cout << "Found LChar piece" << std::endl;
78 // len := -len; ASSERT(~ODD(len), 100);
79 // NEW(lp); lp.len := len DIV 2; lp.attr := attr;
80 // lp.file := rd.rider.Base(); lp.org := org; un := lp;
81 // INC(org, len) -- increment org by len ?
82 } else { // embedded view
83 reader.readInt(); reader.readInt();
84 Store *view = reader.readStore(); // fixme: save somewhere
85 // NEW(v); v.len := 1; v.attr := attr;
86 // rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view);
87 // v.view.InitContext(NewContext(v, t));
88 // un := v; INC(org) -- increment org by one?? WTH?
89 }
90 ano = reader.readByte();
91 }
92 // rd.SetPos(org);
93 }
94 // PROCEDURE (t: StdModel) Internalize (VAR rd: Stores.Reader);
95 // VAR u, un: Run; sp: Piece; lp: LPiece; v: ViewRef;
96 // org, len: INTEGER; ano: BYTE; thisVersion: INTEGER;
97 // attr: Attributes; dict: AttrDict;
98 // BEGIN
99 // ASSERT(t.Domain() = NIL, 20); ASSERT(t.len = 0, 21);
100 // t.Internalize^(rd); IF rd.cancelled THEN RETURN END;
101 // rd.ReadVersion(minVersion, maxStdModelVersion, thisVersion);
102 // IF rd.cancelled THEN RETURN END;
103 // StdInit(t);
104 // dict.len := 0; u := t.trailer;
105 // rd.ReadInt(len); org := rd.Pos() + len;
106 // rd.ReadByte(ano);
107 // WHILE ano # -1 DO
108 // IF ano = dict.len THEN
109 // ReadAttr(rd, attr); Stores.Join(t, attr);
110 // IF dict.len < dictSize THEN dict.attr[dict.len] := attr; INC(dict.len) END
111 // ELSE
112 // attr := dict.attr[ano]
113 // END;
114 // rd.ReadInt(len);
115 // IF len > 0 THEN (* piece *)
116 // NEW(sp); sp.len := len; sp.attr := attr;
117 // sp.file := rd.rider.Base(); sp.org := org; un := sp;
118 // INC(org, len)
119 // ELSIF len < 0 THEN (* longchar piece *)
120 // len := -len; ASSERT(~ODD(len), 100);
121 // NEW(lp); lp.len := len DIV 2; lp.attr := attr;
122 // lp.file := rd.rider.Base(); lp.org := org; un := lp;
123 // INC(org, len)
124 // ELSE (* len = 0 => embedded view *)
125 // NEW(v); v.len := 1; v.attr := attr;
126 // rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view);
127 // v.view.InitContext(NewContext(v, t));
128 // un := v; INC(org)
129 // END;
130 // INC(t.len, un.len); u.next := un; un.prev := u; u := un;
131 // rd.ReadByte(ano)
132 // END;
133 // rd.SetPos(org);
134 // u.next := t.trailer; t.trailer.prev := u
135 // END Internalize;
136 //
138 } // namespace odc