summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 11:57:08 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-16 11:57:08 +0100
commit3cca090a650d2e8268977b57aa0dfdb0fb2cae85 (patch)
tree761eba26c204dfdf6b1d34eee345bc18a0fd13db /src/core/model
parent884c7d772da6ad9869866f8a7a15bd08a15376ba (diff)
added return value in addFieldDescriptor related methods to indicate whether the order of fields had to be changed.
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Domain.cpp49
-rw-r--r--src/core/model/Domain.hpp31
2 files changed, 43 insertions, 37 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp
index ac0699e..f6c3956 100644
--- a/src/core/model/Domain.cpp
+++ b/src/core/model/Domain.cpp
@@ -558,7 +558,7 @@ Rooted<FieldDescriptor> Descriptor::getFieldDescriptor(
}
}
-void Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd,
+bool Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd,
Logger &logger)
{
// only add it if we need to.
@@ -571,37 +571,25 @@ void Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd,
fd->getFieldType() != FieldDescriptor::FieldType::TREE) {
// if so we add the new field before the TREE field.
fieldDescriptors.insert(fieldDescriptors.end() - 1, fd);
-
- // if the new field was from the same domain we warn the user
- // because that is bad coding style.
- if (fd->getParent() != nullptr &&
- fd->getParent().cast<Descriptor>()->getParent() ==
- getParent()) {
- logger.warning(
- std::string("Field \"") + fd->getName() +
- "\" was declared after main field \"" +
- fds.back()->getName() +
- "\". The order of fields was changed to make the "
- "main field the last field.",
- *fd);
- }
+ return true;
} else {
fieldDescriptors.push_back(fd);
}
}
+ return false;
}
-void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
+bool Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
{
- addAndSortFieldDescriptor(fd, logger);
if (fd->getParent() == nullptr) {
fd->setParent(this);
}
+ return addAndSortFieldDescriptor(fd, logger);
}
-void Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
+bool Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
{
- addAndSortFieldDescriptor(fd, logger);
+ bool sorted = addAndSortFieldDescriptor(fd, logger);
Handle<Managed> par = fd->getParent();
if (par != this) {
if (par != nullptr) {
@@ -610,9 +598,10 @@ void Descriptor::moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
}
fd->setParent(this);
}
+ return sorted;
}
-void Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
+bool Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
{
Rooted<FieldDescriptor> copy;
if (fd->isPrimitive()) {
@@ -631,7 +620,7 @@ void Descriptor::copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger)
copy->addChild(c);
}
}
- addFieldDescriptor(copy, logger);
+ return addFieldDescriptor(copy, logger);
}
bool Descriptor::removeFieldDescriptor(Handle<FieldDescriptor> fd)
@@ -646,25 +635,27 @@ bool Descriptor::removeFieldDescriptor(Handle<FieldDescriptor> fd)
return false;
}
-Rooted<FieldDescriptor> Descriptor::createPrimitiveFieldDescriptor(
- Handle<Type> primitiveType, Logger &logger,
- FieldDescriptor::FieldType fieldType, std::string name, bool optional)
+std::pair<Rooted<FieldDescriptor>, bool>
+Descriptor::createPrimitiveFieldDescriptor(Handle<Type> primitiveType,
+ Logger &logger,
+ FieldDescriptor::FieldType fieldType,
+ std::string name, bool optional)
{
Rooted<FieldDescriptor> fd{new FieldDescriptor(getManager(), primitiveType,
this, fieldType,
std::move(name), optional)};
- addFieldDescriptor(fd, logger);
- return fd;
+ bool sorted = addFieldDescriptor(fd, logger);
+ return std::make_pair(fd, sorted);
}
-Rooted<FieldDescriptor> Descriptor::createFieldDescriptor(
+std::pair<Rooted<FieldDescriptor>, bool> Descriptor::createFieldDescriptor(
Logger &logger, FieldDescriptor::FieldType fieldType, std::string name,
bool optional)
{
Rooted<FieldDescriptor> fd{new FieldDescriptor(
getManager(), this, fieldType, std::move(name), optional)};
- addFieldDescriptor(fd, logger);
- return fd;
+ bool sorted = addFieldDescriptor(fd, logger);
+ return std::make_pair(fd, sorted);
}
/* Class StructuredClass */
diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp
index 350c7ba..476a38c 100644
--- a/src/core/model/Domain.hpp
+++ b/src/core/model/Domain.hpp
@@ -469,7 +469,7 @@ private:
Owned<StructType> attributesDescriptor;
NodeVector<FieldDescriptor> fieldDescriptors;
- void addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
+ bool addAndSortFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
protected:
void doResolve(ResolutionState &state) override;
@@ -557,8 +557,11 @@ public:
* parent of the given FieldDescriptor if it is not set yet.
*
* @param fd is a FieldDescriptor.
+ * @return returns true if the given FieldDescriptor was not added at the
+ * end one place before because a TREE field already existed and
+ * the TREE field has to be at the end.
*/
- void addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
+ bool addFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
/**
* Adds the given FieldDescriptor to this Descriptor. This also sets the
@@ -566,16 +569,22 @@ public:
* already and removes it from the old parent Descriptor.
*
* @param fd is a FieldDescriptor.
+ * @return returns true if the given FieldDescriptor was not added at the
+ * end one place before because a TREE field already existed and
+ * the TREE field has to be at the end.
*/
- void moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
+ bool moveFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
/**
* Copies a FieldDescriptor that belongs to another Descriptor to this
* Descriptor.
*
* @param fd some FieldDescriptor belonging to another Descriptor.
+ * @return returns true if the given FieldDescriptor was not added at the
+ * end one place before because a TREE field already existed and
+ * the TREE field has to be at the end.
*/
- void copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
+ bool copyFieldDescriptor(Handle<FieldDescriptor> fd, Logger &logger);
/**
* Removes the given FieldDescriptor from this Descriptor. This also sets
@@ -598,9 +607,12 @@ public:
* filled in order for an instance of the parent
* Descriptor to be valid.
*
- * @return the newly created FieldDescriptor.
+ * @return the newly created FieldDescriptor and a bool
+ * indicating whether the order of FieldDescriptors had
+ * to be changed for the TREE field to be in the last
+ * spot.
*/
- Rooted<FieldDescriptor> createPrimitiveFieldDescriptor(
+ std::pair<Rooted<FieldDescriptor>, bool> createPrimitiveFieldDescriptor(
Handle<Type> primitiveType, Logger &logger,
FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE,
std::string name = "", bool optional = false);
@@ -617,9 +629,12 @@ public:
* filled in order for an instance of the parent
* Descriptor to be valid.
*
- * @return the newly created FieldDescriptor.
+ * @return the newly created FieldDescriptor and a bool
+ * indicating whether the order of FieldDescriptors had
+ * to be changed for the TREE field to be in the last
+ * spot.
*/
- Rooted<FieldDescriptor> createFieldDescriptor(
+ std::pair<Rooted<FieldDescriptor>, bool> createFieldDescriptor(
Logger &logger,
FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE,
std::string name = "", bool optional = false);