DEADSOFTWARE

Completely convert .odc to .txt using Visitor
[odcread.git] / store.h
1 #ifndef _STORE_H_
2 #define _STORE_H_
4 #include <oberon.h>
5 #include <domain.h>
6 #include <typeregister.h>
7 #include <visitor.h>
9 #include <string>
10 #include <vector>
12 namespace odc {
13 class Reader; // forward decl
15 class TypePath : public std::vector<std::string> {
16 public:
17 std::string toString() const;
18 };
20 /**
21 * TYPE Store
22 * ABSTRACT
23 * Storable extensible data types like Views.View or TextModels.Text are derived from Store.
24 * Stores are typically allocated by suitable directories, e.g., Views.Directory or TextModels.Directory.
25 * Stores are used as base types for all objects that must be both extensible and persistent.
26 */
27 class Store {
28 private:
29 static const std::string TYPENAME;
30 static const TypeProxy<Store> PROXY;
32 INTEGER d_id;
34 public:
35 static const SHORTCHAR NEWBASE = 0xF0; // (* new base type (level = 0), i.e. not yet in dict *)
36 static const SHORTCHAR NEWEXT = 0xF1; // (* new extension type (level = 1), i.e. not yet in dict *)
37 static const SHORTCHAR OLDTYPE = 0xF2; // (* old type, i.e. already in dict *)
38 static const SHORTCHAR NIL = 0x80; // (* nil store *)
39 static const SHORTCHAR LINK = 0x81; // (* link to another elem in same file *)
40 static const SHORTCHAR STORE = 0x82; // (* general store *)
41 static const SHORTCHAR ELEM = 0x83; // (* elem store *)
42 static const SHORTCHAR NEWLINK = 0x84; // (* link to another non-elem store in same file *)
44 Store(INTEGER id);
46 INTEGER getId();
48 /**
49 * Get the TypeName of this object.
50 * @see TypeRegister
51 */
52 static const std::string &getType();
53 /**
54 * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
55 * @see TypeRegister
56 */
57 static const std::string *getSuper();
58 /**
59 * Get the TypeName for this object.
60 */
61 virtual const std::string &getTypeName() const;
62 /**
63 * Get the TypePath to this object's type.
64 * @see TypePath
65 */
66 void getTypePath(TypePath *path) const;
68 /**
69 * PROCEDURE (s: Store) Domain (): Domain
70 * NEW
71 * A store may be associated with a domain. This is done by the procedure InitDomain, which assigns a domain to the store.
72 * Domain may be called by arbitrary clients.
73 */
74 //Domain* getDomain();
76 /**
77 * PROCEDURE (s: Store) CopyFrom- (source: Store)
78 * NEW, EMPTY
79 * Copy the contents of source to s. Copying is a deep copy.
80 *
81 * Pre
82 * source # NIL guaranteed
83 * TYP(source) = TYP(s) guaranteed
84 * s.Domain() = NIL guaranteed
85 * s is not yet initialized guaranteed
86 */
87 // FIXME
88 /**
89 * PROCEDURE (s: Store) Internalize- (VAR rd: Reader)
90 * NEW, EMPTY
91 * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
92 * Reads the contents of s from reader rd. Internalize must read the same (amount of) data as is written by the corresponding Externalize procedure.
93 * Internalize is called locally.
94 * Internalize is extended by various persistent object types, e.g., models, views, and controllers.
95 *
96 * Pre
97 * source.Domain() = NIL guaranteed
98 * source is not yet initialized guaranteed
99 */
100 virtual void internalize(Reader &reader);
101 // PROCEDURE (s: Store) Internalize- (VAR rd: Reader), NEW, EXTENSIBLE;
102 // VAR thisVersion: INTEGER;
103 // BEGIN
104 // rd.ReadVersion(minVersion, maxStoreVersion, thisVersion);
105 // IF ~rd.cancelled & s.isElem THEN
106 // rd.ReadVersion(minVersion, maxStoreVersion, thisVersion)
107 // (* works since maxStoreVersion = maxElemVersion = 0 in pre-1.3 *)
108 // END
109 // END Internalize;
110 // }
112 /**
113 * PROCEDURE (s: Store) Externalize- (VAR wr: Writer)
114 * NEW, EMPTY
115 * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
116 * Write the contents of s to writer wr. Externalize must write the same (amount of) data as is read by the corresponding Internalize procedure.
117 * Externalize ist called locally.
118 * Externalize is extended by various persistent object types, e.g., models, views, and controllers.
119 */
120 // FIXME
122 /**
123 * PROCEDURE (s: Store) ExternalizeAs- (VAR s1: Store)
124 * NEW, EMPTY
125 * Before a store's Externalize procedure is called, its ExternalizeAs procedure is called, which gives the store the opportunity to denote another store that should be externalized in its place (a "proxy"). It is also possible to set s1 to NIL, which means that the store should not be externalized at all. This is used e.g. for compiler error markers, which are never stored.
126 * ExternalizeAs ist called locally.
127 *
128 * Pre
129 * s1 = s guaranteed
130 */
131 // FIXME
133 virtual std::string toString();
135 /**
136 * Receiving end of the Visitor pattern.
137 */
138 virtual void accept(Visitor &visitor) const;
140 private:
141 void calcTypePath(TypePath * out, const std::string &name) const;
142 };
144 class Elem : public Store {
145 private:
146 static const std::string TYPENAME;
147 static const TypeProxy<Elem> PROXY;
149 public:
150 Elem(INTEGER id);
152 /**
153 * Get the TypeName of this object.
154 * @see TypeRegister
155 */
156 static const std::string &getType();
157 /**
158 * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
159 * @see TypeRegister
160 */
161 static const std::string *getSuper();
162 /**
163 * Get the TypeName for this object.
164 */
165 virtual const std::string &getTypeName() const;
167 virtual void internalize(Reader &reader);
168 };
170 class Model : public Elem {
171 private:
172 static const std::string TYPENAME;
173 static const TypeProxy<Model> PROXY;
175 public:
176 Model(INTEGER id);
178 /**
179 * Get the TypeName of this object.
180 * @see TypeRegister
181 */
182 static const std::string &getType();
183 /**
184 * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
185 * @see TypeRegister
186 */
187 static const std::string *getSuper();
188 /**
189 * Get the TypeName for this object.
190 */
191 virtual const std::string &getTypeName() const;
193 virtual void internalize(Reader &reader);
194 };
196 class ContainerModel : public Model {
197 private:
198 static const std::string TYPENAME;
199 static const TypeProxy<ContainerModel> PROXY;
201 public:
202 ContainerModel(INTEGER id);
203 static const std::string &getType();
204 static const std::string *getSuper();
205 virtual const std::string &getTypeName() const;
206 virtual void internalize(Reader &reader);
207 };
210 #endif // _STORE_H_