Add a 'sort' function to an STArray. They can be used in cases where

order is significant or where they're sorted.
This commit is contained in:
JoelKatz
2012-10-16 03:52:46 -07:00
parent 9c31daad08
commit b6dc333b68
2 changed files with 9 additions and 2 deletions

View File

@@ -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> STObject::parseJson(const Json::Value& object, SField::ref inName, int depth)
{
if (!object.isObject())

View File

@@ -152,9 +152,9 @@ class STArray : public SerializedType
{
public:
typedef std::vector<STObject> vector;
typedef std::vector<STObject>::iterator iterator;
typedef std::vector<STObject>::iterator iterator;
typedef std::vector<STObject>::const_iterator const_iterator;
typedef std::vector<STObject>::reverse_iterator reverse_iterator;
typedef std::vector<STObject>::reverse_iterator reverse_iterator;
typedef std::vector<STObject>::const_reverse_iterator const_reverse_iterator;
typedef std::vector<STObject>::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; }