DEADSOFTWARE

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