DEADSOFTWARE

Testing odcread against a bunch of existing .odc files
[odcread.git] / store.h
1 #ifndef _STORE_H_
2 #define _STORE_H_
4 #include <oberon.h>
5 #include <typeregister.h>
6 #include <visitor.h>
8 #include <string>
9 #include <vector>
11 namespace odc {
12 class Reader; // forward decl
14 class TypePath : public std::vector<std::string> {
15 public:
16 std::string toString() const;
17 };
19 /**
20 * TYPE Store
21 * ABSTRACT
22 * Storable extensible data types like Views.View or TextModels.Text are derived from Store.
23 * Stores are typically allocated by suitable directories, e.g., Views.Directory or TextModels.Directory.
24 * Stores are used as base types for all objects that must be both extensible and persistent.
25 */
26 class Store {
27 private:
28 static const TopTypeProxy<Store> PROXY;
30 INTEGER d_id;
32 public:
33 static const std::string TYPENAME;
34 static const SHORTCHAR NEWBASE = 0xF0; // (* new base type (level = 0), i.e. not yet in dict *)
35 static const SHORTCHAR NEWEXT = 0xF1; // (* new extension type (level = 1), i.e. not yet in dict *)
36 static const SHORTCHAR OLDTYPE = 0xF2; // (* old type, i.e. already in dict *)
37 static const SHORTCHAR NIL = 0x80; // (* nil store *)
38 static const SHORTCHAR LINK = 0x81; // (* link to another elem in same file *)
39 static const SHORTCHAR STORE = 0x82; // (* general store *)
40 static const SHORTCHAR ELEM = 0x83; // (* elem store *)
41 static const SHORTCHAR NEWLINK = 0x84; // (* link to another non-elem store in same file *)
43 Store(INTEGER id);
45 INTEGER getId();
47 /**
48 * Get the TypeName for this object.
49 */
50 virtual const std::string &getTypeName() const;
51 /**
52 * Get the TypePath to this object's type.
53 * I'm not sure why this was necessary, I think BlackBox uses them in some code
54 * I've omitted.
55 * @see TypePath
56 */
57 TypePath getTypePath() const;
59 /**
60 * PROCEDURE (s: Store) Domain (): Domain
61 * NEW
62 * A store may be associated with a domain. This is done by the procedure InitDomain, which assigns a domain to the store.
63 * Domain may be called by arbitrary clients.
64 */
65 //Domain* getDomain();
67 /**
68 * Read the contents of "this" from reader.
69 * Just reads the version and checks that its in the allowed range.
70 */
71 virtual void internalize(Reader &reader);
73 // In BlackBox, a Store will also have an externalize(writer) method.
74 // The internalize and externalize should be compatible (internalize
75 // should be able to read what externalize writes).
77 /**
78 * A debug "toString".
79 */
80 virtual std::string toString();
82 /**
83 * Receiving end of the Visitor pattern.
84 */
85 virtual void accept(Visitor &visitor) const;
87 private:
88 void calcTypePath(TypePath *out, const std::string &name) const;
89 };
91 /**
92 * An "Elem" store. Some kind of legacy BlackBox type that has been rolled into Store.
93 * I actually found it easier to keep the two separate.
94 */
95 class Elem : public Store {
96 private:
97 static const TypeProxy<Elem, Store> PROXY;
99 public:
100 static const std::string TYPENAME;
101 virtual const std::string &getTypeName() const;
103 Elem(INTEGER id);
104 /**
105 * Just calls super and reads the version and checks that its in the allowed range.
106 */
107 virtual void internalize(Reader &reader);
108 };
110 /**
111 * A "Model" store. The basis for all model objects (in MVC framework).
112 * Most objects of interest extend Model.
113 */
114 class Model : public Elem {
115 private:
116 static const TypeProxy<Model, Elem> PROXY;
118 public:
119 static const std::string TYPENAME;
120 virtual const std::string &getTypeName() const;
122 Model(INTEGER id);
123 /**
124 * Just calls super and reads the version and checks that its in the allowed range.
125 */
126 virtual void internalize(Reader &reader);
127 };
129 /**
130 * Super type for models that contain other stuff (e.g. TextModel).
131 */
132 class ContainerModel : public Model {
133 private:
134 static const TypeProxy<ContainerModel, Model> PROXY;
136 public:
137 static const std::string TYPENAME;
138 virtual const std::string &getTypeName() const;
140 ContainerModel(INTEGER id);
141 /**
142 * Just calls super and reads the version and checks that its in the allowed range.
143 */
144 virtual void internalize(Reader &reader);
145 };
148 #endif // _STORE_H_