diff data/model/SparseModel.h @ 1126:39019ce29178 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents e22bfe8ca248 ed207f89aaef
children 815f82508f96
line wrap: on
line diff
--- a/data/model/SparseModel.h	Fri Aug 14 18:16:14 2015 +0100
+++ b/data/model/SparseModel.h	Thu Aug 20 14:54:21 2015 +0100
@@ -133,6 +133,12 @@
      */
     virtual void deletePoint(const PointType &point);
 
+    /**
+     * Return true if the given point is found in this model, false
+     * otherwise.
+     */
+    virtual bool containsPoint(const PointType &point);
+    
     virtual bool isReady(int *completion = 0) const {
         bool ready = isOK() && (m_completion == 100);
         if (completion) *completion = m_completion;
@@ -153,18 +159,20 @@
                        QString extraAttributes = "") const;
 
     virtual QString toDelimitedDataString(QString delimiter) const {
-        return toDelimitedDataStringWithOptions(delimiter, DataExportDefaults);
+        return toDelimitedDataStringWithOptions
+            (delimiter, DataExportDefaults);
     }
 
     virtual QString toDelimitedDataStringWithOptions(QString delimiter,
                                                      DataExportOptions opts) const {
         return toDelimitedDataStringSubsetWithOptions
             (delimiter, opts,
-             std::min(getStartFrame(), sv_frame_t(0)), getEndFrame());
+             std::min(getStartFrame(), sv_frame_t(0)), getEndFrame() + 1);
     }
 
     virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const {
-        return toDelimitedDataStringSubsetWithOptions(delimiter, DataExportDefaults, f0, f1);
+        return toDelimitedDataStringSubsetWithOptions
+            (delimiter, DataExportDefaults, f0, f1);
     }
 
     virtual QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions opts, sv_frame_t f0, sv_frame_t f1) const {
@@ -772,6 +780,27 @@
 }
 
 template <typename PointType>
+bool
+SparseModel<PointType>::containsPoint(const PointType &point)
+{
+    {
+	QMutexLocker locker(&m_mutex);
+
+	PointListIterator i = m_points.lower_bound(point);
+	typename PointType::Comparator comparator;
+	while (i != m_points.end()) {
+	    if (i->frame > point.frame) break;
+	    if (!comparator(*i, point) && !comparator(point, *i)) {
+                return true;
+	    }
+	    ++i;
+	}
+    }
+
+    return false;
+}
+
+template <typename PointType>
 void
 SparseModel<PointType>::deletePoint(const PointType &point)
 {