diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-18 12:58:55 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-18 12:58:55 +0100 |
commit | 4e590891e9723c42858165a96c96a9f19d4e4c94 (patch) | |
tree | 7d7b2cbf22c111daff899a32296d001511b11519 /src | |
parent | 40428e90ae8b1a5d1c769b6eb2fec9a53b7173bc (diff) |
added Document validation function and finished implementation of AnnotationEntity validation function. Tests still have to be made, though.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/model/Document.cpp | 53 | ||||
-rw-r--r-- | src/core/model/Document.hpp | 16 |
2 files changed, 63 insertions, 6 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 0de750f..0b0a42a 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -92,7 +92,7 @@ int DocumentEntity::getFieldDescriptorIndex( } } -bool DocumentEntity::validate(Logger &logger) const +bool DocumentEntity::doValidate(Logger &logger) const { // TODO: check the validated form of Attributes // iterate over every field @@ -246,7 +246,7 @@ bool StructuredEntity::doValidate(Logger &logger) const return false; } // check the validity as a DocumentEntity. - return DocumentEntity::validate(logger); + return DocumentEntity::doValidate(logger); } /* Class AnnotationEntity */ @@ -281,12 +281,17 @@ bool AnnotationEntity::doValidate(Logger &logger) const logger.error("This annotation was not registered at the document."); return false; } - + // check if the Anchors are part of the right document. + if (!doc->hasChild(start)) { + return false; + } + if (!doc->hasChild(end)) { + return false; + } // check the validity as a DocumentEntity. - if (!DocumentEntity::validate(logger)) { + if (!DocumentEntity::doValidate(logger)) { return false; } - // TODO: then check if the anchors are in the correct document. return true; } @@ -300,6 +305,44 @@ void Document::continueResolve(ResolutionState &state) } continueResolveReferences(domains, state); } + +bool Document::doValidate(Logger &logger) const +{ + if (root != nullptr) { + // check if the root is allowed to be a root. + if (!root->getDescriptor().cast<StructuredClass>()->root) { + logger.error(std::string("A node of type ") + + root->getDescriptor()->getName() + + " is not allowed to be the Document root!"); + return false; + } + // then call validate on the root + if (!root->validate(logger)) { + return false; + } + } + // call validate on the AnnotationEntities + for (auto &a : annotations) { + if (!a->validate(logger)) { + return false; + } + } + return true; +} + +bool Document::hasChild(Handle<StructureNode> s) const +{ + Rooted<Managed> parent = s->getParent(); + if (parent->isa(RttiTypes::StructureNode)) { + return hasChild(parent.cast<StructureNode>()); + } else if (parent->isa(RttiTypes::AnnotationEntity)) { + Handle<AnnotationEntity> a = parent.cast<AnnotationEntity>(); + return this == a->getParent(); + } else if (parent->isa(RttiTypes::Document)) { + return this == parent; + } + return false; +} } /* Type registrations */ diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 5af3ce2..18ec3d5 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -161,7 +161,7 @@ protected: fields[getFieldDescriptorIndex(fieldName, true)].push_back(s); } - bool validate(Logger &logger) const; + bool doValidate(Logger &logger) const; public: /** @@ -569,6 +569,9 @@ private: void continueResolve(ResolutionState &state) override; +protected: + bool doValidate(Logger &logger) const override; + public: Document(Manager &mgr, std::string name) // TODO: Can a document have a parent? @@ -622,6 +625,17 @@ public: { domains.insert(domains.end(), d.begin(), d.end()); } + + /** + * Returns true if and only if the given StructureNode is part of this + * document, meaning that there is a path of parent references in the + * Structure Tree leading from the given StructureNode to this Document. + * + * @param s is some StructureNode. + * @return true if and only if the given StructureNode is part of this + * document. + */ + bool hasChild(Handle<StructureNode> s) const; }; } |