diff options
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Document.cpp | 34 | ||||
-rw-r--r-- | src/core/model/Domain.cpp | 10 | ||||
-rw-r--r-- | src/core/model/Node.cpp | 93 | ||||
-rw-r--r-- | src/core/model/Node.hpp | 4 | ||||
-rw-r--r-- | src/core/model/Project.cpp | 2 | ||||
-rw-r--r-- | src/core/model/RootNode.cpp | 6 | ||||
-rw-r--r-- | src/core/model/Typesystem.cpp | 6 |
7 files changed, 103 insertions, 52 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index b981c26..de73bb8 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -77,7 +77,7 @@ int DocumentEntity::getFieldDescriptorIndex( void DocumentEntity::invalidateSubInstance() { - if (subInst->isa(RttiTypes::StructuredEntity)) { + if (subInst->isa(&RttiTypes::StructuredEntity)) { subInst.cast<StructuredEntity>()->invalidate(); } else { subInst.cast<AnnotationEntity>()->invalidate(); @@ -107,7 +107,7 @@ void DocumentEntity::setDescriptor(Handle<Descriptor> d) descriptor = subInst->acquire(d); // get the effective field descriptors in the descriptor. NodeVector<FieldDescriptor> fieldDescs; - if (descriptor->isa(RttiTypes::StructuredClass)) { + if (descriptor->isa(&RttiTypes::StructuredClass)) { fieldDescs = descriptor.cast<StructuredClass>()->getEffectiveFieldDescriptors(); } else { @@ -149,7 +149,7 @@ bool DocumentEntity::doValidate(Logger &logger) const * overridden in the subclasses. */ NodeVector<FieldDescriptor> fieldDescs; - if (descriptor->isa(RttiTypes::StructuredClass)) { + if (descriptor->isa(&RttiTypes::StructuredClass)) { fieldDescs = descriptor.cast<StructuredClass>()->getEffectiveFieldDescriptors(); } else { @@ -181,7 +181,7 @@ bool DocumentEntity::doValidate(Logger &logger) const continue; } // if we are here we know that exactly one child exists. - if (!fields[f][0]->isa(RttiTypes::DocumentPrimitive)) { + if (!fields[f][0]->isa(&RttiTypes::DocumentPrimitive)) { logger.error(std::string("Primitive Field \"") + fieldDescs[f]->getName() + "\" has non primitive content!", @@ -243,11 +243,11 @@ bool DocumentEntity::doValidate(Logger &logger) const *child); valid = false; } - if (child->isa(RttiTypes::Anchor)) { + if (child->isa(&RttiTypes::Anchor)) { // Anchors are uninteresting and can be ignored. continue; } - if (child->isa(RttiTypes::DocumentPrimitive)) { + if (child->isa(&RttiTypes::DocumentPrimitive)) { logger.error(std::string("Non-primitive Field \"") + fieldDescs[f]->getName() + "\" had primitive content!", @@ -344,7 +344,7 @@ void DocumentEntity::addStructureNode(Handle<StructureNode> s, const int &i) if (par != subInst) { // if a previous parent existed, remove the StructureNode from it if (par != nullptr) { - if (par->isa(RttiTypes::StructuredEntity)) { + if (par->isa(&RttiTypes::StructuredEntity)) { par.cast<StructuredEntity>()->removeStructureNode(s); } else { par.cast<AnnotationEntity>()->removeStructureNode(s); @@ -464,9 +464,9 @@ bool StructureNode::doValidate(Logger &logger) const logger.error("The parent is not set!", *this); valid = false; } - if (!getParent()->isa(RttiTypes::StructuredEntity) && - !getParent()->isa(RttiTypes::AnnotationEntity) && - !getParent()->isa(RttiTypes::Document)) { + if (!getParent()->isa(&RttiTypes::StructuredEntity) && + !getParent()->isa(&RttiTypes::AnnotationEntity) && + !getParent()->isa(&RttiTypes::Document)) { logger.error("The parent does not have a valid type!", *this); valid = false; } @@ -477,9 +477,9 @@ 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 { throw OusiaException("The proposed parent was no DocumentEntity!"); @@ -552,7 +552,7 @@ bool AnnotationEntity::doValidate(Logger &logger) const if (getParent() == nullptr) { logger.error("The parent is not set!", *this); valid = false; - } else if (!getParent()->isa(RttiTypes::Document)) { + } else if (!getParent()->isa(&RttiTypes::Document)) { logger.error("The parent is not a document!", *this); valid = false; } else { @@ -640,7 +640,7 @@ bool Document::doValidate(Logger &logger) const void Document::doReference(Handle<Node> node) { - if (node->isa(RttiTypes::Domain)) { + if (node->isa(&RttiTypes::Domain)) { referenceDomain(node.cast<Domain>()); } } @@ -706,12 +706,12 @@ Rooted<AnnotationEntity> Document::createChildAnnotation( bool Document::hasChild(Handle<StructureNode> s) const { Rooted<Managed> parent = s->getParent(); - if (parent->isa(RttiTypes::StructureNode)) { + if (parent->isa(&RttiTypes::StructureNode)) { return hasChild(parent.cast<StructureNode>()); - } else if (parent->isa(RttiTypes::AnnotationEntity)) { + } else if (parent->isa(&RttiTypes::AnnotationEntity)) { Handle<AnnotationEntity> a = parent.cast<AnnotationEntity>(); return this == a->getParent(); - } else if (parent->isa(RttiTypes::Document)) { + } else if (parent->isa(&RttiTypes::Document)) { return this == parent; } return false; diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 7d5a76e..55f05b3 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -61,7 +61,7 @@ bool FieldDescriptor::doValidate(Logger &logger) const if (getParent() == nullptr) { logger.error("This field has no parent!", *this); valid = false; - } else if (!getParent()->isa(RttiTypes::Descriptor)) { + } else if (!getParent()->isa(&RttiTypes::Descriptor)) { logger.error("The parent of this field is not a descriptor!", *this); valid = false; } @@ -142,7 +142,7 @@ bool Descriptor::doValidate(Logger &logger) const if (getParent() == nullptr) { logger.error("This Descriptor has no parent!", *this); valid = false; - } else if (!getParent()->isa(RttiTypes::Domain)) { + } else if (!getParent()->isa(&RttiTypes::Domain)) { logger.error("The parent of this Descriptor is not a Domain!", *this); valid = false; } @@ -180,7 +180,7 @@ bool Descriptor::continuePath(Handle<StructuredClass> target, // use recursive depth-first search from the top to reach the given child // get the list of effective FieldDescriptors. NodeVector<FieldDescriptor> fields; - if (isa(RttiTypes::StructuredClass)) { + if (isa(&RttiTypes::StructuredClass)) { const StructuredClass *tis = static_cast<const StructuredClass *>(this); fields = tis->getEffectiveFieldDescriptors(); } else { @@ -212,7 +212,7 @@ bool Descriptor::continuePath(Handle<StructuredClass> target, } } - if (isa(RttiTypes::StructuredClass)) { + if (isa(&RttiTypes::StructuredClass)) { const StructuredClass *tis = static_cast<const StructuredClass *>(this); // if this is a StructuredClass we also can call the subclasses. for (auto &c : tis->getSubclasses()) { @@ -489,7 +489,7 @@ bool Domain::doValidate(Logger &logger) const void Domain::doReference(Handle<Node> node) { - if (node->isa(RttiTypes::Domain)) { + if (node->isa(&RttiTypes::Domain)) { referenceTypesystem(node.cast<Typesystem>()); } } diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index 65f093f..39ee2e4 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -62,7 +62,7 @@ public: /** * Type of the node that was requested for resolution. */ - const Rtti &type; + const Rtti *type; /** * Actual path (name pattern) that was requested for resolution. @@ -86,7 +86,7 @@ public: * @param path is a const reference to the actual path that should be * resolved. */ - SharedResolutionState(const Rtti &type, + SharedResolutionState(const Rtti *type, const std::vector<std::string> &path) : type(type), path(path) { @@ -182,35 +182,86 @@ public: /** * Returns true if the given type matches the type given in the query. * + * @param type is the type that should be checked. * @return true if the type matches, false otherwise. */ - bool typeMatches(const Rtti &type) { return type.isa(shared.type); } + bool typeMatches(const Rtti *type) { return type->isa(shared.type); } - bool canContainType(const Rtti &type) + /** + * Returns true if the given type can contain the node that is currently + * being resolved. + * + * @param type is the type that should be checked. + * @return true if the given type can contain the node that is currently + * begin resolved, false otherwise. + */ + bool canContainType(const Rtti *type) + { + return type->composedOf(shared.type); + } + + /** + * Returns true if the resolution process is still allowed to follow + * references. This is only the case if we are at the beginning of the + * resolution process and have not entered another start tree. + * + * @return true if references can still be followed, false if only composita + * may be examined. + */ + bool canFollowReferences() { - return type.composedOf(shared.type); + return idx == 0 && inStartTree && !foundCompositum; } + /** + * Returns true if we can still descend into new composita. This is only + * the case if we have not yet descended into another compositum beforehand. + * + * @return true if composita can be followed, false otherwise. + */ + bool canFollowComposita() { return idx == 0; } + + /** + * Returns the number of matching nodes that were found until now. + * + * @return the number of matching nodes. + */ + size_t resultCount() { return shared.result.size(); } + + /** + * Returns the name that is currently being search for (at the current path + * position). + * + * @return the current name. + */ const std::string ¤tName() { return shared.path[idx]; } + /** + * Returns a new ResolutionState instance where the path position is moved + * on by one element. + * + * @return a copy of the current ResolutionState instance with the path + * position being incremented by one. + */ ResolutionState advance() { return ResolutionState{shared, resolutionRoot, idx + 1, false}; } + /** + * Forks current ResolutionState instance with the resolution starting at + * the given node. This function is used when a reference is being followed. + * + * @param newResolutionRoot is the root node of the new subtree in which + * resolution takes place. + * @return a copy of this ResolutionState instance with the resolution root + * begin set to the new root instance and the path position being set to + * zero. + */ ResolutionState fork(Node *newResolutionRoot) { return ResolutionState{shared, newResolutionRoot, 0, false}; } - - bool canFollowReferences() - { - return idx == 0 && inStartTree && !foundCompositum; - } - - bool canFollowComposita() { return idx == 0; } - - size_t resultCount() { return shared.result.size(); } }; /* Class ResolutionResult */ @@ -329,7 +380,7 @@ bool Node::continueResolveReference(Handle<Node> h, ResolutionState &state) } std::vector<ResolutionResult> Node::resolve( - const Rtti &type, const std::vector<std::string> &path) + const Rtti *type, const std::vector<std::string> &path) { // Create the state variables SharedResolutionState sharedState(type, path); @@ -344,7 +395,7 @@ std::vector<ResolutionResult> Node::resolve( return sharedState.result; } -std::vector<ResolutionResult> Node::resolve(const Rtti &type, +std::vector<ResolutionResult> Node::resolve(const Rtti *type, const std::string &name) { // Place the name in a vector and call the corresponding resolve function @@ -359,7 +410,7 @@ bool Node::checkDuplicate(Handle<Node> elem, if (!names.emplace(name).second) { logger.error(std::string("Element with name \"") + name + std::string("\" defined multiple times in parent ") + - type().name + std::string(" \"") + + type()->name + std::string(" \"") + Utils::join(path(), ".") + std::string("\""), *elem); return false; @@ -398,7 +449,7 @@ bool Node::doValidate(Logger &logger) const { return true; } bool Node::validateName(Logger &logger) const { if (!Utils::isIdentifier(name)) { - logger.error(type().name + std::string(" name \"") + name + + logger.error(type()->name + std::string(" name \"") + name + std::string("\" is not a valid identifier"), this); return false; @@ -421,7 +472,7 @@ bool Node::validateIsAcyclic(const std::string &name, for (size_t i = 0; i < path.size(); i++) { auto node = path[i]; const std::string &name = node->getName(); - const std::string &typeName = node->type().name; + const std::string &typeName = node->type()->name; const std::string suffix = i == path.size() - 1 ? std::string{" (this node closes the cycle):"} @@ -517,14 +568,14 @@ void Node::setParent(Handle<Node> p) namespace RttiTypes { const Rtti Node = RttiBuilder<ousia::Node>("Node") - .property("name", {RttiTypes::String, + .property("name", {&RttiTypes::String, {[](const ousia::Node *obj) { return Variant::fromString(obj->getName()); }}, {[](const Variant &value, ousia::Node *obj) { obj->setName(value.asString()); }}}) - .property("parent", {Node, + .property("parent", {&Node, {[](const ousia::Node *obj) { return Variant::fromObject(obj->getParent()); }}}); diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 61bf418..fe8db16 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -545,7 +545,7 @@ public: * @return a vector containing ResolutionResult structures which describe * the resolved elements. */ - std::vector<ResolutionResult> resolve(const Rtti &type, + std::vector<ResolutionResult> resolve(const Rtti *type, const std::vector<std::string> &path); /** @@ -557,7 +557,7 @@ public: * @return a vector containing ResolutionResult structures which describe * the resolved elements. */ - std::vector<ResolutionResult> resolve(const Rtti &type, + std::vector<ResolutionResult> resolve(const Rtti *type, const std::string &name); /** diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp index 31530f3..f7dab8a 100644 --- a/src/core/model/Project.cpp +++ b/src/core/model/Project.cpp @@ -42,7 +42,7 @@ void Project::doResolve(ResolutionState &state){ } void Project::doReference(Handle<Node> node) { - if (node->isa(RttiTypes::Document)) { + if (node->isa(&RttiTypes::Document)) { referenceDocument(node.cast<Document>()); } } diff --git a/src/core/model/RootNode.cpp b/src/core/model/RootNode.cpp index 821c50c..642ec14 100644 --- a/src/core/model/RootNode.cpp +++ b/src/core/model/RootNode.cpp @@ -24,10 +24,10 @@ namespace ousia { void RootNode::reference(Handle<Node> node) { - if (!node->type().isOneOf(getReferenceTypes())) { + if (!node->type()->isOneOf(getReferenceTypes())) { throw OusiaException( - std::string("Node with type ") + node->type().name + - std::string(" cannot be referenced in a ") + type().name); + std::string("Node with type ") + node->type()->name + + std::string(" cannot be referenced in a ") + type()->name); } doReference(node); } diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp index bd5e615..fb99f87 100644 --- a/src/core/model/Typesystem.cpp +++ b/src/core/model/Typesystem.cpp @@ -648,13 +648,13 @@ bool ArrayType::doCheckIsa(Handle<const Type> type) const Handle<const Type> t2{type}; // Unwrap the array types until only the innermost type is left - while (t1->isa(RttiTypes::ArrayType) && t2->isa(RttiTypes::ArrayType)) { + while (t1->isa(&RttiTypes::ArrayType) && t2->isa(&RttiTypes::ArrayType)) { t1 = t1.cast<const ArrayType>()->innerType; t2 = t2.cast<const ArrayType>()->innerType; } // Abort if only one of the to types is an array type - if (t1->isa(RttiTypes::ArrayType) || t2->isa(RttiTypes::ArrayType)) { + if (t1->isa(&RttiTypes::ArrayType) || t2->isa(&RttiTypes::ArrayType)) { return false; } @@ -725,7 +725,7 @@ bool Typesystem::doValidate(Logger &logger) const void Typesystem::doReference(Handle<Node> node) { - if (node->isa(RttiTypes::Typesystem)) { + if (node->isa(&RttiTypes::Typesystem)) { referenceTypesystem(node.cast<Typesystem>()); } } |