From 20d3e71f26ca884271ed5d372a8459394554c147 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 20 Jan 2015 01:24:11 +0100 Subject: finished setter revival in Document classes, hopefully. --- src/core/model/Document.hpp | 94 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 15 deletions(-) (limited to 'src/core/model/Document.hpp') diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index d89ade8..4147847 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -139,8 +139,6 @@ class StructureNode; * */ class DocumentEntity { - friend StructureNode; - private: /* * this is a rather dirty method that should not be used in other cases: @@ -162,6 +160,8 @@ private: void invalidateSubInstance(); + void addStructureNode(Handle s, const int &i); + protected: bool doValidate(Logger &logger) const; @@ -189,6 +189,13 @@ public: */ Rooted getDescriptor() const { return descriptor; } + /** + * Sets the Descriptor for this DocumentEntity. + * + * @param d is the new Descriptor for this DocumentEntity. + */ + void setDescriptor(Handle d); + /** * Returns a Map Variant adhering to the attribute StructType in the given * descriptor. @@ -270,6 +277,9 @@ public: * * If the name is unknown an exception is thrown. * + * This method also changes the parent of the newly added StructureNode if + * it is not set to this DocumentEntity already. + * * @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. @@ -285,6 +295,9 @@ public: * * If the name is unknown an exception is thrown. * + * This method also changes the parent of each newly added StructureNode if + * it is not set to this DocumentEntity already. + * * @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. @@ -298,6 +311,9 @@ public: * If the FieldDescriptor does not belong to the Descriptor of this node * an exception is thrown. * + * This method also changes the parent of the newly added StructureNode if + * it is not set to this DocumentEntity already. + * * @param s is the StructureNode that shall be added. * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for * this DocumentEntity. @@ -312,6 +328,9 @@ public: * If the FieldDescriptor does not belong to the Descriptor of this node * an exception is thrown. * + * This method also changes the parent of each newly added StructureNode if + * it is not set to this DocumentEntity already. + * * @param ss are the StructureNodes that shall be added. * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for * this DocumentEntity. @@ -328,19 +347,20 @@ class StructureNode : public Node { friend DocumentEntity; public: - /** - * Constructor for a StructureNode at the root. - */ - StructureNode(Manager &mgr, std::string name, Handle doc) - : Node(mgr, std::move(name), doc) - { - } - /** * Constructor for a StructureNode in the StructureTree. */ StructureNode(Manager &mgr, std::string name, Handle parent, const std::string &fieldName); + + /** + * Constructor for an empty StructureNode. + */ + StructureNode(Manager &mgr, std::string name = "", + Handle parent = nullptr) + : Node(mgr, std::move(name), parent) + { + } }; /** @@ -394,6 +414,23 @@ public: StructuredEntity(Manager &mgr, Handle doc, Handle descriptor, Variant attributes = {}, std::string name = ""); + + /** + * Constructor for an empty StructuredEntity that is not yet connected. + * + * @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 parent = nullptr, + Handle descriptor = nullptr, + Variant attributes = {}, std::string name = ""); }; /** @@ -527,8 +564,8 @@ public: * @param name is some name for this AnnotationEntity that might be * used for references later on. It is empty per default. */ - AnnotationEntity(Manager &mgr, Handle parent, - Handle descriptor, + AnnotationEntity(Manager &mgr, Handle parent = nullptr, + Handle descriptor = nullptr, Handle start = nullptr, Handle end = nullptr, Variant attributes = {}, std::string name = ""); @@ -565,6 +602,7 @@ public: */ void setEnd(Handle e) { + invalidate(); end = acquire(e); } }; @@ -575,8 +613,6 @@ public: * document and the AnnotationEntities that span over Anchors in this Document. */ class Document : public Node { - friend AnnotationEntity; - private: // TODO: Might there be several roots? E.g. metadata? Owned root; @@ -589,18 +625,29 @@ protected: bool doValidate(Logger &logger) const override; public: + /** + * This sets up an empty document. + * + * @param mgr is the Manager instance. + * @param name is a name for this Document. + */ Document(Manager &mgr, std::string name) : Node(mgr, std::move(name), nullptr), annotations(this) { } /** - * Sets the root StructuredEntity of this Document. + * Sets the root StructuredEntity of this Document. This also sets the + * parent of the given StructuredEntity if it is not set to this Document + * already. */ void setRoot(Handle root) { invalidate(); this->root = acquire(root); + if (root->getParent() != this) { + root->setParent(this); + } }; /** @@ -622,6 +669,23 @@ public: return annotations; } + /** + * Adds an AnnotationEntity to this document. This also sets the parent + * of the given AnnotationEntity if it is not set to this document already. + * + * @param a is some AnnotationEntity + */ + void addAnnotation(Handle a); + + /** + * Adds multiple AnnotationEntities to this document. This also sets the + * parent of each given AnnotationEntity if it is not set to this document + * already. + * + * @param as is a vector of AnnotationEntities. + */ + void addAnnotations(std::vector> as); + /** * Returns a const reference to the NodeVector of Domains that are used * within this Document. -- cgit v1.2.3