summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-20 11:41:24 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-01-20 11:41:24 +0100
commit403fbc4552822af899d85ba97ada2559eb776ea8 (patch)
treea19d3daeade79b9d11975a24d9b68189ff4cbf2c /src/core
parent90047e6e1df4f32c7c935639df122136dccb3aa1 (diff)
Further work on document validation. More of a finetuning.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/model/Document.cpp110
-rw-r--r--src/core/model/Document.hpp6
2 files changed, 75 insertions, 41 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp
index e6fe1f3..ec58141 100644
--- a/src/core/model/Document.cpp
+++ b/src/core/model/Document.cpp
@@ -360,6 +360,27 @@ void DocumentEntity::addStructureNodes(
/* Class StructureNode */
+bool StructureNode::doValidate(Logger &logger) const
+{
+ bool valid = true;
+ // check name
+ if (!getName().empty()) {
+ valid = validateName(logger);
+ }
+ // check the parent.
+ if (getParent() == nullptr) {
+ logger.error("The parent is not set!");
+ valid = false;
+ }
+ if (!getParent()->isa(RttiTypes::StructuredEntity) &&
+ !getParent()->isa(RttiTypes::AnnotationEntity) &&
+ !getParent()->isa(RttiTypes::Document)) {
+ logger.error("The parent does not have a valid type!");
+ valid = false;
+ }
+ return valid;
+}
+
StructureNode::StructureNode(Manager &mgr, std::string name,
Handle<Node> parent, const std::string &fieldName)
: Node(mgr, std::move(name), parent)
@@ -394,18 +415,22 @@ StructuredEntity::StructuredEntity(Manager &mgr, Handle<Node> parent,
bool StructuredEntity::doValidate(Logger &logger) const
{
+ // check the validity as a StructureNode and as a DocumentEntity.
+ return StructureNode::doValidate(logger) &
+ DocumentEntity::doValidate(logger);
+}
+
+/* Class Anchor */
+
+bool Anchor::doValidate(Logger &logger) const
+{
bool valid = true;
- // check if the parent is set.
- if (getParent() == nullptr) {
- logger.error("The parent is not set!");
- valid = false;
- }
// check name
- if (!getName().empty()) {
- valid = valid & validateName(logger);
+ if (getName().empty()) {
+ logger.error("An Anchor needs a name!");
+ valid = false;
}
- // check the validity as a DocumentEntity.
- return valid & DocumentEntity::doValidate(logger);
+ return valid & StructureNode::doValidate(logger);
}
/* Class AnnotationEntity */
@@ -427,6 +452,10 @@ AnnotationEntity::AnnotationEntity(Manager &mgr, Handle<Document> parent,
bool AnnotationEntity::doValidate(Logger &logger) const
{
bool valid = true;
+ // check name
+ if (!getName().empty()) {
+ valid = valid & validateName(logger);
+ }
// check if this AnnotationEntity is correctly registered at its document.
if (getParent() == nullptr) {
logger.error("The parent is not set!");
@@ -434,39 +463,38 @@ bool AnnotationEntity::doValidate(Logger &logger) const
} else if (!getParent()->isa(RttiTypes::Document)) {
logger.error("The parent is not a document!");
valid = false;
- }
- Handle<Document> doc = getParent().cast<Document>();
- bool found = false;
- for (auto &a : doc->getAnnotations()) {
- if (a == this) {
- found = true;
- break;
+ } else {
+ Handle<Document> doc = getParent().cast<Document>();
+ bool found = false;
+ for (auto &a : doc->getAnnotations()) {
+ if (a == this) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ logger.error("This annotation was not registered at the document.");
+ valid = false;
+ }
+ // check if the Anchors are part of the right document.
+ if (start == nullptr) {
+ logger.error("This annotation has no start Anchor!");
+ valid = false;
+ } else if (!doc->hasChild(start)) {
+ logger.error(
+ "This annotations start anchor was not part of the same "
+ "document!");
+ valid = false;
+ }
+ if (end == nullptr) {
+ logger.error("This annotation has no end Anchor!");
+ valid = false;
+ } else if (!doc->hasChild(end)) {
+ logger.error(
+ "This annotations end anchor was not part of the same "
+ "document!");
+ valid = false;
}
- }
- if (!found) {
- logger.error("This annotation was not registered at the document.");
- valid = false;
- }
- // check name
- if (!getName().empty()) {
- valid = valid & validateName(logger);
- }
- // check if the Anchors are part of the right document.
- if (start == nullptr) {
- logger.error("This annotation has no start Anchor!");
- valid = false;
- } else if (!doc->hasChild(start)) {
- logger.error(
- "This annotations start anchor was not part of the same document!");
- valid = false;
- }
- if (end == nullptr) {
- logger.error("This annotation has no end Anchor!");
- valid = false;
- } else if (!doc->hasChild(end)) {
- logger.error(
- "This annotations end anchor was not part of the same document!");
- valid = false;
}
// check the validity as a DocumentEntity.
return valid & DocumentEntity::doValidate(logger);
diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp
index 4147847..5d5879e 100644
--- a/src/core/model/Document.hpp
+++ b/src/core/model/Document.hpp
@@ -346,6 +346,9 @@ public:
class StructureNode : public Node {
friend DocumentEntity;
+protected:
+ bool doValidate(Logger &logger) const override;
+
public:
/**
* Constructor for a StructureNode in the StructureTree.
@@ -491,6 +494,9 @@ public:
* Please refer to the AnnotationEntity documentation for more information.
*/
class Anchor : public StructureNode {
+protected:
+ bool doValidate(Logger &logger) const override;
+
public:
/**
* Constructor for Anchor.