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/Domain.hpp | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'src/core/model/Domain.hpp') diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 85caa14..12cb9b3 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -510,33 +510,21 @@ public: /** * Adds the given FieldDescriptor to this Descriptor. This also sets the * parent of the given FieldDescriptor if it is not set to this Descriptor - * already. - * - * This should not be used if the given FieldDescriptor is a field of - * another Descriptor already. Use copyFieldDescriptor in that case. - * TODO: But this could get move semantics. + * already and removes it from the old parent Descriptor. * * @param fd is a FieldDescriptor. */ - void addFieldDescriptor(Handle fd) - { - invalidate(); - fieldDescriptors.push_back(fd); - if (fd->getParent() != this) { - fd->setParent(this); - } - } + void addFieldDescriptor(Handle fd); /** * Adds the given FieldDescriptors to this Descriptor. This also sets the * parent of each given FieldDescriptor if it is not set to this Descriptor - * already. + * already and removes it from the old parent Descriptor. * * @param fds are FieldDescriptors. */ void addFieldDescriptors(const std::vector> &fds) { - invalidate(); for (Handle fd : fds) { addFieldDescriptor(fd); } @@ -550,6 +538,16 @@ public: */ void copyFieldDescriptor(Handle fd); + /** + * Removes the given FieldDescriptor from this Descriptor. This also sets + * the parent of the given FieldDescriptor to null. + * + * @param fd is a FieldDescriptor. + * @return true if the FieldDescriptor was removed and false if this + * Descriptor did not have the given FieldDescriptor as child. + */ + bool removeFieldDescriptor(Handle fd); + /** * This tries to construct the shortest possible path of this Descriptor * to the given child Descriptor. As an example consider the book domain @@ -877,13 +875,7 @@ private: protected: void doResolve(ResolutionState &state) override; - /* - * TODO: doValidate with: - * # namecheck - * # are all structureclasses valid and have a unique name? - * # are all annotationclasses valid and have a unique name? - * # are all typesystems valid? - */ + bool doValidate(Logger &logger) const override; public: @@ -931,13 +923,23 @@ public: } /** * Adds a StructuredClass to this domain. This also sets the parent of the - * given StructuredClass if it is not set to this Domain already. - * TODO: This could have move semantics. + * given StructuredClass if it is not set to this Domain already and removes + * it from the old Domain. * * @param s is some StructuredClass. */ void addStructuredClass(Handle s); + /** + * Removes a StructuredClass from this domain. This also sets the parent of + * the given StructuredClass to null. + * + * @param s is some StructuredClass. + * @return true if the given StructuredClass was removed and false if this + * Domain did not have the given StructuredClass as child. + */ + bool removeStructuredClass(Handle s); + /** * Returns a const reference to the NodeVector of AnnotationClasses that are * part of this Domain. @@ -951,13 +953,23 @@ public: } /** * Adds an AnnotationClass to this domain. This also sets the parent of the - * given AnnotationClass if it is not set to this Domain already. - * TODO: This could have move semantics. + * given AnnotationClass if it is not set to this Domain already and removes + * it from the old Domain. * * @param a is some AnnotationClass. */ void addAnnotationClass(Handle a); + /** + * Removes a AnnotationClass from this domain. This also sets the parent of + * the given AnnotationClass to null. + * + * @param a is some AnnotationClass. + * @return true if the given AnnotationClass was removed and false if this + * Domain did not have the given AnnotationClass as child. + */ + bool removeAnnotationClass(Handle a); + /** * Returns a const reference to the NodeVector of TypeSystems that are * references in this Domain. -- cgit v1.2.3