From 9249dbedc1a778cf02203a1bcb14880c9bdb0b4e Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 4 Feb 2015 22:40:40 +0100 Subject: allowed actual field descriptor references. --- src/core/model/Domain.cpp | 26 +++++++++++++------------- src/core/model/Domain.hpp | 27 ++++++++++++++++++++++++--- src/plugins/xml/XmlParser.cpp | 2 +- 3 files changed, 38 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 9368005..f8c0779 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -155,19 +155,6 @@ bool Descriptor::doValidate(Logger &logger) const } else { valid = valid & validateName(logger); } - // check if all FieldDescriptors have this Descriptor as parent. - for (Handle fd : fieldDescriptors) { - if (fd->getParent() != this) { - logger.error(std::string("Descriptor \"") + getName() + - "\" has " - "field \"" + - fd->getName() + - "\" as child but the field does not " - "have the Descriptor as parent.", - *this); - valid = false; - } - } // check the FieldDescriptors themselves. return valid & continueValidationCheckDuplicates(fieldDescriptors, logger); } @@ -248,7 +235,20 @@ bool Descriptor::continuePath(Handle target, return found; } + void Descriptor::addFieldDescriptor(Handle fd) +{ + // only add it if we need to. + if (fieldDescriptors.find(fd) == fieldDescriptors.end()) { + invalidate(); + fieldDescriptors.push_back(fd); + } + if (fd->getParent() == nullptr) { + fd->setParent(this); + } +} + +void Descriptor::moveFieldDescriptor(Handle fd) { // only add it if we need to. if (fieldDescriptors.find(fd) == fieldDescriptors.end()) { diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index bef7919..dd0af4c 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -507,6 +507,27 @@ public: return fieldDescriptors; } + /** + * Adds the given FieldDescriptor to this Descriptor. This also sets the + * parent of the given FieldDescriptor if it is not set yet. + * + * @param fd is a FieldDescriptor. + */ + 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 yet. + * + * @param fds are FieldDescriptors. + */ + void addFieldDescriptors(const std::vector> &fds) + { + for (Handle fd : fds) { + addFieldDescriptor(fd); + } + } + /** * Adds the given FieldDescriptor to this Descriptor. This also sets the * parent of the given FieldDescriptor if it is not set to this Descriptor @@ -514,7 +535,7 @@ public: * * @param fd is a FieldDescriptor. */ - void addFieldDescriptor(Handle fd); + void moveFieldDescriptor(Handle fd); /** * Adds the given FieldDescriptors to this Descriptor. This also sets the @@ -523,10 +544,10 @@ public: * * @param fds are FieldDescriptors. */ - void addFieldDescriptors(const std::vector> &fds) + void moveFieldDescriptors(const std::vector> &fds) { for (Handle fd : fds) { - addFieldDescriptor(fd); + moveFieldDescriptor(fd); } } diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index c288f40..2d62c11 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -411,7 +411,7 @@ public: name, parent, logger(), [](Handle field, Handle parent, Logger &logger) { if (field != nullptr) { - parent.cast()->copyFieldDescriptor( + parent.cast()->addFieldDescriptor( field.cast()); } }); -- cgit v1.2.3