summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c715680)
raw | patch | inline | side by side (parent: c715680)
author | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Wed, 9 Nov 2011 17:56:55 +0000 (17:56 +0000) | ||
committer | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Wed, 9 Nov 2011 17:56:55 +0000 (17:56 +0000) |
fold.cc | patch | blob | history | |
fold.h | patch | blob | history | |
store.cc | patch | blob | history | |
store.h | patch | blob | history | |
textmodel.cc | patch | blob | history | |
textmodel.h | patch | blob | history | |
typeregister.h | patch | blob | history |
index 37e0fd667756bff233d05d0a9f911d6257b373b8..b88d24b66a303e2b0602e755cfd01c6cbcdff707 100644 (file)
--- a/fold.cc
+++ b/fold.cc
namespace odc {
const std::string View::TYPENAME("Views.View^");
-const TypeProxy<View> View::PROXY;
+const TypeProxy<View, Store> View::PROXY;
View::View(INTEGER id) : Store(id) {}
-const std::string &View::getType() {
- return TYPENAME;
-}
-
-const std::string *View::getSuper() {
- return &Store::getType();
-}
-
const std::string &View::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void View::internalize(Reader &reader) {
}
const std::string Fold::TYPENAME("StdFolds.Fold^");
-const TypeProxy<Fold> Fold::PROXY;
+const TypeProxy<Fold, View> Fold::PROXY;
Fold::Fold(INTEGER id) : View(id) {}
-const std::string &Fold::getType() {
- return TYPENAME;
-}
-
-const std::string *Fold::getSuper() {
- return &View::getType();
-}
-
const std::string &Fold::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void Fold::internalize(Reader &reader) {
index 589b76b28783fa740cb718e700231fbb09a9d0d8..79ee7354cc7c0c005f30f859ab5799240e83c101 100644 (file)
--- a/fold.h
+++ b/fold.h
class View : public Store {
private:
- static const std::string TYPENAME;
- static const TypeProxy<View> PROXY;
+ static const TypeProxy<View, Store> PROXY;
public:
- View(INTEGER id);
- static const std::string &getType();
- static const std::string *getSuper();
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+
+ View(INTEGER id);
virtual void internalize(Reader &reader);
};
class Fold : public View {
private:
- static const std::string TYPENAME;
- static const TypeProxy<Fold> PROXY;
+ static const TypeProxy<Fold, View> PROXY;
Store *d_hidden;
SHORTCHAR *d_label;
bool d_collapsed;
public:
- Fold(INTEGER id);
- static const std::string &getType();
- static const std::string *getSuper();
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+
+ Fold(INTEGER id);
virtual void internalize(Reader &reader);
virtual std::string toString();
diff --git a/store.cc b/store.cc
index 4bbabf83591858e3106d1a1fd5cd4767240d3362..6f44e8525457c8135b7eafc9c773753fc93a545f 100644 (file)
--- a/store.cc
+++ b/store.cc
}
const std::string Store::TYPENAME("Stores.Store^");
-const TypeProxy<Store> Store::PROXY;
+const TopTypeProxy<Store> Store::PROXY;
Store::Store(INTEGER id): d_id(id) {}
return d_id;
}
-const std::string &Store::getType() {
- return Store::TYPENAME;
-}
-
-const std::string *Store::getSuper() {
- return 0;
-}
-
const std::string &Store::getTypeName() const {
- return Store::getType();
+ return Store::TYPENAME;
}
-void Store::getTypePath(TypePath *out) const {
- return calcTypePath(out, getTypeName());
+TypePath Store::getTypePath() const {
+ TypePath out;
+ calcTypePath(&out, getTypeName());
+ return out;
}
void Store::calcTypePath(TypePath *path, const std::string &name) const {
void Store::accept(Visitor &visitor) const {}
const std::string Elem::TYPENAME("Stores.Elem^");
-const TypeProxy<Elem> Elem::PROXY;
+const TypeProxy<Elem, Store> Elem::PROXY;
Elem::Elem(INTEGER id) : Store(id) {}
-const std::string &Elem::getType() {
- return TYPENAME;
-}
-
-const std::string *Elem::getSuper() {
- return &Store::getType();
-}
-
const std::string &Elem::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void Elem::internalize(Reader &reader) {
}
const std::string Model::TYPENAME("Models.Model^");
-const TypeProxy<Model> Model::PROXY;
+const TypeProxy<Model, Elem> Model::PROXY;
Model::Model(INTEGER id) : Elem(id) {}
-const std::string &Model::getType() {
- return TYPENAME;
-}
-
-const std::string *Model::getSuper() {
- return &Elem::getType();
-}
-
const std::string &Model::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void Model::internalize(Reader &reader) {
}
const std::string ContainerModel::TYPENAME("Containers.Model^");
-const TypeProxy<ContainerModel> ContainerModel::PROXY;
+const TypeProxy<ContainerModel, Model> ContainerModel::PROXY;
ContainerModel::ContainerModel(INTEGER id) : Model(id) {}
-const std::string &ContainerModel::getType() {
- return TYPENAME;
-}
-
-const std::string *ContainerModel::getSuper() {
- return &Model::getType();
-}
-
const std::string &ContainerModel::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void ContainerModel::internalize(Reader &reader) {
index 4e7360e782170315dafd917c53816b6ae5d141c4..a77febecbe6bb3514fc1a3b07e6a9ae8e835c858 100644 (file)
--- a/store.h
+++ b/store.h
*/
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 *)
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.
*/
* Get the TypePath to this object's type.
* @see TypePath
*/
- void getTypePath(TypePath *path) const;
+ TypePath getTypePath() const;
/**
* PROCEDURE (s: Store) Domain (): Domain
* source.Domain() = NIL guaranteed
* source is not yet initialized guaranteed
*/
- virtual void internalize(Reader &reader);
+ virtual void internalize(Reader &reader);
// PROCEDURE (s: Store) Internalize- (VAR rd: Reader), NEW, EXTENSIBLE;
// VAR thisVersion: INTEGER;
// BEGIN
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;
};
class Elem : public Store {
private:
- static const std::string TYPENAME;
- static const TypeProxy<Elem> PROXY;
+ static const TypeProxy<Elem, Store> PROXY;
public:
- 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.
- */
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+ Elem(INTEGER id);
virtual void internalize(Reader &reader);
};
class Model : public Elem {
private:
- static const std::string TYPENAME;
- static const TypeProxy<Model> PROXY;
+ static const TypeProxy<Model, Elem> PROXY;
public:
- 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
- */
- static const std::string *getSuper();
- /**
- * Get the TypeName for this object.
- */
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+ Model(INTEGER id);
virtual void internalize(Reader &reader);
};
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);
virtual void internalize(Reader &reader);
};
}
diff --git a/textmodel.cc b/textmodel.cc
index 56bedbae3aa34a82d08c8249a16796fcb71099b8..c02620c36c9e0dd5c97b31c493f3ebddb827eb0a 100644 (file)
--- a/textmodel.cc
+++ b/textmodel.cc
namespace odc {
const std::string TextModel::TYPENAME("TextModels.Model^");
-const TypeProxy<TextModel> TextModel::PROXY;
+const TypeProxy<TextModel, ContainerModel> TextModel::PROXY;
TextModel::TextModel(INTEGER id) : ContainerModel(id) {}
-const std::string &TextModel::getType() {
- return TYPENAME;
-}
-
-const std::string *TextModel::getSuper() {
- return &ContainerModel::getType();
-}
-
const std::string &TextModel::getTypeName() const {
- return getType();
+ return TYPENAME;
}
void TextModel::internalize(Reader &reader) {
}
const std::string StdTextModel::TYPENAME("TextModels.StdModel^");
-const TypeProxy<StdTextModel> StdTextModel::PROXY;
+const TypeProxy<StdTextModel, TextModel> StdTextModel::PROXY;
StdTextModel::StdTextModel(INTEGER id) : TextModel(id), d_pieces() {}
-const std::string &StdTextModel::getType() {
- return TYPENAME;
-}
-
-const std::string *StdTextModel::getSuper() {
- return &TextModel::getType();
-}
-
const std::string &StdTextModel::getTypeName() const {
- return getType();
+ return TYPENAME;
}
/*
diff --git a/textmodel.h b/textmodel.h
index 07a8f646c56760606adf5607623a3a5260dd7d46..abfe13d24f6c6ad38b2dae6a333c05d88aa076c8 100644 (file)
--- a/textmodel.h
+++ b/textmodel.h
class TextModel : public ContainerModel {
private:
- static const std::string TYPENAME;
- static const TypeProxy<TextModel> PROXY;
+ static const TypeProxy<TextModel, ContainerModel> PROXY;
public:
- TextModel(INTEGER id);
- static const std::string &getType();
- static const std::string *getSuper();
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+
+ TextModel(INTEGER id);
virtual void internalize(Reader &reader);
};
class StdTextModel : public TextModel {
private:
- static const std::string TYPENAME;
- static const TypeProxy<StdTextModel> PROXY;
+ static const TypeProxy<StdTextModel, TextModel> PROXY;
std::vector<TextPiece *> d_pieces;
public:
- StdTextModel(INTEGER id);
- static const std::string &getType();
- static const std::string *getSuper();
+ static const std::string TYPENAME;
virtual const std::string &getTypeName() const;
+
+ StdTextModel(INTEGER id);
virtual void internalize(Reader &reader);
virtual std::string toString();
diff --git a/typeregister.h b/typeregister.h
index d647b5bc00f513be88743013156bfe10809cd2ae..52a542821a93877baf7cae8f9a4dbcaa7d4d58d1 100644 (file)
--- a/typeregister.h
+++ b/typeregister.h
class Store;
class TypeProxyBase; // forward declaration
+ /**
+ * Register of Oberon/BlackBox types.
+ * Each type has a registered name, which refers to the full BlackBox type name (including any modules).
+ * It also (optionally) has a supertype (also referred to by the full BlackBox type name).
+ */
class TypeRegister {
static TypeRegister *s_instance;
TypeRegister &operator=(const TypeRegister &other); // NI
public:
+ /**
+ * Get an instance of the type register (singleton pattern).
+ */
static TypeRegister &getInstance();
+ /**
+ * Register a new type.
+ */
void add(const std::string &name, TypeProxyBase *proxy);
+
+ /**
+ * Get a type's proxy.
+ */
const TypeProxyBase *get(const std::string &name);
};
+ /**
+ * Proxy to represent a BlackBox type. Has a name and optional supertype name.
+ * Can instantiate new instances of the type.
+ */
class TypeProxyBase {
public:
+ /**
+ * Create a new TypeProxy and register it with the TypeRegister.
+ */
TypeProxyBase(const std::string &name);
+ /**
+ * @return The full BlackBox type name (including modules).
+ */
virtual const std::string &getName() const = 0;
+ /**
+ * @return The full BlackBox type name of the supertype (if applicable, otherwise a 0-pointer).
+ */
virtual const std::string *getSuper() const = 0;
+ /**
+ * @return A new instance of the type, with the given ID.
+ */
virtual Store *newInstance(INTEGER id) const = 0;
};
- template <class T> class TypeProxy : public TypeProxyBase {
+ /**
+ * Proxy for a toplevel type (no supertype).
+ * T: the class to proxy for.
+ * Requires T to have a static const std::string TYPENAME.
+ */
+ template <class T> class TopTypeProxy : public TypeProxyBase {
+ public:
+ TopTypeProxy(): TypeProxyBase(T::TYPENAME) {}
+ virtual const std::string &getName() const {
+ return T::TYPENAME;
+ }
+ virtual const std::string *getSuper() const {
+ return 0;
+ }
+ virtual Store *newInstance(INTEGER id) const {
+ return new T(id);
+ }
+ };
+
+ /**
+ * Proxy for a derived type (with supertype).
+ * T: the class to proxy for.
+ * S: the supertype.
+ * Requires T, S to have a static const std::string TYPENAME.
+ */
+ template <class T, class S> class TypeProxy : public TypeProxyBase {
public:
- TypeProxy(): TypeProxyBase(T::getType()) {}
+ TypeProxy(): TypeProxyBase(T::TYPENAME) {}
virtual const std::string &getName() const {
- return T::getType();
+ return T::TYPENAME;
}
virtual const std::string *getSuper() const {
- return T::getSuper();
+ return &S::TYPENAME;
}
virtual Store *newInstance(INTEGER id) const {
return new T(id);