From 3e305871c376ebb2c8391adb535664414c689dd8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 29 Sep 2012 00:30:21 -0700 Subject: [PATCH] Missing sort. --- src/SerializedObject.cpp | 16 ++++++++++++++++ src/SerializedObject.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 4178ef0087..9cd320e06f 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../json/writer.h" @@ -129,11 +130,26 @@ void STObject::set(SOElement::ptr elem) } } +bool STObject::compare(const SerializedType& f1, const SerializedType& f2) +{ + BOOST_FOREACH(SOElement::ptr elem, mType) + { + if (elem->e_field == f1.getFName()) // element one comes first + return true; + if (elem->e_field == f2.getFName()) // element two comes first + return false; + } + assert(false); + return false; +} + void STObject::setType(SOElement::ptrList t) { mType.empty(); while (t->flags != SOE_END) mType.push_back(t++); + + std::sort(mData.begin(), mData.end(), boost::bind(&STObject::compare, this, _1, _2)); } bool STObject::isValidForType() diff --git a/src/SerializedObject.h b/src/SerializedObject.h index c69f18d3a9..ee66681ee4 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -28,6 +28,7 @@ protected: std::vector mType; STObject* duplicate() const { return new STObject(*this); } + bool compare(const SerializedType& f1, const SerializedType& f2); public: STObject() { ; }