# HG changeset patch # User Chris Cannam # Date 1207211425 0 # Node ID 78dd9b35559b940e4c147477b4d8cc8d74fdbd3e # Parent 0f0f08c225528305eb617142d73da77b34cc5ce6 * transform operator< diff -r 0f0f08c22552 -r 78dd9b35559b transform/Transform.cpp --- a/transform/Transform.cpp Fri Mar 28 17:51:13 2008 +0000 +++ b/transform/Transform.cpp Thu Apr 03 08:30:25 2008 +0000 @@ -107,7 +107,7 @@ } bool -Transform::operator==(const Transform &t) +Transform::operator==(const Transform &t) const { return m_id == t.m_id && @@ -122,6 +122,42 @@ m_sampleRate == t.m_sampleRate; } +bool +Transform::operator<(const Transform &t) const +{ + if (m_id != t.m_id) { + return m_id < t.m_id; + } + if (m_parameters != t.m_parameters) { + return mapLessThan(m_parameters, t.m_parameters); + } + if (m_configuration != t.m_configuration) { + return mapLessThan(m_configuration, t.m_configuration); + } + if (m_program != t.m_program) { + return m_program < t.m_program; + } + if (m_stepSize != t.m_stepSize) { + return m_stepSize < t.m_stepSize; + } + if (m_blockSize != t.m_blockSize) { + return m_blockSize < t.m_blockSize; + } + if (m_windowType != t.m_windowType) { + return m_windowType < t.m_windowType; + } + if (m_startTime != t.m_startTime) { + return m_startTime < t.m_startTime; + } + if (m_duration != t.m_duration) { + return m_duration < t.m_duration; + } + if (m_sampleRate != t.m_sampleRate) { + return m_sampleRate < t.m_sampleRate; + } + return false; +} + void Transform::setIdentifier(TransformId id) { diff -r 0f0f08c22552 -r 78dd9b35559b transform/Transform.h --- a/transform/Transform.h Fri Mar 28 17:51:13 2008 +0000 +++ b/transform/Transform.h Thu Apr 03 08:30:25 2008 +0000 @@ -22,6 +22,8 @@ #include +#include + typedef QString TransformId; class QXmlAttributes; @@ -55,7 +57,13 @@ * Compare two Transforms. They only compare equal if every data * element matches. */ - bool operator==(const Transform &); + bool operator==(const Transform &) const; + + /** + * Order two Transforms, so that they can be used as keys in + * containers. + */ + bool operator<(const Transform &) const; void setIdentifier(TransformId id); TransformId getIdentifier() const; @@ -139,6 +147,21 @@ (QString identifier, QString &type, QString &soName, QString &label, QString &output); + template + bool mapLessThan(const std::map &a, const std::map &b) const { + // Return true if a is "less than" b. Ordering doesn't have + // to be meaningful, just consistent. + typename std::map::const_iterator i; + typename std::map::const_iterator j; + for (i = a.begin(), j = b.begin(); i != a.end(); ++i) { + if (j == b.end()) return false; // a is longer than b + if (i->first != j->first) return i->first < j->first; + if (i->second != j->second) return i->second < j->second; + } + if (j != b.end()) return true; // a is shorter than b + return false; // equal + } + ParameterMap m_parameters; ConfigurationMap m_configuration; QString m_pluginVersion;