diff data/model/SparseModel.h @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 9f526ddc6165
children a1cd5abcb38b
line wrap: on
line diff
--- a/data/model/SparseModel.h	Tue Mar 03 09:33:59 2015 +0000
+++ b/data/model/SparseModel.h	Tue Mar 03 15:18:24 2015 +0000
@@ -48,8 +48,8 @@
     virtual ~SparseModel() { }
     
     virtual bool isOK() const { return true; }
-    virtual int getStartFrame() const;
-    virtual int getEndFrame() const;
+    virtual sv_frame_t getStartFrame() const;
+    virtual sv_frame_t getEndFrame() const;
     virtual int getSampleRate() const { return m_sampleRate; }
 
     virtual Model *clone() const;
@@ -91,25 +91,25 @@
      * after the boundaries.  If you need exact boundaries, check the
      * point coordinates in the returned list.
      */
-    virtual PointList getPoints(long start, long end) const;
+    virtual PointList getPoints(sv_frame_t start, sv_frame_t end) const;
 
     /**
      * Get all points that cover the given frame number, taking the
      * resolution of the model into account.
      */
-    virtual PointList getPoints(long frame) const;
+    virtual PointList getPoints(sv_frame_t frame) const;
 
     /**
      * Return all points that share the nearest frame number prior to
      * the given one at which there are any points.
      */
-    virtual PointList getPreviousPoints(long frame) const;
+    virtual PointList getPreviousPoints(sv_frame_t frame) const;
 
     /**
      * Return all points that share the nearest frame number
      * subsequent to the given one at which there are any points.
      */
