summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-04 22:40:40 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-04 22:40:40 +0100
commit9249dbedc1a778cf02203a1bcb14880c9bdb0b4e (patch)
tree07d66baf8718ff8c238a99a485f435dc76091a9a /src/core/model
parent0cfb5a4e1edbc164fc674a98ee8d788c821fbc39 (diff)
allowed actual field descriptor references.
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Domain.cpp26
-rw-r--r--src/core/model/Domain.hpp27
2 files changed, 37 insertions, 16 deletions
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<FieldDescriptor> 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,6 +235,7 @@ bool Descriptor::continuePath(Handle<StructuredClass> target,
return found;
}
+
void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd)
{
// only add it if we need to.
@@ -255,6 +243,18 @@ void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd)
invalidate();
fieldDescriptors.push_back(fd);
}
+ if (fd->getParent() == nullptr) {
+ fd->setParent(this);
+ }
+}
+
+void Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd)
+{
+ // only add it if we need to.
+ if (fieldDescriptors.find(fd) == fieldDescriptors.end()) {
+ invalidate();
+ fieldDescriptors.push_back(fd);
+ }
Handle<Managed> par = fd->getParent();
if (par != this) {
if (par != nullptr) {
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
@@ -509,12 +509,33 @@ public:
/**
* 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<FieldDescriptor> 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<Handle<FieldDescriptor>> &fds)
+ {
+ for (Handle<FieldDescriptor> 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
* already and removes it from the old parent Descriptor.
*
* @param fd is a FieldDescriptor.
*/
- void addFieldDescriptor(Handle<FieldDescriptor> fd);
+ void moveFieldDescriptor(Handle<FieldDescriptor> 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<Handle<FieldDescriptor>> &fds)
+ void moveFieldDescriptors(const std::vector<Handle<FieldDescriptor>> &fds)
{
for (Handle<FieldDescriptor> fd : fds) {
- addFieldDescriptor(fd);
+ moveFieldDescriptor(fd);
}
}