diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-16 12:31:06 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-16 12:31:06 +0100 |
commit | 8cf24170a4998e316c1b9c9bfd2b56e266c544cd (patch) | |
tree | f795906bafc9c904fed92c5c6c9942e4d3285c36 | |
parent | 7bdaa89ccef864d36f1e1adce535179d9e5fadce (diff) |
renamed isa to superclass in Domain::Descriptor and id some cosmetic changes.
-rw-r--r-- | src/core/model/Document.cpp | 6 | ||||
-rw-r--r-- | src/core/model/Domain.cpp | 54 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 15 |
3 files changed, 28 insertions, 47 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 299b427..fb39384 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -95,11 +95,11 @@ StructureNode::StructureNode(Manager &mgr, std::string name, Handle<Node> parent, const std::string &fieldName) : Node(mgr, std::move(name), parent) { - if(parent->isa(RttiTypes::StructuredEntity)){ + if (parent->isa(RttiTypes::StructuredEntity)) { parent.cast<StructuredEntity>()->addStructureNode(this, fieldName); - } else if(parent->isa(RttiTypes::AnnotationEntity)){ + } else if (parent->isa(RttiTypes::AnnotationEntity)) { parent.cast<AnnotationEntity>()->addStructureNode(this, fieldName); - } else{ + } else { throw OusiaException("The proposed parent was no DocumentEntity!"); } } diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index f1b91cc..b4fea3c 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -28,8 +28,7 @@ namespace model { template <class T> static void checkUniqueName(Handle<Node> parent, NodeVector<T> vec, - Handle<T> child, - const std::string &parentClassName, + Handle<T> child, const std::string &parentClassName, const std::string &childClassName) { std::set<std::string> childNames; @@ -96,31 +95,15 @@ std::vector<Rooted<Node>> Descriptor::pathTo( return path; } -static bool pathEquals(const Descriptor &a, const Descriptor &b) -{ - // We assume that two Descriptors are equal if their names and domain names - // are equal. - if (a.getName() != b.getName()) { - return false; - } - Handle<Domain> aDom = a.getParent().cast<Domain>(); - Handle<Domain> bDom = b.getParent().cast<Domain>(); - return aDom->getName() == bDom->getName(); -} - bool Descriptor::continuePath(Handle<StructuredClass> target, std::vector<Rooted<Node>> ¤tPath, std::set<std::string> ignoredFields, bool exploreSuperclass, bool exploreSubclasses) const { - // TODO: REMOVE - std::string targetName = target->getName(); - std::string thisName = getName(); - std::string currentPathName; - for (auto &n : currentPath) { - currentPathName += "."; - currentPathName += n->getName(); + // check if we are at the target already + if (this == target) { + return true; } // a variable to determine if we already found a solution bool found = false; @@ -133,7 +116,8 @@ bool Descriptor::continuePath(Handle<StructuredClass> target, continue; } for (auto &c : fd->getChildren()) { - if (pathEquals(*c, *target)) { + // check if a child is the target node. + if (c == target) { // if we have made the connection, stop the search. currentPath.push_back(fd); return true; @@ -161,11 +145,11 @@ bool Descriptor::continuePath(Handle<StructuredClass> target, * if this is a StructuredClass, we can also use the super class * (at least for fields that are not overridden) */ - if (exploreSuperclass && !tis->getIsA().isNull()) { + if (exploreSuperclass && tis->getSuperclass() != nullptr) { // copy the path. std::vector<Rooted<Node>> cPath = currentPath; - if (tis->getIsA()->continuePath(target, cPath, ignoredFields, true, - false) && + if (tis->getSuperclass()->continuePath(target, cPath, ignoredFields, + true, false) && (!found || optimum.size() > cPath.size())) { // look if this path is better than the current optimum. optimum = std::move(cPath); @@ -203,13 +187,11 @@ void Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd) * constructor will add the newly constructed FieldDescriptor to this * Descriptor automatically. */ - new FieldDescriptor(getManager(), this, - fd->getPrimitiveType(), - fd->getName(), fd->optional); + new FieldDescriptor(getManager(), this, fd->getPrimitiveType(), + fd->getName(), fd->optional); } else { - new FieldDescriptor(getManager(), this, - fd->getFieldType(), - fd->getName(), fd->optional); + new FieldDescriptor(getManager(), this, fd->getFieldType(), + fd->getName(), fd->optional); } } @@ -219,17 +201,17 @@ StructuredClass::StructuredClass(Manager &mgr, std::string name, Handle<Domain> domain, const Cardinality &cardinality, Handle<StructType> attributesDescriptor, - Handle<StructuredClass> isa, bool transparent, - bool root) + Handle<StructuredClass> superclass, + bool transparent, bool root) : Descriptor(mgr, std::move(name), domain, attributesDescriptor), cardinality(cardinality), - isa(acquire(isa)), + superclass(acquire(superclass)), subclasses(this), transparent(transparent), root(root) { - if (!isa.isNull()) { - isa->subclasses.push_back(this); + if (superclass != nullptr) { + superclass->subclasses.push_back(this); } if (!domain.isNull()) { domain->addStructuredClass(this); diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 791d563..8bc21e9 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -546,7 +546,7 @@ typedef RangeSet<size_t> Cardinality; class StructuredClass : public Descriptor { private: const Cardinality cardinality; - Owned<StructuredClass> isa; + Owned<StructuredClass> superclass; NodeVector<StructuredClass> subclasses; public: @@ -570,7 +570,7 @@ public: * @param attributesDescriptor is a StructType that specifies the attribute * keys as well as value domains for this * Descriptor. - * @param isa references a parent StructuredClass. Please + * @param superclass references a parent StructuredClass. Please * look for more information on inheritance in * the class documentation above. The default is * a null reference, meaning no super class. @@ -585,7 +585,7 @@ public: const Cardinality &cardinality, Handle<StructType> attributesDescriptor = nullptr, // TODO: What would be a wise default value for isa? - Handle<StructuredClass> isa = nullptr, + Handle<StructuredClass> superclass = nullptr, bool transparent = false, bool root = false); /** @@ -596,13 +596,12 @@ public: const Cardinality &getCardinality() const { return cardinality; } /** - * Returns the parent of this StructuredClass in the class inheritance - * hierarchy (!). This is not the same as the parents in the Structure Tree! + * Returns the superclass of this StructuredClass. This is not the same as + * the parents in the Structure Tree! * - * @return the parent of this StructuredClass in the class inheritance - * hierarchy (!). + * @return the superclass of this StructuredClass. */ - Rooted<StructuredClass> getIsA() const { return isa; } + Rooted<StructuredClass> getSuperclass() const { return superclass; } /** * Returns the StructuredClasses that are subclasses of this class. This |