DEADSOFTWARE

Documentation for store.h
[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 * I'm not sure why this was necessary, I think BlackBox uses them in some code
55 * I've omitted.
56 * @see TypePath
57 */
58 TypePath getTypePath() const;
60 /**
61 * PROCEDURE (s: Store) Domain (): Domain
62 * NEW
63 * A store may be associated with a domain. This is done by the procedure InitDomain, which assigns a domain to the store.
64 * Domain may be called by arbitrary clients.
65 */
66 //Domain* getDomain();
68 /**
69 * Read the contents of "this" from reader.
70 * Just reads the version and checks that its in the allowed range.
71 */
72 virtual void internalize(Reader &reader);
74 // In BlackBox, a Store will also have an externalize(writer) method.
75 // The internalize and externalize should be compatible (internalize
76 // should be able to read what externalize writes).
78 /**
79 * A debug "toString".
80 */
81 virtual std::string toString();
83 /**
84 * Receiving end of the Visitor pattern.
85 */
86 virtual void accept(Visitor &visitor) const;
88 private:
89 void calcTypePath(TypePath *out, const std::string &name) const;
90 };
92 /**
93 * An "Elem" store. Some kind of legacy BlackBox type that has been rolled into Store.
94 * I actually found it easier to keep the two separate.
95 */
96 class Elem : public Store {
97 private:
98 static const TypeProxy<Elem, Store> PROXY;
100 public:
101 static const std::string TYPENAME;
102 virtual const std::string &getTypeName() const;
104 Elem(INTEGER id);
105 /**
106 * Just calls super and reads the version and checks that its in the allowed range.
107 */
108 virtual void internalize(Reader &reader);
109 };
111 /**
112 * A "Model" store. The basis for all model objects (in MVC framework).
113 * Most objects of interest extend Model.
114 */
115 class Model : public Elem {
116 private:
117 static const TypeProxy<Model, Elem> PROXY;
119 public:
120 static const std::string TYPENAME;
121 virtual const std::string &getTypeName() const;
123 Model(INTEGER id);
124 /**
125 * Just calls super and reads the version and checks that its in the allowed range.
126 */
127 virtual void internalize(Reader &reader);
128 };
130 /**
131 * Super type for models that contain other stuff (e.g. TextModel).
132 */
133 class ContainerModel : public Model {
134 private:
135 static const TypeProxy<ContainerModel, Model> PROXY;
137 public:
138 static const std::string TYPENAME;
139 virtual const std::string &getTypeName() const;
141 ContainerModel(INTEGER id);
142 /**
143 * Just calls super and reads the version and checks that its in the allowed range.
144 */
145 virtual void internalize(Reader &reader);
146 };
149 #endif // _STORE_H_