From 78bdb210ad81edd0ba41a6adfc4797b1ccc62228 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 23 Jan 2015 00:40:51 +0100 Subject: Added 'createChild'-style methods to Document and Domain classes. --- src/core/model/Document.cpp | 46 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 2ae9107..61c384d 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -383,8 +383,8 @@ void DocumentEntity::addStructureNodes( } } -bool DocumentEntity::removeStructureNodeFromField( - Handle s, const std::string &fieldName) +bool DocumentEntity::removeStructureNodeFromField(Handle s, + const std::string &fieldName) { return removeStructureNodeFromField( s, getFieldDescriptorIndex(fieldName, true)); @@ -428,6 +428,29 @@ bool DocumentEntity::removeStructureNode(Handle s) return false; } +Rooted DocumentEntity::createChildStructuredEntity( + Handle descriptor, Variant attributes, + const std::string &fieldName, std::string name) +{ + return Rooted{new StructuredEntity( + subInst->getManager(), subInst, descriptor, std::move(attributes), + fieldName, std::move(name))}; +} + +Rooted DocumentEntity::createChildDocumentPrimitive( + Variant content, const std::string &fieldName) +{ + return Rooted{new DocumentPrimitive( + subInst->getManager(), subInst, std::move(content), fieldName)}; +} + +Rooted DocumentEntity::createChildAnchor(std::string name, + const std::string &fieldName) +{ + return Rooted{ + new Anchor(subInst->getManager(), std::move(name), subInst, fieldName)}; +} + /* Class StructureNode */ bool StructureNode::doValidate(Logger &logger) const @@ -611,6 +634,14 @@ bool Document::doValidate(Logger &logger) const return valid & continueValidation(annotations, logger); } +Rooted Document::createRootStructuredEntity( + Handle descriptor, Variant attributes, std::string name) +{ + return Rooted{ + new StructuredEntity(getManager(), Handle{this}, descriptor, + attributes, std::move(name))}; +} + void Document::addAnnotation(Handle a) { // only add it if we need to. @@ -635,8 +666,6 @@ void Document::addAnnotations(const std::vector> &as) } } - - bool Document::removeAnnotation(Handle a) { auto it = annotations.find(a); @@ -649,6 +678,15 @@ bool Document::removeAnnotation(Handle a) return false; } +Rooted Document::createChildAnnotation( + Handle descriptor, Handle start, + Handle end, Variant attributes, std::string name) +{ + return Rooted{ + new AnnotationEntity(getManager(), this, descriptor, start, end, + attributes, std::move(name))}; +} + bool Document::hasChild(Handle s) const { Rooted parent = s->getParent(); -- cgit v1.2.3