summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-15 23:09:18 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-15 23:09:18 +0100
commit988fac434d2450998cbce85e338cb1534acfa808 (patch)
tree3e6cffb1e22aadf2958bb8b483922af552d9c2b0
parent40f33ed35691c5052beaa98ca89c0f22ceb12666 (diff)
changed order of fields in StructuredClass::getFieldDescriptors
-rw-r--r--src/core/model/Domain.cpp44
-rw-r--r--src/core/model/Domain.hpp14
2 files changed, 35 insertions, 23 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp
index ae20068..8bacdb8 100644
--- a/src/core/model/Domain.cpp
+++ b/src/core/model/Domain.cpp
@@ -778,36 +778,40 @@ void StructuredClass::removeSubclass(Handle<StructuredClass> sc, Logger &logger)
sc->setSuperclass(nullptr, logger);
}
-void StructuredClass::gatherFieldDescriptors(
+Rooted<FieldDescriptor> StructuredClass::gatherFieldDescriptors(
NodeVector<FieldDescriptor> &current,
std::set<std::string> &overriddenFields, bool hasTREE) const
{
- // append all FieldDescriptors that are not overridden.
- for (auto &f : Descriptor::getFieldDescriptors()) {
+ Rooted<FieldDescriptor> mainField;
+ NodeVector<FieldDescriptor> tmp;
+ // first gather the non-overridden fields.
+ for (auto f : Descriptor::getFieldDescriptors()) {
if (overriddenFields.insert(f->getName()).second) {
bool isTREE = f->getFieldType() == FieldDescriptor::FieldType::TREE;
- if (hasTREE) {
- if (!isTREE) {
- /*
- * If we already have a tree field it has to be at the end
- * of the current vector. So ensure that all new non-TREE
- * fields are inserted before the TREE field such that after
- * this method the TREE field is still at the end.
- */
- current.insert(current.end() - 1, f);
- }
+ if (!isTREE) {
+ tmp.push_back(f);
} else {
- if (isTREE) {
+ if (!hasTREE) {
hasTREE = true;
+ mainField = f;
}
- current.push_back(f);
}
}
}
- // if we have a superclass, go there.
+ // append all non-overridden superclass fields.
+
if (superclass != nullptr) {
- superclass->gatherFieldDescriptors(current, overriddenFields, hasTREE);
+ Rooted<FieldDescriptor> super_main_field =
+ superclass->gatherFieldDescriptors(current, overriddenFields,
+ hasTREE);
+ if (!hasTREE) {
+ mainField = super_main_field;
+ }
}
+ // then append all subtree fields of this level.
+ current.insert(current.end(), tmp.begin(), tmp.end());
+ // and return the main field.
+ return mainField;
}
NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const
@@ -815,7 +819,11 @@ NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const
// in this case we return a NodeVector of Rooted entries without owner.
NodeVector<FieldDescriptor> vec;
std::set<std::string> overriddenFields;
- gatherFieldDescriptors(vec, overriddenFields, false);
+ Rooted<FieldDescriptor> mainField =
+ gatherFieldDescriptors(vec, overriddenFields, false);
+ if (mainField != nullptr) {
+ vec.push_back(mainField);
+ }
return vec;
}
diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp
index 081435a..350c7ba 100644
--- a/src/core/model/Domain.hpp
+++ b/src/core/model/Domain.hpp
@@ -791,9 +791,9 @@ private:
/**
* Helper method for getFieldDescriptors.
*/
- void gatherFieldDescriptors(NodeVector<FieldDescriptor> &current,
- std::set<std::string> &overriddenFields,
- bool hasTREE) const;
+ Rooted<FieldDescriptor> gatherFieldDescriptors(
+ NodeVector<FieldDescriptor> &current,
+ std::set<std::string> &overriddenFields, bool hasTREE) const;
protected:
bool doValidate(Logger &logger) const override;
@@ -915,10 +915,14 @@ public:
void removeSubclass(Handle<StructuredClass> sc, Logger &logger);
/**
- * Returns a const reference to the NodeVector of all FieldDescriptors of
+ * Returns a NodeVector of all FieldDescriptors of
* this StructuredClass. This also merges the FieldDescriptors directly
* belonging to this StructuredClass with all FieldDescritptors of its
- * Superclass (and so on recurvively).
+ * Superclass (and so on recurvively). The order of field descriptors is
+ * as follows:
+ * 1.) non-overridden SUBTREE FieldDescriptors of super classes.
+ * 2.) SUBTREE FieldDescriptors of this class.
+ * 3.) TREE FieldDescriptor (either inherited from super class or direct)
*
* @return a NodeVector of all FieldDescriptors of this StructuredClass.
*/