From 33008f1110523ae9c9b9e1d2ca24ed642637c40d Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 22 Jan 2015 00:43:40 +0100 Subject: added move semantics do Domain and Document classes. --- src/core/model/Document.hpp | 88 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 11 deletions(-) (limited to 'src/core/model/Document.hpp') diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index f13faf2..7357dd2 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -162,6 +162,8 @@ private: void addStructureNode(Handle s, const int &i); + bool removeStructureNodeFromField(Handle s, const int &i); + protected: bool doValidate(Logger &logger) const; @@ -278,8 +280,8 @@ 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. - * TODO: This could get move semantics. + * it is not set to this DocumentEntity already and removes it from the + * old parent. * * @param s is the StructureNode that shall be added. * @param fieldName is the name of a field as specified in the @@ -287,6 +289,7 @@ public: */ void addStructureNode(Handle s, const std::string &fieldName = ""); + /** * This adds multiple StructureNodes to the field with the given name. * If an empty name is given it is assumed that the 'default' @@ -297,7 +300,8 @@ 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. + * it is not set to this DocumentEntity already and removes it from the + * old parent. * * @param ss are the StructureNodes that shall be added. * @param fieldName is the name of a field as specified in the @@ -306,6 +310,26 @@ public: void addStructureNodes(const std::vector> &ss, const std::string &fieldName = ""); + /** + * This removes a StructureNode from 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. + * + * This method also changes the parent of the removed StructureNode to null. + * + * @param s is the StructureNode that shall be removed. + * @param fieldName is the name of a field as specified in the + * FieldDescriptor in the Domain description. + * @return true if this StructureNode was a child here and false if + * if was not found. + */ + bool removeStructureNodeFromField(Handle s, + const std::string &fieldName = ""); + /** * This adds a StructureNode to the field with the given FieldDescriptor. * @@ -313,7 +337,8 @@ public: * an exception is thrown. * * This method also changes the parent of the newly added StructureNode if - * it is not set to this DocumentEntity already. + * it is not set to this DocumentEntity already and removes it from the + * old parent. * * @param s is the StructureNode that shall be added. * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for @@ -330,7 +355,8 @@ public: * an exception is thrown. * * This method also changes the parent of each newly added StructureNode if - * it is not set to this DocumentEntity already. + * it is not set to this DocumentEntity already and removes it from the + * old parent. * * @param ss are the StructureNodes that shall be added. * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for @@ -338,6 +364,35 @@ public: */ void addStructureNodes(const std::vector> &ss, Handle fieldDescriptor); + + /** + * This removes a StructureNode from the field with the given + * FieldDescriptor. + * + * This method also changes the parent of the removed StructureNode to null. + * + * @param s is the StructureNode that shall be removed. + * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for + * this DocumentEntity. + + * @return true if this StructureNode was a child here and false if + * if was not found. + */ + bool removeStructureNodeFromField(Handle s, + Handle fieldDescriptor); + + /** + * This removes a StructureNode from this DocumentEntity. It iterates + * through all fields to find it. + * + * This method also changes the parent of the removed StructureNode to null. + * + * @param s is the StructureNode that shall be removed. + + * @return true if this StructureNode was a child here and false if if was + * not found. + */ + bool removeStructureNode(Handle s); }; /** @@ -680,21 +735,32 @@ public: } /** - * Adds an AnnotationEntity to this document. This also sets the parent - * of the given AnnotationEntity if it is not set to this document already. + * Adds an AnnotationEntity to this Document. This also sets the parent + * of the given AnnotationEntity if it is not set to this Document already + * and removes it from the old Document. * * @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. + * Adds multiple AnnotationEntities to this Document. This also sets the + * parent of each given AnnotationEntity if it is not set to this Document + * already and removes it from the old Document. * * @param as is a vector of AnnotationEntities. */ - void addAnnotations(const std::vector>& as); + void addAnnotations(const std::vector> &as); + + /** + * Removes an AnnotationEntity from this Document. This also sets the parent + * of the given AnnotationEntity to null. + * + * @param a is some AnnotationEntity. + * @return true if the given AnnotationEntity was removed and false if this + * Document did not have the given AnnotationEntity as child. + */ + bool removeAnnotation(Handle a); /** * Returns a const reference to the NodeVector of Domains that are used -- cgit v1.2.3