From b6dc333b68e491d89e4ca58dd1c7cd88fc03263e Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 16 Oct 2012 03:52:46 -0700 Subject: [PATCH] Add a 'sort' function to an STArray. They can be used in cases where order is significant or where they're sorted. --- src/SerializedObject.cpp | 5 +++++ src/SerializedObject.h | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 678b1add3c..c8d243952e 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -866,6 +866,11 @@ STArray* STArray::construct(SerializerIterator& sit, SField::ref field) return new STArray(field, value); } +void STArray::sort(bool (*compare)(const STObject&, const STObject&)) +{ + std::sort(value.begin(), value.end(), compare); +} + std::auto_ptr STObject::parseJson(const Json::Value& object, SField::ref inName, int depth) { if (!object.isObject()) diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 7ecd539eb3..f2c389f09d 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -152,9 +152,9 @@ class STArray : public SerializedType { public: typedef std::vector vector; - typedef std::vector::iterator iterator; + typedef std::vector::iterator iterator; typedef std::vector::const_iterator const_iterator; - typedef std::vector::reverse_iterator reverse_iterator; + typedef std::vector::reverse_iterator reverse_iterator; typedef std::vector::const_reverse_iterator const_reverse_iterator; typedef std::vector::size_type size_type; @@ -205,6 +205,8 @@ public: virtual Json::Value getJson(int) const; virtual void add(Serializer& s) const; + void sort(bool (*compare)(const STObject& o1, const STObject& o2)); + bool operator==(const STArray &s) { return value == s.value; } bool operator!=(const STArray &s) { return value != s.value; }