From a1245cf2ad80cba0a71ffb184966ee77a7e166cc Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 15 Jan 2015 14:18:07 +0100 Subject: Further simplified document buildup by doing the addition to parents of StructureNodes in the constructor and refactored Anchor as standalone class instead of AnnotationEntity child. This made some changes in the test bench necessary as well. --- test/core/model/TestDocumentBuilder.hpp | 90 ++------------------------------- 1 file changed, 3 insertions(+), 87 deletions(-) (limited to 'test/core/model/TestDocumentBuilder.hpp') diff --git a/test/core/model/TestDocumentBuilder.hpp b/test/core/model/TestDocumentBuilder.hpp index ae7b3fd..dc0479d 100644 --- a/test/core/model/TestDocumentBuilder.hpp +++ b/test/core/model/TestDocumentBuilder.hpp @@ -107,8 +107,6 @@ Rooted buildRootStructuredEntity(Handle document, Rooted root{new StructuredEntity( document->getManager(), document, descriptor.cast(), attributes, std::move(name))}; - // append it to the document. - document->setRoot(root); // and return it. return root; } @@ -162,94 +160,12 @@ Rooted buildStructuredEntity( // Then construct the StructuredEntity itself. Rooted entity{new StructuredEntity( parent->getManager(), parent, descriptor.cast(), - attributes, std::move(name))}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(entity, fieldName); + attributes, fieldName, std::move(name))}; // and return it. return entity; } -/** - * This builds a DocumentPrimitive as child of the given DocumentEntity. It - * automatically appends the newly build entity to its parent. - * - * @param logger is the current logger. - * @param parent is the parent DocumentEntity. The newly constructed - * DocumentPrimitive will automatically be appended to it. - * @param content is the primitive content of the new node in terms of a - * Struct variant. - * @param fieldName is the name of the field where the newly constructed - * StructuredEntity shall be appended. - * - * @return the newly created DocumentPrimitive or a nullptr if some - * input handle was empty. - */ -Rooted buildPrimitiveEntity( - Logger &logger, Handle parent, Variant content = {}, - const std::string &fieldName = "") -{ - // If the input handles are not set, we can not build the entity. - if (parent == nullptr) { - logger.error("The input parent handle was null!"); - return {nullptr}; - } - // Then construct the StructuredEntity itself. - Rooted entity{ - new DocumentPrimitive(parent->getManager(), parent, content)}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(entity, fieldName); - // and return it. - return entity; -} - -/** - * This builds an Anchor as child of the given DocumentEntity. It - * automatically appends the newly build Anchor to its parent. - * - * @param logger is the current logger. - * @param parent is the parent DocumentEntity. The newly constructed - * Anchor will automatically be appended to it. - * @param id is the id of this Anchor. - * @param fieldName is the name of the field where the newly constructed - * Anchor shall be appended. - * - * @return the newly created Anchor or a nullptr if some - * input handle was empty. - */ -Rooted buildAnchor(Logger &logger, - Handle parent, - std::string id, - const std::string &fieldName = "") -{ - // If the parent is not set, we can not build the anchor. - if (parent == nullptr) { - logger.error("The input parent handle was null!"); - return {nullptr}; - } - // Then construct the Anchor itself - Rooted anchor{ - new AnnotationEntity::Anchor(parent->getManager(), id, parent)}; - // append the new entity to the right field. - if (!parent->hasField(fieldName)) { - logger.error(std::string("The parent has no field of the name ") + - fieldName + "!"); - return {nullptr}; - } - parent->addStructureNode(anchor, fieldName); - // and return it. - return anchor; -} /** * This builds an AnnotationEntity as child of the given Document. It * automatically appends the newly build entity to its parent. @@ -271,8 +187,8 @@ Rooted buildAnchor(Logger &logger, */ Rooted buildAnnotationEntity( Handle document, Logger &logger, const Path &path, - Handle start, - Handle end, Variant attributes = {}, + Handle start, + Handle end, Variant attributes = {}, std::string name = "") { // If the input handles are not set, we can not build the entity. -- cgit v1.2.3