diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-15 20:40:25 +0200 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:19 +0200 |
commit | 8810fc675a07e0ed62bcc391bb0464bc04dd3e37 (patch) | |
tree | 16a8cace91fc65bc7d1df2802d2e456f60786c52 /src/core | |
parent | 2a5b3632fb49452adb6ecedb9c678909341ef662 (diff) |
Implement generic "inheritsFrom" method for Descriptor class
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/model/Ontology.cpp | 15 | ||||
-rw-r--r-- | src/core/model/Ontology.hpp | 21 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/core/model/Ontology.cpp b/src/core/model/Ontology.cpp index 89710d3..fa0cd1e 100644 --- a/src/core/model/Ontology.cpp +++ b/src/core/model/Ontology.cpp @@ -571,6 +571,16 @@ bool Descriptor::doValidate(Logger &logger) const return valid & continueValidationCheckDuplicates(fds, logger); } +bool Descriptor::doCheckInheritsFrom(Handle<Descriptor> c) const +{ + return false; +} + +bool Descriptor::inheritsFrom(Handle<Descriptor> c) const +{ + return (c == this) || ((c != nullptr) && (c->type() == type()) && doCheckInheritsFrom(c)); +} + NodeVector<Node> Descriptor::pathTo(Handle<StructuredClass> target, Logger &logger) const { @@ -813,6 +823,11 @@ StructuredClass::StructuredClass(Manager &mgr, std::string name, } } +bool StructuredClass::doCheckInheritsFrom(Handle<Descriptor> c) const +{ + return isSubclassOf(c.cast<StructuredClass>()); +} + bool StructuredClass::doValidate(Logger &logger) const { bool valid = true; diff --git a/src/core/model/Ontology.hpp b/src/core/model/Ontology.hpp index 014f912..ddfa468 100644 --- a/src/core/model/Ontology.hpp +++ b/src/core/model/Ontology.hpp @@ -618,6 +618,16 @@ protected: bool doValidate(Logger &logger) const override; + /** + * Called when the "inheritsFrom" function is called, and this instance and + * c are of the same type, but not the same instance. Default implementation + * return false. + * + * @param c is the descriptor that should be checked for inheritance. + * @return true if this instance inherits from c. + */ + virtual bool doCheckInheritsFrom(Handle<Descriptor> c) const; + public: Descriptor(Manager &mgr, std::string name, Handle<Ontology> ontology) : Node(mgr, std::move(name), ontology), @@ -627,6 +637,16 @@ public: } /** + * Returns true if this class is a subclass of the given class or the given + * class itself. + * + * @param c is the class that should be checked for inheriting from this + * class. + * @return true if c either is this class or c inherits from this class. + */ + bool inheritsFrom(Handle<Descriptor> c) const; + + /** * Returns a reference to the StructType that specifies the attribute keys * as well as value ontologies for this Descriptor. * @@ -1042,6 +1062,7 @@ private: protected: bool doValidate(Logger &logger) const override; + bool doCheckInheritsFrom(Handle<Descriptor> c) const override; public: /** |