DEADSOFTWARE

Testing odcread against a bunch of existing .odc files
[odcread.git] / store.h
diff --git a/store.h b/store.h
index da8434060bf2af7999e2440fb45e85fb33efaef6..03d1c8f226021011461eaa4daeb3d669e3c1e572 100644 (file)
--- a/store.h
+++ b/store.h
@@ -2,8 +2,8 @@
 #define _STORE_H_
 
 #include <oberon.h>
-#include <domain.h>
 #include <typeregister.h>
+#include <visitor.h>
 
 #include <string>
 #include <vector>
@@ -25,12 +25,12 @@ namespace odc {
         */
        class Store {
        private:
-               static const std::string TYPENAME;
-               static const TypeProxy<Store> PROXY;
+               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 *)
@@ -44,25 +44,17 @@ namespace odc {
 
                INTEGER getId();
                
-               /**
-                * Get the TypeName of this object.
-                * @see TypeRegister
-                */
-               static const std::string &getType();
-               /**
-                * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
-                * @see TypeRegister
-                */
-               static const std::string *getSuper();
                /**
                 * 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
                 */
-               void getTypePath(TypePath *path) const;
+               TypePath getTypePath() const;
 
                /**
                 * PROCEDURE (s: Store) Domain (): Domain
@@ -73,130 +65,82 @@ namespace odc {
                //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
-               /**
-                * 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
-                */
-                virtual 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 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) 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.
+                * A debug "toString".
                 */
-               // FIXME
+               virtual std::string toString();
 
                /**
-                * 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
+                * Receiving end of the Visitor pattern.
                 */
-               // FIXME
-
-               virtual std::string toString();
+               virtual void accept(Visitor &visitor) const;
 
                private:
-               void calcTypePath(TypePath * out, const std::string &name) const;
+               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 std::string TYPENAME;
-               static const TypeProxy<Elem> PROXY;
+               static const TypeProxy<Elem, Store> PROXY;
 
                public:
+               static const std::string TYPENAME;
+               virtual const std::string &getTypeName() const;
+
                Elem(INTEGER id);
-               
-               /**
-                * Get the TypeName of this object.
-                * @see TypeRegister
-                */
-               static const std::string &getType();
                /**
-                * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
-                * @see TypeRegister
-                */
-               static const std::string *getSuper();
-               /**
-                * Get the TypeName for this object.
+                * Just calls super and reads the version and checks that its in the allowed range.
                 */
-               virtual const std::string &getTypeName() const;
-
                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 std::string TYPENAME;
-               static const TypeProxy<Model> PROXY;
+               static const TypeProxy<Model, Elem> PROXY;
 
                public:
+               static const std::string TYPENAME;
+               virtual const std::string &getTypeName() const;
+
                Model(INTEGER id);
-               
-               /**
-                * Get the TypeName of this object.
-                * @see TypeRegister
-                */
-               static const std::string &getType();
                /**
-                * Get the TypeName of the supertype of this object. Return 0 pointer if no supertype.
-                * @see TypeRegister
+                * Just calls super and reads the version and checks that its in the allowed range.
                 */
-               static const std::string *getSuper();
-               /**
-                * Get the TypeName for this object.
-                */
-               virtual const std::string &getTypeName() const;
-
                virtual void internalize(Reader &reader);
        };
 
+       /**
+        * Super type for models that contain other stuff (e.g. TextModel).
+        */
        class ContainerModel : public Model {
                private:
-               static const std::string TYPENAME;
-               static const TypeProxy<ContainerModel> PROXY;
+               static const TypeProxy<ContainerModel, Model> PROXY;
 
                public:
-               ContainerModel(INTEGER id);
-               static const std::string &getType();
-               static const std::string *getSuper();
+               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);
        };
 }