DEADSOFTWARE

Testing odcread against a bunch of existing .odc files
[odcread.git] / store.h
diff --git a/store.h b/store.h
index be351b70ea70092709155aa9b1c2e750d95e7ceb..03d1c8f226021011461eaa4daeb3d669e3c1e572 100644 (file)
--- a/store.h
+++ b/store.h
@@ -2,11 +2,19 @@
 #define _STORE_H_
 
 #include <oberon.h>
-#include <domain.h>
+#include <typeregister.h>
+#include <visitor.h>
 
 #include <string>
+#include <vector>
 
 namespace odc {
+       class Reader; // forward decl
+
+       class TypePath : public std::vector<std::string> {
+               public:
+               std::string toString() const;
+       };
 
        /**
         * TYPE Store
@@ -17,9 +25,12 @@ namespace odc {
         */
        class Store {
        private:
+               static const TopTypeProxy<Store> PROXY;
+
                INTEGER d_id;
 
        public: 
+               static const std::string TYPENAME;
                static const SHORTCHAR NEWBASE = 0xF0; // (* new base type (level = 0), i.e. not yet in dict *)
                static const SHORTCHAR NEWEXT = 0xF1;  // (* new extension type (level = 1), i.e. not yet in dict *)
                static const SHORTCHAR OLDTYPE = 0xF2; // (* old type, i.e. already in dict *)
@@ -33,6 +44,17 @@ namespace odc {
 
                INTEGER getId();
                
+               /**
+                * Get the TypeName for this object.
+                */
+               virtual const std::string &getTypeName() const;
+               /**
+                * Get the TypePath to this object's type.
+                * I'm not sure why this was necessary, I think BlackBox uses them in some code
+                * I've omitted.
+                * @see TypePath
+                */
+               TypePath getTypePath() const;
 
                /**
                 * PROCEDURE (s: Store) Domain (): Domain
@@ -40,68 +62,87 @@ namespace odc {
                 * A store may be associated with a domain. This is done by the procedure InitDomain, which assigns a domain to the store.
                 * Domain may be called by arbitrary clients.
                 */
-               Domain* getDomain();
+               //Domain* getDomain();
 
                /**
-                * PROCEDURE (s: Store) CopyFrom- (source: Store)
-                * NEW, EMPTY
-                * Copy the contents of source to s. Copying is a deep copy.
-                *
-                * Pre
-                * source # NIL guaranteed
-                * TYP(source) = TYP(s) guaranteed
-                * s.Domain() = NIL     guaranteed
-                * s is not yet initialized     guaranteed
+                * Read the contents of "this" from reader.
+                * Just reads the version and checks that its in the allowed range.
                 */
-               // FIXME
+               virtual void internalize(Reader &reader);
+
+               // In BlackBox, a Store will also have an externalize(writer) method.
+               // The internalize and externalize should be compatible (internalize
+               // should be able to read what externalize writes).
+
                /**
-                * PROCEDURE (s: Store) Internalize- (VAR rd: Reader)
-                * NEW, EMPTY
-                * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
-                * Reads the contents of s from reader rd. Internalize must read the same (amount of) data as is written by the corresponding Externalize procedure.
-                * Internalize is called locally.
-                * Internalize is extended by various persistent object types, e.g., models, views, and controllers.
-                *
-                * Pre
-                * source.Domain() = NIL        guaranteed
-                * source is not yet initialized        guaranteed
+                * A debug "toString".
                 */
-//              void internalize(Reader &reader) {
-//     PROCEDURE (s: Store) Internalize- (VAR rd: Reader), NEW, EXTENSIBLE;
-//             VAR thisVersion: INTEGER;
-//     BEGIN
-//             rd.ReadVersion(minVersion, maxStoreVersion, thisVersion);
-//             IF ~rd.cancelled & s.isElem THEN
-//                     rd.ReadVersion(minVersion, maxStoreVersion, thisVersion)
-//                     (* works since maxStoreVersion = maxElemVersion = 0 in pre-1.3 *)
-//             END     
-//     END Internalize;        
-//             }
+               virtual std::string toString();
 
                /**
-                * PROCEDURE (s: Store) Externalize- (VAR wr: Writer)
-                * NEW, EMPTY
-                * (For backward compatibility, this method is actually still EXTENSIBLE. This may change in the future.)
-                * Write the contents of s to writer wr. Externalize must write the same (amount of) data as is read by the corresponding Internalize procedure.
-                * Externalize ist called locally.
-                * Externalize is extended by various persistent object types, e.g., models, views, and controllers.
+                * Receiving end of the Visitor pattern.
                 */
-               // FIXME
+               virtual void accept(Visitor &visitor) const;
+
+               private:
+               void calcTypePath(TypePath *out, const std::string &name) const;
+       };
+
+       /**
+        * An "Elem" store. Some kind of legacy BlackBox type that has been rolled into Store.
+        * I actually found it easier to keep the two separate.
+        */
+       class Elem : public Store {
+               private:
+               static const TypeProxy<Elem, Store> PROXY;
+
+               public:
+               static const std::string TYPENAME;
+               virtual const std::string &getTypeName() const;
 
+               Elem(INTEGER id);
                /**
-                * PROCEDURE (s: Store) ExternalizeAs- (VAR s1: Store)
-                * NEW, EMPTY
-                * 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.
-                * ExternalizeAs ist called locally.
-                * 
-                * Pre
-                * s1 = s       guaranteed
+                * Just calls super and reads the version and checks that its in the allowed range.
                 */
-               // FIXME
+               virtual void internalize(Reader &reader);
+       };
+
+       /**
+        * A "Model" store. The basis for all model objects (in MVC framework).
+        * Most objects of interest extend Model.
+        */
+       class Model : public Elem {
+               private:
+               static const TypeProxy<Model, Elem> PROXY;
 
-               virtual std::string toString() = 0;
+               public:
+               static const std::string TYPENAME;
+               virtual const std::string &getTypeName() const;
+
+               Model(INTEGER id);
+               /**
+                * Just calls super and reads the version and checks that its in the allowed range.
+                */
+               virtual void internalize(Reader &reader);
        };
 
+       /**
+        * Super type for models that contain other stuff (e.g. TextModel).
+        */
+       class ContainerModel : public Model {
+               private:
+               static const TypeProxy<ContainerModel, Model> PROXY;
+
+               public:
+               static const std::string TYPENAME;
+               virtual const std::string &getTypeName() const;
+
+               ContainerModel(INTEGER id);
+               /**
+                * Just calls super and reads the version and checks that its in the allowed range.
+                */
+               virtual void internalize(Reader &reader);
+       };
 }
 
 #endif // _STORE_H_