From 988fac434d2450998cbce85e338cb1534acfa808 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 15 Feb 2015 23:09:18 +0100 Subject: changed order of fields in StructuredClass::getFieldDescriptors --- src/core/model/Domain.cpp | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/core/model/Domain.cpp') 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 sc, Logger &logger) sc->setSuperclass(nullptr, logger); } -void StructuredClass::gatherFieldDescriptors( +Rooted StructuredClass::gatherFieldDescriptors( NodeVector ¤t, std::set &overriddenFields, bool hasTREE) const { - // append all FieldDescriptors that are not overridden. - for (auto &f : Descriptor::getFieldDescriptors()) { + Rooted mainField; + NodeVector 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 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 StructuredClass::getFieldDescriptors() const @@ -815,7 +819,11 @@ NodeVector StructuredClass::getFieldDescriptors() const // in this case we return a NodeVector of Rooted entries without owner. NodeVector vec; std::set overriddenFields; - gatherFieldDescriptors(vec, overriddenFields, false); + Rooted mainField = + gatherFieldDescriptors(vec, overriddenFields, false); + if (mainField != nullptr) { + vec.push_back(mainField); + } return vec; } -- cgit v1.2.3