diff options
| -rw-r--r-- | src/core/model/Document.cpp | 41 | ||||
| -rw-r--r-- | src/core/model/Document.hpp | 287 | ||||
| -rw-r--r-- | src/plugins/html/DemoOutput.cpp | 3 | ||||
| -rw-r--r-- | test/core/model/TestAdvanced.hpp | 28 | ||||
| -rw-r--r-- | test/core/model/TestDocument.hpp | 11 | ||||
| -rw-r--r-- | test/core/model/TestDocumentBuilder.hpp | 90 | ||||
| -rw-r--r-- | test/plugins/html/DemoOutputTest.cpp | 22 | 
7 files changed, 239 insertions, 243 deletions
| diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index eca24e7..299b427 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -89,11 +89,38 @@ int DocumentEntity::getFieldDescriptorIndex(  	}  } +/* Class StructureNode */ + +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)){ +		parent.cast<StructuredEntity>()->addStructureNode(this, fieldName); +	} else if(parent->isa(RttiTypes::AnnotationEntity)){ +		parent.cast<AnnotationEntity>()->addStructureNode(this, fieldName); +	} else{ +		throw OusiaException("The proposed parent was no DocumentEntity!"); +	} +} + +/* Class StructuredEntity */ + +StructuredEntity::StructuredEntity(Manager &mgr, Handle<Document> doc, +                                   Handle<StructuredClass> descriptor, +                                   Variant attributes, std::string name) +    : StructureNode(mgr, std::move(name), doc), +      DocumentEntity(this, descriptor, std::move(attributes)) +{ +	doc->setRoot(this); +} +  /* Class AnnotationEntity */  AnnotationEntity::AnnotationEntity(Manager &mgr, Handle<Document> parent, -                 Handle<AnnotationClass> descriptor, Handle<Anchor> start, -                 Handle<Anchor> end, Variant attributes, std::string name) +                                   Handle<AnnotationClass> descriptor, +                                   Handle<Anchor> start, Handle<Anchor> end, +                                   Variant attributes, std::string name)      : Node(mgr, std::move(name), parent),        DocumentEntity(this, descriptor, attributes),        start(acquire(start)), @@ -121,15 +148,15 @@ const Rtti<model::Document> Document =          {&AnnotationEntity, &StructuredEntity});  const Rtti<model::StructureNode> StructureNode =      RttiBuilder("StructureNode").parent(&Node); -const Rtti<model::AnnotationEntity> AnnotationEntity = -    RttiBuilder("AnnotationEntity").parent(&Node).composedOf(&StructureNode);  const Rtti<model::StructuredEntity> StructuredEntity =      RttiBuilder("StructuredEntity").parent(&StructureNode).composedOf( -        {&StructureNode}); +        {&StructuredEntity, &DocumentPrimitive, &Anchor});  const Rtti<model::DocumentPrimitive> DocumentPrimitive =      RttiBuilder("DocumentPrimitive").parent(&StructureNode); -const Rtti<model::AnnotationEntity::Anchor> Anchor = -    RttiBuilder("Anchor").parent(&StructureNode); +const Rtti<model::Anchor> Anchor = RttiBuilder("Anchor").parent(&StructureNode); +const Rtti<model::AnnotationEntity> AnnotationEntity = +    RttiBuilder("AnnotationEntity").parent(&Node).composedOf( +        {&StructuredEntity, &DocumentPrimitive, &Anchor});  }  } diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 9a8719c..be8b5c8 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -139,6 +139,8 @@ class StructureNode;   *   */  class DocumentEntity { +	friend StructureNode; +  private:  	Owned<Descriptor> descriptor;  	const Variant attributes; @@ -150,6 +152,13 @@ private:  	int getFieldDescriptorIndex(Handle<FieldDescriptor> fieldDescriptor,  	                            bool enforce) const; +protected: +	void addStructureNode(Handle<StructureNode> s, +	                      const std::string &fieldName = "") +	{ +		fields[getFieldDescriptorIndex(fieldName, true)].push_back(s); +	} +  public:  	/**  	 * The constructor for a DocumentEntity. Node that this does not inherit @@ -169,7 +178,6 @@ public:  	    : descriptor(owner->acquire(descriptor)),  	      attributes(std::move(attributes))  	{ -		// TODO: Validation at construction time?  		// insert empty vectors for each field.  		if (!descriptor.isNull()) {  			for (size_t f = 0; f < descriptor->getFieldDescriptors().size(); @@ -247,79 +255,85 @@ public:  	{  		return fields[getFieldDescriptorIndex(fieldDescriptor, true)];  	} -	/** -	 * This adds a StructureNode to the field with the given name. If an -	 * empty name is given it is assumed that the 'default' FieldDescriptor is -	 * referenced, where 'default' means either: -	 * 1.) The only TREE typed FieldDescriptor (if present) or -	 * 2.) the only FieldDescriptor (if only one is specified). -	 * -	 * If the name is unknown an exception is thrown. -	 * -	 * @param s         is the StructureNode that shall be added. -	 * @param fieldName is the name of a field as specified in the -	 *                  FieldDescriptor in the Domain description. -	 */ -	void addStructureNode(Handle<StructureNode> s, -	                         const std::string &fieldName = "") -	{ -		fields[getFieldDescriptorIndex(fieldName, true)].push_back(s); -	} -	/** -	 * This adds multiple StructureNodes to the field with the given name. -	 * If an empty name is given it is assumed that the 'default' -	 * FieldDescriptor is referenced, where 'default' means either: -	 * 1.) The only TREE typed FieldDescriptor (if present) or -	 * 2.) the only FieldDescriptor (if only one is specified). -	 * -	 * If the name is unknown an exception is thrown. -	 * -	 * @param ss        are the StructureNodes that shall be added. -	 * @param fieldName is the name of a field as specified in the -	 *                  FieldDescriptor in the Domain description. -	 */ -	void addStructureNodes(const std::vector<Handle<StructureNode>> &ss, -	                           const std::string &fieldName = "") -	{ -		NodeVector<StructureNode> &field = -		    fields[getFieldDescriptorIndex(fieldName, true)]; -		field.insert(field.end(), ss.begin(), ss.end()); -	} - -	/** -	 * This adds a StructureNode to the field with the given FieldDescriptor. -	 * -	 * If the FieldDescriptor does not belong to the Descriptor of this node -	 * an exception is thrown. -	 * -	 * @param s               is the StructureNode that shall be added. -	 * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for -	 *                        this DocumentEntity. -	 */ -	void addStructureNode(Handle<StructureNode> s, -	                         Handle<FieldDescriptor> fieldDescriptor) -	{ -		fields[getFieldDescriptorIndex(fieldDescriptor, true)].push_back(s); -	} -	/** -	 * This adds multiple StructureNodes to the field with the given -	 * FieldDescriptor. -	 * -	 * If the FieldDescriptor does not belong to the Descriptor of this node -	 * an exception is thrown. -	 * -	 * @param ss              are the StructureNodes that shall be added. -	 * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for -	 *                        this DocumentEntity. -	 */ -	void addStructureNodes(const std::vector<Handle<StructureNode>> &ss, -	                           Handle<FieldDescriptor> fieldDescriptor) -	{ -		NodeVector<StructureNode> &field = -		    fields[getFieldDescriptorIndex(fieldDescriptor, true)]; -		field.insert(field.end(), ss.begin(), ss.end()); -	} +	// TODO: Change this to move methods. +	//	/** +	//	 * This adds a StructureNode to the field with the given name. If an +	//	 * empty name is given it is assumed that the 'default' FieldDescriptor +	// is +	//	 * referenced, where 'default' means either: +	//	 * 1.) The only TREE typed FieldDescriptor (if present) or +	//	 * 2.) the only FieldDescriptor (if only one is specified). +	//	 * +	//	 * If the name is unknown an exception is thrown. +	//	 * +	//	 * @param s         is the StructureNode that shall be added. +	//	 * @param fieldName is the name of a field as specified in the +	//	 *                  FieldDescriptor in the Domain description. +	//	 */ +	//	void addStructureNode(Handle<StructureNode> s, +	//	                         const std::string &fieldName = "") +	//	{ +	//		fields[getFieldDescriptorIndex(fieldName, true)].push_back(s); +	//	} +	//	/** +	//	 * This adds multiple StructureNodes to the field with the given name. +	//	 * If an empty name is given it is assumed that the 'default' +	//	 * FieldDescriptor is referenced, where 'default' means either: +	//	 * 1.) The only TREE typed FieldDescriptor (if present) or +	//	 * 2.) the only FieldDescriptor (if only one is specified). +	//	 * +	//	 * If the name is unknown an exception is thrown. +	//	 * +	//	 * @param ss        are the StructureNodes that shall be added. +	//	 * @param fieldName is the name of a field as specified in the +	//	 *                  FieldDescriptor in the Domain description. +	//	 */ +	//	void addStructureNodes(const std::vector<Handle<StructureNode>> &ss, +	//	                           const std::string &fieldName = "") +	//	{ +	//		NodeVector<StructureNode> &field = +	//		    fields[getFieldDescriptorIndex(fieldName, true)]; +	//		field.insert(field.end(), ss.begin(), ss.end()); +	//	} + +	//	/** +	//	 * This adds a StructureNode to the field with the given +	// FieldDescriptor. +	//	 * +	//	 * If the FieldDescriptor does not belong to the Descriptor of this node +	//	 * an exception is thrown. +	//	 * +	//	 * @param s               is the StructureNode that shall be added. +	//	 * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor +	// for +	//	 *                        this DocumentEntity. +	//	 */ +	//	void addStructureNode(Handle<StructureNode> s, +	//	                         Handle<FieldDescriptor> fieldDescriptor) +	//	{ +	//		fields[getFieldDescriptorIndex(fieldDescriptor, true)].push_back(s); +	//	} + +	//	/** +	//	 * This adds multiple StructureNodes to the field with the given +	//	 * FieldDescriptor. +	//	 * +	//	 * If the FieldDescriptor does not belong to the Descriptor of this node +	//	 * an exception is thrown. +	//	 * +	//	 * @param ss              are the StructureNodes that shall be added. +	//	 * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor +	// for +	//	 *                        this DocumentEntity. +	//	 */ +	//	void addStructureNodes(const std::vector<Handle<StructureNode>> &ss, +	//	                           Handle<FieldDescriptor> fieldDescriptor) +	//	{ +	//		NodeVector<StructureNode> &field = +	//		    fields[getFieldDescriptorIndex(fieldDescriptor, true)]; +	//		field.insert(field.end(), ss.begin(), ss.end()); +	//	}  };  /** @@ -328,10 +342,19 @@ public:   */  class StructureNode : public Node {  public: -	StructureNode(Manager &mgr, std::string name, Handle<Node> parent) -	    : Node(mgr, std::move(name), parent) +	/** +	 * Constructor for a StructureNode at the root. +	 */ +	StructureNode(Manager &mgr, std::string name, Handle<Document> doc) +	    : Node(mgr, std::move(name), doc)  	{  	} + +	/** +	 * Constructor for a StructureNode in the StructureTree. +	 */ +	StructureNode(Manager &mgr, std::string name, Handle<Node> parent, +	              const std::string &fieldName);  };  /** @@ -340,13 +363,48 @@ public:   */  class StructuredEntity : public StructureNode, public DocumentEntity {  public: +	/** +	 * Constructor for a StructuredEntity in the Structure Tree. +	 * +	 * @param mgr        is the Manager instance. +	 * @param parent     is the parent DocumentEntity of this StructuredEntity +	 *                   in the DocumentTree. Note that this StructuredEntity +	 *                   will automatically register itself as child of this +	 *                   parent. +	 * @param descriptor is the StructuredClass of this StructuredEntity. +	 * @param attributes is a Map Variant containing attribute fillings for this +	 *                   StructuredEntity. It is empty per default. +	 * @param fieldName  is the name of the field in the parent DocumentEntity +	 *                   where this StructuredEntity shall be added. It is empty +	 *                   per default, referring to the default field. +	 * @param name       is some name for this StructuredEntity that may be used +	 *                   for later reference. It is empty per default. +	 */  	StructuredEntity(Manager &mgr, Handle<Node> parent, -	                 Handle<StructuredClass> descriptor, Variant attributes, +	                 Handle<StructuredClass> descriptor, +	                 Variant attributes = {}, const std::string &fieldName = "",  	                 std::string name = "") -	    : StructureNode(mgr, std::move(name), parent), +	    : StructureNode(mgr, std::move(name), parent, fieldName),  	      DocumentEntity(this, descriptor, std::move(attributes))  	{  	} + +	/** +	 * Constructor for a StructuredEntity at the document root. +	 * +	 * @param mgr        is the Manager instance. +	 * @param parent     is the parent Document of this StructuredEntity. Note +	 *                   that this StructuredEntity will automatically register +	 *                   itself as child of this Document. +	 * @param descriptor is the StructuredClass of this StructuredEntity. +	 * @param attributes is a Map Variant containing attribute fillings for this +	 *                   StructuredEntity. It is empty per default. +	 * @param name       is some name for this StructuredEntity that may be used +	 *                   for later reference. It is empty per default. +	 */ +	StructuredEntity(Manager &mgr, Handle<Document> doc, +	                 Handle<StructuredClass> descriptor, +	                 Variant attributes = {}, std::string name = "");  };  /** @@ -359,8 +417,25 @@ private:  	Variant content;  public: -	DocumentPrimitive(Manager &mgr, Handle<Node> parent, Variant content = {}) -	    : StructureNode(mgr, "", parent), content(content) +	/** +	 * Constructor for a DocumentPrimitive. +	 * +	 * @param mgr       is the Manager instance. +	 * @param parent    is the parent DocumentEntity of this DocumentPrimitive +	 *                  in the DocumentTree. Note that this DocumentPrimitive +	 *                  will automatically register itself as child of this +	 *                  parent. +	 * @param content   is a Variant containing the content of this +	 *                  DocumentPrimitive. The Type of this Variant is +	 *                  specified at the parents Descriptor for the given +	 *                  fieldName. +	 * @param fieldName is the name of the field in the parent DocumentEntity +	 *                  where this DocumentPrimitive shall be added. It is empty +	 *                  per default, referring to the default field. +	 */ +	DocumentPrimitive(Manager &mgr, Handle<Node> parent, Variant content, +	                  const std::string &fieldName = "") +	    : StructureNode(mgr, "", parent, fieldName), content(content)  	{  	} @@ -373,6 +448,34 @@ public:  };  /** + * An Anchor is an elementary StructureNode without any children that + * marks a point in the text content of the document that can later be + * referenced by an AnnotationEntity as it start and end point. + * Please refer to the AnnotationEntity documentation for more information. + */ +class Anchor : public StructureNode { +public: +	/** +	 * Constructor for Anchor. +	 * +	 * @param mgr       is the Manager instance. +	 * @param parent    is the parent of this Anchor in the Structure Tree (!), +	 *                  not the AnnotationEntity that references this Anchor. +	 *                  Note that this Anchor will automatically register itself +	 *                  as child of the given parent. +	 * @param name      is the Anchor id. +	 * @param fieldName is the name of the field in the parent DocumentEntity +	 *                  where this Anchor shall be added. It is empty +	 *                  per default, referring to the default field. +	 */ +	Anchor(Manager &mgr, std::string name, Handle<Node> parent, +	       const std::string &fieldName = "") +	    : StructureNode(mgr, std::move(name), parent, fieldName) +	{ +	} +}; + +/**   * An AnnotationEntity is a span-like instance that is not bound by the elements   * of the Structure Tree. An annotation may very well overlap and cross the   * limits of StructureEntities. A typical example for AnnotationEntities are @@ -397,27 +500,6 @@ public:   *   */  class AnnotationEntity : public Node, public DocumentEntity { -public: -	/** -	 * An Anchor is an elementary StructuredEntity without any children that -	 * marks a point in the text content of the document that can later be -	 * referenced by an AnnotationEntity as it start and end point. -	 * Please refer to the AnnotationEntity documentation for more information. -	 */ -	class Anchor : public StructureNode { -	public: -		/** -		 * @param mgr    is the Manager instance. -		 * @param parent is the parent of this Anchor in the Structure Tree (!), -		 *               not the AnnotationEntity that references this Anchor. -		 * @param name   is the Anchor id. -		 */ -		Anchor(Manager &mgr, std::string name, Handle<Node> parent) -		    : StructureNode(mgr, std::move(name), parent) -		{ -		} -	}; -  private:  	Owned<Anchor> start;  	Owned<Anchor> end; @@ -466,8 +548,7 @@ public:   * document and the AnnotationEntities that span over Anchors in this Document.   */  class Document : public Node { - -friend AnnotationEntity; +	friend AnnotationEntity;  private:  	// TODO: Might there be several roots? E.g. metadata? @@ -540,7 +621,7 @@ extern const Rtti<model::AnnotationEntity> AnnotationEntity;  extern const Rtti<model::StructureNode> StructureNode;  extern const Rtti<model::StructuredEntity> StructuredEntity;  extern const Rtti<model::DocumentPrimitive> DocumentPrimitive; -extern const Rtti<model::AnnotationEntity::Anchor> Anchor; +extern const Rtti<model::Anchor> Anchor;  }  } diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp index b94b397..a3d1b84 100644 --- a/src/plugins/html/DemoOutput.cpp +++ b/src/plugins/html/DemoOutput.cpp @@ -203,7 +203,6 @@ Rooted<xml::Element> DemoHTMLTransformer::transformList(  	return l;  } -typedef model::AnnotationEntity::Anchor Anchor;  typedef std::stack<Rooted<model::AnnotationEntity>> AnnoStack;  static Rooted<xml::Element> openAnnotation( @@ -262,7 +261,7 @@ Rooted<xml::Element> DemoHTMLTransformer::transformParagraph(  	// this is a handle for our current XML element for annotation handling.  	Rooted<xml::Element> current = p;  	for (auto &n : par->getField()) { -		if (n->isa(typeOf<Anchor>())) { +		if (n->isa(RttiTypes::Anchor)) {  			// check if this is a start Anchor.  			// here we assume, again, that the ids/names of anchors are unique.  			auto it = startMap.find(n->getName()); diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index 15a4042..f8585d1 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -115,11 +115,9 @@ static Rooted<Domain> constructEmphasisDomain(Manager &mgr,  	// set up domain node.  	Rooted<Domain> domain{new Domain(mgr, sys, "emphasis")};  	// create AnnotationClasses -	Rooted<AnnotationClass> em{ -	    new AnnotationClass(mgr, "emphasized", domain)}; +	Rooted<AnnotationClass> em{new AnnotationClass(mgr, "emphasized", domain)}; -	Rooted<AnnotationClass> strong{ -	    new AnnotationClass(mgr, "strong", domain)}; +	Rooted<AnnotationClass> strong{new AnnotationClass(mgr, "strong", domain)};  	return domain;  } @@ -135,12 +133,8 @@ static bool addText(Logger &logger, Handle<Document> doc,  	}  	// And the primitive content  	Variant content_var{content.c_str()}; -	Rooted<DocumentPrimitive> primitive = -	    buildPrimitiveEntity(logger, text, content_var, "content"); -	if (primitive.isNull()) { -		return false; -	} - +	Rooted<DocumentPrimitive> primitive{new DocumentPrimitive( +	    parent->getManager(), text, content_var, "content")};  	return true;  } @@ -167,19 +161,12 @@ static bool addAnnotation(Logger &logger, Handle<Document> doc,                            Handle<StructuredEntity> parent,                            const std::string &text, const std::string &annoClass)  { -	Rooted<AnnotationEntity::Anchor> start = -	    buildAnchor(logger, parent, std::to_string(annoIdx++)); -	if (start.isNull()) { -		return false; -	} +	Manager& mgr = parent->getManager(); +	Rooted<Anchor> start{new Anchor(mgr, std::to_string(annoIdx++), parent)};  	if (!addText(logger, doc, parent, text)) {  		return false;  	} -	Rooted<AnnotationEntity::Anchor> end = -	    buildAnchor(logger, parent, std::to_string(annoIdx++)); -	if (end.isNull()) { -		return false; -	} +	Rooted<Anchor> end{new Anchor(mgr, std::to_string(annoIdx++), parent)};  	Rooted<AnnotationEntity> anno =  	    buildAnnotationEntity(doc, logger, {annoClass}, start, end);  	if (anno.isNull()) { @@ -191,7 +178,6 @@ static bool addAnnotation(Logger &logger, Handle<Document> doc,  /**   * This constructs a more advanced book document using not only the book   * domain but also headings, emphasis and lists. - * TODO: insert emphasis and lists.   */  static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger,                                                    Handle<Domain> bookDom, diff --git a/test/core/model/TestDocument.hpp b/test/core/model/TestDocument.hpp index eaec42c..2397fe6 100644 --- a/test/core/model/TestDocument.hpp +++ b/test/core/model/TestDocument.hpp @@ -60,11 +60,8 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger,  	}  	// And its primitive content  	Variant text{"Some introductory text"}; -	Rooted<DocumentPrimitive> foreword_primitive = -	    buildPrimitiveEntity(logger, foreword_text, text, "content"); -	if (foreword_primitive.isNull()) { -		return {nullptr}; -	} +	Rooted<DocumentPrimitive> foreword_primitive{ +	    new DocumentPrimitive(mgr, foreword_text, text, "content")};  	// Add a section.  	Rooted<StructuredEntity> section =  	    buildStructuredEntity(doc, logger, root, {"section"}); @@ -82,8 +79,8 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger,  	}  	// And its primitive content  	text = Variant{"Some actual text"}; -	Rooted<DocumentPrimitive> main_primitive = -	    buildPrimitiveEntity(logger, main_text, text, "content"); +	Rooted<DocumentPrimitive> main_primitive{ +	    new DocumentPrimitive(mgr, main_text, text, "content")};  	if (main_primitive.isNull()) {  		return {nullptr};  	} 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<StructuredEntity> buildRootStructuredEntity(Handle<Document> document,  	Rooted<StructuredEntity> root{new StructuredEntity(  	    document->getManager(), document, descriptor.cast<StructuredClass>(),  	    attributes, std::move(name))}; -	// append it to the document. -	document->setRoot(root);  	// and return it.  	return root;  } @@ -162,95 +160,13 @@ Rooted<StructuredEntity> buildStructuredEntity(  	// Then construct the StructuredEntity itself.  	Rooted<StructuredEntity> entity{new StructuredEntity(  	    parent->getManager(), parent, descriptor.cast<StructuredClass>(), -	    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<DocumentPrimitive> buildPrimitiveEntity( -    Logger &logger, Handle<StructuredEntity> 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<DocumentPrimitive> 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<AnnotationEntity::Anchor> buildAnchor(Logger &logger, -                                             Handle<StructuredEntity> 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<AnnotationEntity::Anchor> 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<AnnotationEntity::Anchor> buildAnchor(Logger &logger,   */  Rooted<AnnotationEntity> buildAnnotationEntity(      Handle<Document> document, Logger &logger, const Path &path, -    Handle<AnnotationEntity::Anchor> start, -    Handle<AnnotationEntity::Anchor> end, Variant attributes = {}, +    Handle<Anchor> start, +    Handle<Anchor> end, Variant attributes = {},      std::string name = "")  {  	// If the input handles are not set, we can not build the entity. diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp index d18a314..5668ddc 100644 --- a/test/plugins/html/DemoOutputTest.cpp +++ b/test/plugins/html/DemoOutputTest.cpp @@ -55,7 +55,7 @@ TEST(DemoHTMLTransformer, writeHTML)  	ASSERT_TRUE(doc != nullptr);  #ifdef MANAGER_GRAPHVIZ_EXPORT -	// dump the manager state +// dump the manager state  // 	mgr.exportGraphviz("bookDocument.dot");  #endif @@ -93,31 +93,21 @@ TEST(DemoHTMLTransformer, AnnotationProcessing)  	Rooted<model::StructuredEntity> p =  	    buildStructuredEntity(doc, logger, book, {"paragraph"});  	ASSERT_TRUE(p != nullptr); -	Rooted<model::AnnotationEntity::Anchor> em_start = -	    buildAnchor(logger, p, "1"); -	ASSERT_TRUE(em_start != nullptr); +	Rooted<model::Anchor> em_start{new model::Anchor(mgr, "1", p)};  	ASSERT_TRUE(addText(logger, doc, p, "bla")); -	Rooted<model::AnnotationEntity::Anchor> strong_start = -	    buildAnchor(logger, p, "2"); -	ASSERT_TRUE(strong_start != nullptr); +	Rooted<model::Anchor> strong_start{new model::Anchor(mgr, "2", p)};  	ASSERT_TRUE(addText(logger, doc, p, "blub")); -	Rooted<model::AnnotationEntity::Anchor> em_end = -	    buildAnchor(logger, p, "3"); -	ASSERT_TRUE(em_end != nullptr); +	Rooted<model::Anchor> em_end{new model::Anchor(mgr, "3", p)};  	ASSERT_TRUE(addText(logger, doc, p, "bla")); -	Rooted<model::AnnotationEntity::Anchor> strong_end = -	    buildAnchor(logger, p, "4"); -	ASSERT_TRUE(strong_end != nullptr); +	Rooted<model::Anchor> strong_end{new model::Anchor(mgr, "4", p)};  	buildAnnotationEntity(doc, logger, {"emphasized"}, em_start, em_end);  	buildAnnotationEntity(doc, logger, {"strong"}, strong_start, strong_end); -  #ifdef MANAGER_GRAPHVIZ_EXPORT -	// dump the manager state +// dump the manager state  // 	mgr.exportGraphviz("annotationDocument.dot");  #endif -  	// Check serialization.  	DemoHTMLTransformer transformer;  	std::stringstream out; | 