-    virtual PointList getNextPoints(long frame) const;
+    virtual PointList getNextPoints(sv_frame_t frame) const;
 
     /**
      * Remove all points.
@@ -157,11 +157,11 @@
         return s;
     }
 
-    virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
+    virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
     { 
         QString s;
         for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
-            if (i->frame >= (long)f0 && i->frame < (long)f1) {
+            if (i->frame >= f0 && i->frame < f1) {
                 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
             }
         }
@@ -284,31 +284,26 @@
 
     virtual int getRowCount() const
     {
-        return m_points.size();
+        return int(m_points.size());
     }
 
-    virtual long getFrameForRow(int row) const
+    virtual sv_frame_t getFrameForRow(int row) const
     {
         PointListConstIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return 0;
         return i->frame;
     }
 
-    virtual int getRowForFrame(long frame) const
+    virtual int getRowForFrame(sv_frame_t frame) const
     {
         if (m_rows.empty()) rebuildRowVector();
-        std::vector<long>::iterator i =
+        std::vector<sv_frame_t>::iterator i =
             std::lower_bound(m_rows.begin(), m_rows.end(), frame);
-#if defined(__SUNPRO_CC) && defined(__STD_RW_ITERATOR__)
-        int row = 0;
-        std::distance(m_rows.begin(), i, row);
-#else
-        int row = std::distance(m_rows.begin(), i);
-#endif
+        ssize_t row = std::distance(m_rows.begin(), i);
         if (i != m_rows.begin() && (i == m_rows.end() || *i != frame)) {
             --row;
         }
-        return row;
+        return int(row);
     }
 
     virtual int getColumnCount() const { return 1; }
@@ -374,8 +369,8 @@
     int m_sampleRate;
     int m_resolution;
     bool m_notifyOnAdd;
-    long m_sinceLastNotifyMin;
-    long m_sinceLastNotifyMax;
+    sv_frame_t m_sinceLastNotifyMin;
+    sv_frame_t m_sinceLastNotifyMax;
     bool m_hasTextLabels;
 
     PointList m_points;
@@ -383,16 +378,16 @@
     mutable QMutex m_mutex;
     int m_completion;
 
-    void getPointIterators(long frame,
+    void getPointIterators(sv_frame_t frame,
                            PointListIterator &startItr,
                            PointListIterator &endItr);
-    void getPointIterators(long frame,
+    void getPointIterators(sv_frame_t frame,
                            PointListConstIterator &startItr,
                            PointListConstIterator &endItr) const;
 
     // This is only used if the model is called on to act in
     // TabularModel mode
-    mutable std::vector<long> m_rows; // map from row number to frame
+    mutable std::vector<sv_frame_t> m_rows; // map from row number to frame
     void rebuildRowVector() const
     {
         m_rows.clear();
@@ -407,7 +402,7 @@
         if (m_rows.empty()) rebuildRowVector();
         if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
 
-        int frame = m_rows[row];
+        sv_frame_t frame = m_rows[row];
         int indexAtFrame = 0;
         int ri = row;
         while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
@@ -434,7 +429,7 @@
         if (m_rows.empty()) rebuildRowVector();
         if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
 
-        int frame = m_rows[row];
+        sv_frame_t frame = m_rows[row];
         int indexAtFrame = 0;
         int ri = row;
         while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
@@ -480,11 +475,11 @@
 }
 
 template <typename PointType>
-int
+sv_frame_t
 SparseModel<PointType>::getStartFrame() const
 {
     QMutexLocker locker(&m_mutex);
-    int f = 0;
+    sv_frame_t f = 0;
     if (!m_points.empty()) {
 	f = m_points.begin()->frame;
     }
@@ -492,11 +487,11 @@
 }
 
 template <typename PointType>
-int
+sv_frame_t
 SparseModel<PointType>::getEndFrame() const
 {
     QMutexLocker locker(&m_mutex);
-    int f = 0;
+    sv_frame_t f = 0;
     if (!m_points.empty()) {
 	PointListConstIterator i(m_points.end());
 	f = (--i)->frame;
@@ -541,7 +536,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPoints(long start, long end) const
+SparseModel<PointType>::getPoints(sv_frame_t start, sv_frame_t end) const
 {
     if (start > end) return PointList();
     QMutexLocker locker(&m_mutex);
@@ -567,7 +562,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPoints(long frame) const
+SparseModel<PointType>::getPoints(sv_frame_t frame) const
 {
     PointListConstIterator startItr, endItr;
     getPointIterators(frame, startItr, endItr);
@@ -583,7 +578,7 @@
 
 template <typename PointType>
 void
-SparseModel<PointType>::getPointIterators(long frame,
+SparseModel<PointType>::getPointIterators(sv_frame_t frame,
                                           PointListIterator &startItr,
                                           PointListIterator &endItr)
 {
@@ -595,8 +590,8 @@
         return;
     }
 
-    long start = (frame / m_resolution) * m_resolution;
-    long end = start + m_resolution;
+    sv_frame_t start = (frame / m_resolution) * m_resolution;
+    sv_frame_t end = start + m_resolution;
 
     PointType startPoint(start), endPoint(end);
 
@@ -606,7 +601,7 @@
 
 template <typename PointType>
 void
-SparseModel<PointType>::getPointIterators(long frame,
+SparseModel<PointType>::getPointIterators(sv_frame_t frame,
                                           PointListConstIterator &startItr,
                                           PointListConstIterator &endItr) const
 {
@@ -619,8 +614,8 @@
         return;
     }
 
-    long start = (frame / m_resolution) * m_resolution;
-    long end = start + m_resolution;
+    sv_frame_t start = (frame / m_resolution) * m_resolution;
+    sv_frame_t end = start + m_resolution;
 
     PointType startPoint(start), endPoint(end);
     
@@ -632,7 +627,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPreviousPoints(long originFrame) const
+SparseModel<PointType>::getPreviousPoints(sv_frame_t originFrame) const
 {
     QMutexLocker locker(&m_mutex);
 
@@ -643,7 +638,7 @@
     if (i == m_points.begin()) return rv;
 
     --i;
-    long frame = i->frame;
+    sv_frame_t frame = i->frame;
     while (i->frame == frame) {
 	rv.insert(*i);
 	if (i == m_points.begin()) break;
@@ -655,7 +650,7 @@
  
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getNextPoints(long originFrame) const
+SparseModel<PointType>::getNextPoints(sv_frame_t originFrame) const
 {
     QMutexLocker locker(&m_mutex);
 
@@ -665,7 +660,7 @@
     PointListConstIterator i = m_points.upper_bound(lookupPoint);
     if (i == m_points.end()) return rv;
 
-    long frame = i->frame;
+    sv_frame_t frame = i->frame;
     while (i != m_points.end() && i->frame == frame) {
 	rv.insert(*i);
 	++i;