DEADSOFTWARE

Reduce boilerplate for BlackBox Types and add some javadoc.
[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 TopTypeProxy<Store> PROXY;
31 INTEGER d_id;
33 public:
34 static const std::string TYPENAME;
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 for this object.
50 */
51 virtual const std::string &getTypeName() const;
52 /**
53 * Get the TypePath to this object's type.
54 * @see TypePath
55 */
56 TypePath getTypePath() const;
58 /**
59 * PROCEDURE (s: Store) Domain (): Domain
60 * NEW
61 * A store may be associated with a domain. This is done by the procedure InitDomain, which assigns a domain to the store.
62 * Domain may be called by arbitrary clients.
63 */
64 //Domain* getDomain();
66 /**
67 * PROCEDURE (s: Store) CopyFrom- (source: Store)
68 * NEW, EMPTY
69 * Copy the contents of source to s. Copying is a deep copy.
70 *
71 * Pre
72 * source # NIL guaranteed
73 * TYP(source) = TYP(s) guaranteed
74 * s.Domain() = NIL guaranteed
75 * s is not yet initialized guaranteed
76 */
77 // FIXME
78 /**
79 * PROCEDURE (s: Store) Internalize- (VAR rd: Reader)
80 * NEW, EMPTY
81 * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
82 * Reads the contents of s from reader rd. Internalize must read the same (amount of) data as is written by the corresponding Externalize procedure.
83 * Internalize is called locally.
84 * Internalize is extended by various persistent object types, e.g., models, views, and controllers.
85 *
86 * Pre
87 * source.Domain() = NIL guaranteed
88 * source is not yet initialized guaranteed
89 */
90 virtual void internalize(Reader &reader);
91 // PROCEDURE (s: Store) Internalize- (VAR rd: Reader), NEW, EXTENSIBLE;
92 // VAR thisVersion: INTEGER;
93 // BEGIN
94 // rd.ReadVersion(minVersion, maxStoreVersion, thisVersion);
95 // IF ~rd.cancelled & s.isElem THEN
96 // rd.ReadVersion(minVersion, maxStoreVersion, thisVersion)
97 // (* works since maxStoreVersion = maxElemVersion = 0 in pre-1.3 *)
98 // END
99 // END Internalize;
100 // }
102 /**
103 * PROCEDURE (s: Store) Externalize- (VAR wr: Writer)
104 * NEW, EMPTY
105 * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
106 * Write the contents of s to writer wr. Externalize must write the same (amount of) data as is read by the corresponding Internalize procedure.
107 * Externalize ist called locally.
108 * Externalize is extended by various persistent object types, e.g., models, views, and controllers.
109 */
110 // FIXME
112 /**
113 * PROCEDURE (s: Store) ExternalizeAs- (VAR s1: Store)
114 * NEW, EMPTY
115 * 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.
116 * ExternalizeAs ist called locally.
117 *
118 * Pre
119 * s1 = s guaranteed
120 */
121 // FIXME
123 virtual std::string toString();
125 /**
126 * Receiving end of the Visitor pattern.
127 */
128 virtual void accept(Visitor &visitor) const;
130 private:
131 void calcTypePath(TypePath *out, const std::string &name) const;
132 };
134 class Elem : public Store {
135 private:
136 static const TypeProxy<Elem, Store> PROXY;
138 public:
139 static const std::string TYPENAME;
140 virtual const std::string &getTypeName() const;
142 Elem(INTEGER id);
143 virtual void internalize(Reader &reader);
144 };
146 class Model : public Elem {
147 private:
148 static const TypeProxy<Model, Elem> PROXY;
150 public:
151 static const std::string TYPENAME;
152 virtual const std::string &getTypeName() const;
154 Model(INTEGER id);
155 virtual void internalize(Reader &reader);
156 };
158 class ContainerModel : public Model {
159 private:
160 static const TypeProxy<ContainerModel, Model> PROXY;
162 public:
163 static const std::string TYPENAME;
164 virtual const std::string &getTypeName() const;
166 ContainerModel(INTEGER id);
167 virtual void internalize(Reader &reader);
168 };
171 #endif // _STORE_H_